Subversion Repositories shark

Rev

Rev 8 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 pj 1
/*
2
 * Project:
3
 *   Parallel Port S.Ha.R.K. Project
4
 *
5
 * Module:
6
 *   ppDrv.h
7
 *
8
 * Description:
9
 *   file contents description
10
 *
11
 * Coordinators:
12
 *   Giorgio Buttazzo    <giorgio@sssup.it>
13
 *   Paolo Gai           <pj@gandalf.sssup.it>
14
 *
15
 * Authors:
16
 *   Andrea Battistotti <btandrea@libero.it>
17
 *   Armando Leggio     <a_leggio@hotmail.com>
18
 *
19
 *
20
 * http://www.sssup.it
21
 * http://retis.sssup.it
22
 * http://shark.sssup.it
23
 *
24
 */
25
 
26
/* PPDrv.h
27
        header file for par port communication...
28
*/
29
 
30
/*
31
 * Copyright (C) 2002 Andrea Battistotti , Armando Leggio
32
 *
33
 * This program is free software; you can redistribute it and/or modify
34
 * it under the terms of the GNU General Public License as published by
35
 * the Free Software Foundation; either version 2 of the License, or
36
 * (at your option) any later version.
37
 *
38
 * This program is distributed in the hope that it will be useful,
39
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41
 * GNU General Public License for more details.
42
 *
43
 * You should have received a copy of the GNU General Public License
44
 * along with this program; if not, write to the Free Software
45
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
46
 *
61 pj 47
 * CVS : $Id: parport.h,v 1.2 2003-02-28 12:05:43 pj Exp $
8 pj 48
 */
49
 
50
#include <kernel/kern.h>
51
#include <drivers/keyb.h>
52
#include <time.h>
53
#include <stdio.h>
54
#include <stdlib.h>
55
#include <kernel/func.h>
56
#include <string.h>
57
#include <ll/ll.h>
58
#include <kernel/types.h>
59
#include <kernel/descr.h>
60
#include <math.h>
61
 
62
 
63
/* general defs... */
64
#define PP_DEBUG   1      /* 1/0  Activate/Disactive internal debugs...     */
65
#define PP_STATS   1      /* 1/0  Activate/Disactive internal statistics... */
66
 
67
/* return value... */
68
#define FALSE   0
69
#define TRUE    1
70
#define TIMEOUT 2
71
 
72
#define PP_BASE_ADR             0x0378                                          /* std addr for LPT1 */
73
 
74
#define BYTE unsigned char
75
#define BOOL unsigned char
76
#define BUF_IDX unsigned int
77
#define BUF_PNTR unsigned int
78
#define PIN_MASK unsigned int
79
 
80
#define clock()              sys_gettime(NULL)
81
 
82
enum PIN_STATUS { PIN_OFF ,     PIN_ON } ;             /* positive logic: off==0, on==1 */
83
 
84
/*********************************************************************************/
85
/* PART 1 : LOW LIVEL FUNC */
86
 
87
/* defs used in ppPinDrv....*/
88
/* for std & pin use of pp... */
89
#define PP_DATA_REG     (PP_BASE_ADR+0)             //  address of data register
90
#define PP_STATUS_REG   (PP_BASE_ADR+1)             //  address of status register
91
#define PP_CONTR_REG    (PP_BASE_ADR+2)             //  address of control regist
92
 
93
/* out data pins... */
94
#define PP_PIN_D0                       0x01   /* pin 2 */
95
#define PP_PIN_D1                       0x02   /* pin 3 */
96
#define PP_PIN_D2                       0x04   /* pin 4 */
97
#define PP_PIN_D3                       0x08   /* pin 5 */
98
#define PP_PIN_D4                       0x10   /* pin 6 */
99
#define PP_PIN_D5                       0x20   /* pin 7 */
100
#define PP_PIN_D6                       0x40   /* pin 8 */
101
#define PP_PIN_D7                       0x80   /* pin 9 */
102
 
103
/* status pins... */
104
#define PP_PIN_ERROR            0x08   /* pin 15 */
105
#define PP_PIN_SELECTED         0x10   /* pin 13 */
106
#define PP_PIN_PAPEROUT         0x20   /* pin 12 */
107
#define PP_PIN_ACK                      0x40   /* pin 10 */
108
#define PP_PIN_BUSY             0x80   /* pin 11 */
109
 
