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
 *
47
 * CVS : $Id: parport.h,v 1.1 2002-10-28 07:52:11 pj Exp $
48
 */
49
 
50
#include <kernel/kern.h>
51
#include <drivers/glib.h>
52
#include <drivers/keyb.h>
53
#include <time.h>
54
#include <stdio.h>
55
#include <stdlib.h>
56
#include <kernel/func.h>
57
#include <string.h>
58
#include <ll/ll.h>
59
#include <kernel/types.h>
60
#include <kernel/descr.h>
61
#include <math.h>
62
 
63
 
64
/* general defs... */
65
#define PP_DEBUG   1      /* 1/0  Activate/Disactive internal debugs...     */
66
#define PP_STATS   1      /* 1/0  Activate/Disactive internal statistics... */
67
 
68
/* return value... */
69
#define FALSE   0
70
#define TRUE    1
71
#define TIMEOUT 2
72
 
73
#define PP_BASE_ADR             0x0378                                          /* std addr for LPT1 */
74
 
75
#define BYTE unsigned char
76
#define BOOL unsigned char
77
#define BUF_IDX unsigned int
78
#define BUF_PNTR unsigned int
79
#define PIN_MASK unsigned int
80
 
81
#define clock()              sys_gettime(NULL)
82
 
83
enum PIN_STATUS { PIN_OFF ,     PIN_ON } ;             /* positive logic: off==0, on==1 */
84
 
85
/*********************************************************************************/
86
/* PART 1 : LOW LIVEL FUNC */
87
 
88
/* defs used in ppPinDrv....*/
89
/* for std & pin use of pp... */
90
#define PP_DATA_REG     (PP_BASE_ADR+0)             //  address of data register
91
#define PP_STATUS_REG   (PP_BASE_ADR+1)             //  address of status register
92
#define PP_CONTR_REG    (PP_BASE_ADR+2)             //  address of control regist
93
 
94
/* out data pins... */
95
#define PP_PIN_D0                       0x01   /* pin 2 */
96
#define PP_PIN_D1                       0x02   /* pin 3 */
97
#define PP_PIN_D2                       0x04   /* pin 4 */
98
#define PP_PIN_D3                       0x08   /* pin 5 */
99
#define PP_PIN_D4                       0x10   /* pin 6 */
100
#define PP_PIN_D5                       0x20   /* pin 7 */
101
#define PP_PIN_D6                       0x40   /* pin 8 */
102
#define PP_PIN_D7                       0x80   /* pin 9 */
103
 
104
/* status pins... */
105
#define PP_PIN_ERROR            0x08   /* pin 15 */
106
#define PP_PIN_SELECTED         0x10   /* pin 13 */
107
#define PP_PIN_PAPEROUT         0x20   /* pin 12 */
108
#define PP_PIN_ACK                      0x40   /* pin 10 */
109
#define PP_PIN_BUSY             0x80   /* pin 11 */
110
 
111
/* control pins... */
112
#define PP_PIN_DATASTROBE       0x01   /* pin 1  */
113
#define PP_PIN_AUTOFEED         0x02   /* pin 14 */
114
#define PP_PIN_INITOUT          0x04   /* pin 16 */
115
#define PP_PIN_SELECT           0x08   /* pin 17 */
116
 
117
/* Data i/o */
118
#define ppSetDataByte(a)             outp(PP_DATA_REG,a)
119
#define ppReadDataByte()             inp(PP_DATA_REG)
120
/* this is NOT bidirectional actually: simply read value that I myself wrote on parport early...*/
121
/* in std lpt you cannot lay down electric pin D0,D1,..D7 from extern and read value in pc...*/
122
/* this (in std lpt) will broke down lpt port!... */
123
/* there are obviously also bi-dir port on 8 bit (ECC & ECP) but ctrl & status pins have */
124
/* different meaning so we don't manage them... See docs. */
125
 
126
/* Data pins */
127
void ppSetDataPin(int state, PIN_MASK pin);                                             /* in ppPinDrv.c */
128
#define ppSetPin_D0(a)                          ppSetDataPin(a,PP_PIN_D0)   /* On ==1 , Off == 0 */
129
#define ppSetPin_D1(a)                          ppSetDataPin(a,PP_PIN_D1)
130
#define ppSetPin_D2(a)                          ppSetDataPin(a,PP_PIN_D2)
131
#define ppSetPin_D3(a)                          ppSetDataPin(a,PP_PIN_D3)
132
#define ppSetPin_D4(a)                          ppSetDataPin(a,PP_PIN_D4)
133
#define ppSetPin_D5(a)                          ppSetDataPin(a,PP_PIN_D5)
134
#define ppSetPin_D6(a)                          ppSetDataPin(a,PP_PIN_D6)
135
#define ppSetPin_D7(a)                          ppSetDataPin(a,PP_PIN_D7)
136
 
137
/* Status pins */
138
#define ppCheckPin_Error()              (inp(PP_STATUS_REG & PP_PIN_ERROR)!=0?1:0)
139
#define ppCheckPin_Selected()           (inp(PP_STATUS_REG & PP_PIN_SELECTED)!=0?1:0)
140
#define ppCheckPin_PaperOut()           (inp(PP_STATUS_REG & PP_PIN_PAPEROUT)!=0?1:0)
141
#define ppCheckPin_Acknowledge()        (inp(PP_STATUS_REG & PP_PIN_ACK)!=0?1:0)
142
#define ppCheckPin_Busy()                       (inp(PP_STATUS_REG & PP_PIN_BUSY)!=0?0:1)       /* act low...*/
143
 
