Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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