110
/* control pins... */
111
#define PP_PIN_DATASTROBE       0x01   /* pin 1  */
112
#define PP_PIN_AUTOFEED         0x02   /* pin 14 */
113
#define PP_PIN_INITOUT          0x04   /* pin 16 */
114
#define PP_PIN_SELECT           0x08   /* pin 17 */
115
 
116
/* Data i/o */
117
#define ppSetDataByte(a)             outp(PP_DATA_REG,a)
118
#define ppReadDataByte()             inp(PP_DATA_REG)
119
/* this is NOT bidirectional actually: simply read value that I myself wrote on parport early...*/
120
/* in std lpt you cannot lay down electric pin D0,D1,..D7 from extern and read value in pc...*/
121
/* this (in std lpt) will broke down lpt port!... */
122
/* there are obviously also bi-dir port on 8 bit (ECC & ECP) but ctrl & status pins have */
123
/* different meaning so we don't manage them... See docs. */
124
 
125
/* Data pins */
126
void ppSetDataPin(int state, PIN_MASK pin);                                             /* in ppPinDrv.c */
127
#define ppSetPin_D0(a)                          ppSetDataPin(a,PP_PIN_D0)   /* On ==1 , Off == 0 */
128
#define ppSetPin_D1(a)                          ppSetDataPin(a,PP_PIN_D1)
129
#define ppSetPin_D2(a)                          ppSetDataPin(a,PP_PIN_D2)
130
#define ppSetPin_D3(a)                          ppSetDataPin(a,PP_PIN_D3)
131
#define ppSetPin_D4(a)                          ppSetDataPin(a,PP_PIN_D4)
132
#define ppSetPin_D5(a)                          ppSetDataPin(a,PP_PIN_D5)
133
#define ppSetPin_D6(a)                          ppSetDataPin(a,PP_PIN_D6)
134
#define ppSetPin_D7(a)                          ppSetDataPin(a,PP_PIN_D7)
135
 
136
/* Status pins */
137
#define ppCheckPin_Error()              (inp(PP_STATUS_REG & PP_PIN_ERROR)!=0?1:0)
138
#define ppCheckPin_Selected()           (inp(PP_STATUS_REG & PP_PIN_SELECTED)!=0?1:0)
139
#define ppCheckPin_PaperOut()           (inp(PP_STATUS_REG & PP_PIN_PAPEROUT)!=0?1:0)
140
#define ppCheckPin_Acknowledge()        (inp(PP_STATUS_REG & PP_PIN_ACK)!=0?1:0)
141
#define ppCheckPin_Busy()                       (inp(PP_STATUS_REG & PP_PIN_BUSY)!=0?0:1)       /* act low...*/
142
 
143
/* Control pins */
144
/* Control i/o */
145
#define ppSetCtrlByte(a)             outp(PP_CONTR_REG,a)
146
#define ppReadCtrlByte()             inp(PP_CONTR_REG) 
147
/* idem...*/
148
void ppSetCtrlPin(int state, PIN_MASK pin);                                                             /* in ppPinDrv.c */
149
#define ppSetPin_DataStrobe(a)          ppSetCtrlPin(!a,PP_PIN_DATASTROBE)  /* low active...*/
150
#define ppSetPin_Autofeed(a)            ppSetCtrlPin(!a,PP_PIN_AUTOFEED)    /* low active...*/
151
#define ppSetPin_InitOut(a)                     ppSetCtrlPin(a,PP_PIN_INITOUT)    
152
#define ppSetPin_Select(a)                      ppSetCtrlPin(!a,PP_PIN_SELECT)          /* low active...*/
153
 
154
 
155
 
156
 
157
/*********************************************************************************/
158
/* PART 2 : DATA TRANSFER BETWEEN PC */
159
/* defs used in ppDrv & ppNRTDrv... */
160
#define PPDRV_PERIOD          1000                      /* 300000 ok for debug...*/
161
#define PPDRV_WCET             150                      /* lower bound: 120; more if debug & stats are on...*/
162
#define PP_BUF_LEN            1024                      /* between 2^2 and 2^16 (64k) */
163
#define CLK_TIMEOUT          55000                      /* timeout for sync pc-pc...*/
164
 