144
/* Control pins */
145
/* Control i/o */
146
#define ppSetCtrlByte(a)             outp(PP_CONTR_REG,a)
147
#define ppReadCtrlByte()             inp(PP_CONTR_REG) 
148
/* idem...*/
149
void ppSetCtrlPin(int state, PIN_MASK pin);                                                             /* in ppPinDrv.c */
150
#define ppSetPin_DataStrobe(a)          ppSetCtrlPin(!a,PP_PIN_DATASTROBE)  /* low active...*/
151
#define ppSetPin_Autofeed(a)            ppSetCtrlPin(!a,PP_PIN_AUTOFEED)    /* low active...*/
152
#define ppSetPin_InitOut(a)                     ppSetCtrlPin(a,PP_PIN_INITOUT)    
153
#define ppSetPin_Select(a)                      ppSetCtrlPin(!a,PP_PIN_SELECT)          /* low active...*/
154
 
155
 
156
 
157
 
158
/*********************************************************************************/
159
/* PART 2 : DATA TRANSFER BETWEEN PC */
160
/* defs used in ppDrv & ppNRTDrv... */
161
#define PPDRV_PERIOD          1000                      /* 300000 ok for debug...*/
162
#define PPDRV_WCET             150                      /* lower bound: 120; more if debug & stats are on...*/
163
#define PP_BUF_LEN            1024                      /* between 2^2 and 2^16 (64k) */
164
#define CLK_TIMEOUT          55000                      /* timeout for sync pc-pc...*/
165
 
166
/* for laplink use of std pp... */
167
#define TX_PORT                         PP_BASE_ADR                     /* transmit port */
168
#define RX_PORT                         TX_PORT+1                       /* receive port  */
169
 
170
/*  laplink bit mask */
171
#define TX_DATA                         0x0F                                    /* 0000 1111 pin 2,3,4,5 */
172
#define TX_CTR                          0x10                                    /* 0001 0000 bit 4 port TX pin 6*/
173
#define RX_DATA                         0x78                                    /* 0111 1000 pin 15,13,12,10 */
174
#define RX_CTR                          0x80                                    /* 1000 0000 bit 7 port RX pin 11*/
175
#define LSN                             0x0F                                    /* 0000 1111 low significative nibble */
176
#define MSN                             0xF0                                    /* 1111 0000 most significative nibble */
177
#define BYTE_CTR                        0xAF                                    /* 1010 1111 control char */
178
 
179
 
180
/* comm protocol */
181
#define ppSendRTS()          ppSetOnPinTX_CTR()
182
#define ppIsRTS()            ppReadIfPinRX_CTRIsOn()
183
#define ppSendOTS()          ppSetOnPinTX_CTR()
184
#define ppIsOTS()            ppReadIfPinRX_CTRIsOn()
185
#define ppSendDR()           ppSetOffPinTX_CTR()
186
#define ppIsDR()             ppReadIfPinRX_CTRIsOff()
187
#define ppSendER()           ppSetOffPinTX_CTR()
188
#define ppIsER()             ppReadIfPinRX_CTRIsOff()
189
 
190
 
191
#define ppSetOnPinTX_CTR()          outp(TX_PORT,(inp(TX_PORT)|TX_CTR))          /* used by: ppSendRTS ppSendOTS */
192
#define ppSetOffPinTX_CTR()         outp(TX_PORT,(inp(TX_PORT)&(~TX_CTR)))       /* used by: ppSendDR ppSendER */
193
#define ppReadIfPinRX_CTRIsOn()     ((((~inp(RX_PORT))&RX_CTR)==0)?FALSE:TRUE)
194
#define ppReadIfPinRX_CTRIsOff()    (((BYTE)((~RX_CTR)|(~inp(RX_PORT)))==0x7F)?TRUE:FALSE)
195
 
196
/* Funct Return Code */
197
enum PP_COMM_RTR_CODE {
198
  PP_COMM_OK,
199
  PP_COMM_NOREADYBYTES_EXC,
200
  PP_COMM_NOFREEBYTES_EXC
201
};
202
 
203
/* Funct Return Code */
204
enum PP_SYSMSG_RTR_CODE {
205
  PP_SYSMSG_OK,
206
  PP_NOSYSMSG_EXC,
207
  PP_NOFREEMSG_EXC
208
};
209
 
210
/* NON REAL TIME (== BLOCK) functions...*/
211
/* from ppNRTDrv.c...*/
212
BOOL ppNRTOpenComm(void);
213
BOOL ppNRTWaitRTS(void);
214
BOOL ppNRTWaitDR(void);
215
BOOL ppNRTWaitOTS(void);
216
BOOL ppNRTWaitER(void);
217
BOOL ppNRTTxOneByte(BYTE c);
218
BOOL ppNRTRxOneByte(BYTE *c);
219
 
220
 
221
/* REAL TIME (== NON BLOCK) POLLING SERVER */
222
/* from ppDrv.c... */
223
void ppInitDrv(void (*pf)(char *));                   /* NRT: to be called before start ppPollingSrv...*/
224
TASK ppPollingSvr(void *arg);   /* periodic task to be started before any call to Rx/Tx...*/
225
 
226
/* input output function */
227
int ppRxOneByte(BYTE *c);                    /* retrive 1 byte */
228
int ppTxOneByte(BYTE c);                     /* send 1 byte */
229
 
230
int ppRxBytes(BYTE *c, unsigned int nbyte);  /* retrive n byte... */
231
int ppTxBytes(BYTE *c, unsigned int nbyte);  /* send n byte... */
232
 
233
 
234
/* System msg */
235
#define SYS_MSG_COLS 33
236
#define SYS_MSG_LINS 15
237
 
238
 
239
int ppReadSysMsg(char * buf);
240
int ppWriteSysMsg(char * buf, ...);
241