165
/* for laplink use of std pp... */
166
#define TX_PORT                         PP_BASE_ADR                     /* transmit port */
167
#define RX_PORT                         TX_PORT+1                       /* receive port  */
168
 
169
/*  laplink bit mask */
170
#define TX_DATA                         0x0F                                    /* 0000 1111 pin 2,3,4,5 */
171
#define TX_CTR                          0x10                                    /* 0001 0000 bit 4 port TX pin 6*/
172
#define RX_DATA                         0x78                                    /* 0111 1000 pin 15,13,12,10 */
173
#define RX_CTR                          0x80                                    /* 1000 0000 bit 7 port RX pin 11*/
174
#define LSN                             0x0F                                    /* 0000 1111 low significative nibble */
175
#define MSN                             0xF0                                    /* 1111 0000 most significative nibble */
176
#define BYTE_CTR                        0xAF                                    /* 1010 1111 control char */
177
 
178
 
179
/* comm protocol */
180
#define ppSendRTS()          ppSetOnPinTX_CTR()
181
#define ppIsRTS()            ppReadIfPinRX_CTRIsOn()
182
#define ppSendOTS()          ppSetOnPinTX_CTR()
183
#define ppIsOTS()            ppReadIfPinRX_CTRIsOn()
184
#define ppSendDR()           ppSetOffPinTX_CTR()
185
#define ppIsDR()             ppReadIfPinRX_CTRIsOff()
186
#define ppSendER()           ppSetOffPinTX_CTR()
187
#define ppIsER()             ppReadIfPinRX_CTRIsOff()
188
 
189
 
190
#define ppSetOnPinTX_CTR()          outp(TX_PORT,(inp(TX_PORT)|TX_CTR))          /* used by: ppSendRTS ppSendOTS */
191
#define ppSetOffPinTX_CTR()         outp(TX_PORT,(inp(TX_PORT)&(~TX_CTR)))       /* used by: ppSendDR ppSendER */
192
#define ppReadIfPinRX_CTRIsOn()     ((((~inp(RX_PORT))&RX_CTR)==0)?FALSE:TRUE)
193
#define ppReadIfPinRX_CTRIsOff()    (((BYTE)((~RX_CTR)|(~inp(RX_PORT)))==0x7F)?TRUE:FALSE)
194
 
195
/* Funct Return Code */
196
enum PP_COMM_RTR_CODE {
197
  PP_COMM_OK,
198
  PP_COMM_NOREADYBYTES_EXC,
199
  PP_COMM_NOFREEBYTES_EXC
200
};
201
 
202
/* Funct Return Code */
203
enum PP_SYSMSG_RTR_CODE {
204
  PP_SYSMSG_OK,
205
  PP_NOSYSMSG_EXC,
206
  PP_NOFREEMSG_EXC
207
};
208
 
209
/* NON REAL TIME (== BLOCK) functions...*/
210
/* from ppNRTDrv.c...*/
211
BOOL ppNRTOpenComm(void);
212
BOOL ppNRTWaitRTS(void);
213
BOOL ppNRTWaitDR(void);
214
BOOL ppNRTWaitOTS(void);
215
BOOL ppNRTWaitER(void);
216
BOOL ppNRTTxOneByte(BYTE c);
217
BOOL ppNRTRxOneByte(BYTE *c);
218
 
219
 
220
/* REAL TIME (== NON BLOCK) POLLING SERVER */
221
/* from ppDrv.c... */
222
void ppInitDrv(void (*pf)(char *));                   /* NRT: to be called before start ppPollingSrv...*/
223
TASK ppPollingSvr(void *arg);   /* periodic task to be started before any call to Rx/Tx...*/
224
 
225
/* input output function */
226
int ppRxOneByte(BYTE *c);                    /* retrive 1 byte */
227
int ppTxOneByte(BYTE c);                     /* send 1 byte */
228
 
229
int ppRxBytes(BYTE *c, unsigned int nbyte);  /* retrive n byte... */
230
int ppTxBytes(BYTE *c, unsigned int nbyte);  /* send n byte... */
231
 
232
 
233
/* System msg */
234
#define SYS_MSG_COLS 33
235
#define SYS_MSG_LINS 15
236
 
237
 
238
int ppReadSysMsg(char * buf);
239
int ppWriteSysMsg(char * buf, ...);
240