Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | pj | 1 | /* |
2 | * |
||
3 | * Project: |
||
4 | * Parallel Port S.Ha.R.K. Project |
||
5 | * |
||
6 | * Module: |
||
7 | * ppNRTDrv.c |
||
8 | * |
||
9 | * Description: |
||
10 | * file contents description |
||
11 | * |
||
12 | * Coordinators: |
||
13 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
14 | * Paolo Gai <pj@gandalf.sssup.it> |
||
15 | * |
||
16 | * Authors: |
||
17 | * Andrea Battistotti <btandrea@libero.it> |
||
18 | * Armando Leggio <a_leggio@hotmail.com> |
||
19 | * |
||
20 | * |
||
21 | * http://www.sssup.it |
||
22 | * http://retis.sssup.it |
||
23 | * http://shark.sssup.it |
||
24 | * |
||
25 | */ |
||
26 | |||
27 | /************************************************************************* |
||
28 | * Module : ppNRTDrv.c |
||
29 | * Author : Andrea Battistotti , Armando Leggio |
||
30 | * Description: Set On/Off single pin of LPT1... |
||
31 | * 2002 @ Pavia - GNU Copyrights |
||
32 | *******************************************************************************************/ |
||
33 | |||
34 | /* |
||
35 | * Copyright (C) 2002 Andrea Battistotti , Armando Leggio |
||
36 | * |
||
37 | * This program is free software; you can redistribute it and/or modify |
||
38 | * it under the terms of the GNU General Public License as published by |
||
39 | * the Free Software Foundation; either version 2 of the License, or |
||
40 | * (at your option) any later version. |
||
41 | * |
||
42 | * This program is distributed in the hope that it will be useful, |
||
43 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
44 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
45 | * GNU General Public License for more details. |
||
46 | * |
||
47 | * You should have received a copy of the GNU General Public License |
||
48 | * along with this program; if not, write to the Free Software |
||
49 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
50 | * |
||
51 | * CVS : $Id: ppnrtdrv.c,v 1.1 2002-10-28 08:03:54 pj Exp $ |
||
52 | */ |
||
53 | |||
54 | |||
55 | /******************************************************************************************* |
||
56 | * A standard PC provides for three printer ports, at the following base addresses: |
||
57 | * |
||
58 | * LPT1 = 0x0378 or 0x03BC |
||
59 | * LPT2 = 0x0278 or 0x0378 |
||
60 | * LPT3 = 0x0278 |
||
61 | * |
||
62 | * This module assumes that LPT1 is at 0x0378. |
||
63 | * |
||
64 | * The printer port has three 8-bit registers: |
||
65 | * |
||
66 | * Data Register (base + 0) ........ outputs |
||
67 | * |
||
68 | * 7 6 5 4 3 2 1 0 |
||
69 | * . . . . . . . * D0 ........... (pin 2), 1=High, 0=Low (true) |
||
70 | * . . . . . . * . D1 ........... (pin 3), 1=High, 0=Low (true) |
||
71 | * . . . . . * . . D2 ........... (pin 4), 1=High, 0=Low (true) |
||
72 | * . . . . * . . . D3 ........... (pin 5), 1=High, 0=Low (true) |
||
73 | * . . . * . . . . D4 ........... (pin 6), 1=High, 0=Low (true) |
||
74 | * . . * . . . . . D5 ........... (pin 7), 1=High, 0=Low (true) |
||
75 | * . * . . . . . . D6 ........... (pin 8), 1=High, 0=Low (true) |
||
76 | * * . . . . . . . D7 ........... (pin 9), 1=High, 0=Low (true) |
||
77 | * |
||
78 | * Status Register (base + 1) ...... inputs |
||
79 | * |
||
80 | * 7 6 5 4 3 2 1 0 |
||
81 | * . . . . . * * * Undefined |
||
82 | * . . . . * . . . Error ........ (pin 15), high=1, low=0 (true) |
||
83 | * . . . * . . . . Selected ..... (pin 13), high=1, low=0 (true) |
||
84 | * . . * . . . . . No paper ..... (pin 12), high=1, low=0 (true) |
||
85 | * . * . . . . . . Ack .......... (pin 10), high=1, low=0 (true) |
||
86 | * * . . . . . . . Busy ......... (pin 11), high=0, low=1 (inverted) |
||
87 | * |
||
88 | * Control Register (base + 2) ..... outputs |
||
89 | * |
||
90 | * 7 6 5 4 3 2 1 0 |
||
91 | * . . . . . . . * Strobe ....... (pin 1), 1=low, 0=high (inverted) |
||
92 | * . . . . . . * . Auto Feed .... (pin 14), 1=low, 0=high (inverted) |
||
93 | * . . . . . * . . Initialize ... (pin 16), 1=high, 0=low (true) |
||
94 | * . . . . * . . . Select ....... (pin 17), 1=low, 0=high (inverted) |
||
95 | * * * * * . . . . Unused |
||
96 | * |
||
97 | * Pins 18-25 are ground. |
||
98 | ********************************************************************************************/ |
||
99 | |||
100 | |||
101 | #include <drivers/parport.h> |
||
102 | |||
103 | |||
104 | /*************************************************************************/ |
||
105 | BOOL ppNRTWaitRTS(void) |
||
106 | { |
||
107 | BYTE port; |
||
108 | TIME start = clock(); |
||
109 | do |
||
110 | { |
||
111 | port = ~inp(RX_PORT); /* port status */ |
||
112 | port = port & RX_CTR; /* test cntr read bit*/ |
||
113 | if(clock() > start + CLK_TIMEOUT) return TIMEOUT; |
||
114 | } while(port == 0); |
||
115 | return TRUE; |
||
116 | } |
||
117 | |||
118 | /*************************************************************************/ |
||
119 | BOOL ppNRTWaitDR(void) |
||
120 | { |
||
121 | BYTE port; |
||
122 | TIME start = clock(); /* start */ |
||
123 | do { |
||
124 | port = (~inp(RX_PORT)) | (~RX_CTR); /* test cntr read bit*/ |
||
125 | if(clock() > start + CLK_TIMEOUT) return TIMEOUT; |
||
126 | } while(port != 0x7F); /* 0111 1111 */ |
||
127 | |||
128 | return TRUE; |
||
129 | } |
||
130 | |||
131 | /*************************************************************************/ |
||
132 | BOOL ppNRTWaitOTS(void) |
||
133 | { |
||
134 | BYTE port; |
||
135 | TIME start = clock(); /* start time */ |
||
136 | do |
||
137 | { |
||
138 | port = ~inp(RX_PORT); /* read port status */ |
||
139 | port = port & RX_CTR; /* test cntr read bit*/ |
||
140 | if(clock() > start + CLK_TIMEOUT) return TIMEOUT; |
||
141 | } while(port == 0); |
||
142 | return TRUE; |
||
143 | } |
||
144 | |||
145 | /*************************************************************************/ |
||
146 | BOOL ppNRTWaitER(void) |
||
147 | { |
||
148 | BYTE port; |
||
149 | TIME start = clock(); /* start */ |
||
150 | do |
||
151 | { |
||
152 | port = ~inp(RX_PORT); /* read port status */ |
||
153 | port = port | (~RX_CTR); /* test cntr read bit*/ |
||
154 | if(clock() > start + CLK_TIMEOUT) return TIMEOUT; |
||
155 | } while(port != 0x7F); /* 0111 1111 */ |
||
156 | return TRUE; |
||
157 | } |
||
158 | |||
159 | |||
160 | /**************************************************************************/ |
||
161 | BOOL ppNRTTxOneByte(BYTE c) |
||
162 | { |
||
163 | BYTE port; |
||
164 | /*------------------------- Least Significative Nibble */ |
||
165 | ppSendRTS(); /* Request To Send */ |
||
166 | |||
167 | port = inp(TX_PORT); /* read port status */ |
||
168 | port = port & (~TX_DATA); /* set tx bits == 0 */ |
||
169 | port = port | (c & LSN); /* set bit 0..3 with LSN */ |
||
170 | |||
171 | #if PP_DEBUG == 1 |
||
172 | kern_printf("ppNRTTxOneByte: SendRTS, before WaitOTS\n"); |
||
173 | #endif |
||
174 | |||
175 | if(ppNRTWaitOTS()!=TRUE) return TIMEOUT; |
||
176 | outp(TX_PORT,port); |
||
177 | ppSendDR(); /* Data Ready */ |
||
178 | |||
179 | #if PP_DEBUG == 1 |
||
180 | kern_printf("ppNRTTxOneByte: SendDR, before WaitER\n"); |
||
181 | #endif |
||
182 | |||
183 | |||
184 | if(ppNRTWaitER() !=TRUE) return TIMEOUT; |
||
185 | |||
186 | /*------------------------- More Significative Nibble */ |
||
187 | ppSendRTS(); /* Request To Send */ |
||
188 | |||
189 | port = inp(TX_PORT); /* read port status */ |
||
190 | port = port & (~TX_DATA); /* set off trasmission bits... */ |
||
191 | port = port | (c >> 4); /* set bit 0..3 with MSN */ |
||
192 | |||
193 | #if PP_DEBUG == 1 |
||
194 | kern_printf("ppNRTTxOneByte: SendRTS, before WaitOTS\n"); |
||
195 | #endif |
||
196 | |||
197 | if(ppNRTWaitOTS()!=TRUE) return TIMEOUT; |
||
198 | outp(TX_PORT,port); /* send data nibble... */ |
||
199 | ppSendDR(); /* Data Ready */ |
||
200 | |||
201 | #if PP_DEBUG == 1 |
||
202 | kern_printf("ppNRTTxOneByte: SendDR, before WaitER\n"); |
||
203 | #endif |
||
204 | |||
205 | if(ppNRTWaitER() !=TRUE) return TIMEOUT; |
||
206 | |||
207 | return TRUE; |
||
208 | } |
||
209 | |||
210 | /**************************************************************************/ |
||
211 | BOOL ppNRTRxOneByte(BYTE *c) |
||
212 | { |
||
213 | BYTE port; |
||
214 | |||
215 | if(ppIsRTS() == FALSE) return FALSE; |
||
216 | |||
217 | |||
218 | ppSendOTS(); /* Ok To Send */ |
||
219 | |||
220 | #if PP_DEBUG == 1 |
||
221 | kern_printf("ppNRTRxOneByte: IsRTS, SendOTS, before WaitDR\n"); |
||
222 | #endif |
||
223 | |||
224 | if(ppNRTWaitDR() != TRUE) return TIMEOUT; |
||
225 | port = inp(RX_PORT); /* read nibble */ |
||
226 | ppSendER(); /* End Read */ |
||
227 | *c = (port >> 3); /* read LSN */ |
||
228 | |||
229 | #if PP_DEBUG == 1 |
||
230 | kern_printf("ppNRTRxOneByte: SendER, before WaitRTS\n"); |
||
231 | #endif |
||
232 | |||
233 | if(ppNRTWaitRTS() != TRUE) return TIMEOUT; |
||
234 | ppSendOTS(); |
||
235 | |||
236 | #if PP_DEBUG == 1 |
||
237 | kern_printf("ppNRTRxOneByte: SendOTS, before WaitDR\n"); |
||
238 | #endif |
||
239 | |||
240 | if(ppNRTWaitDR() != TRUE) return TIMEOUT; |
||
241 | |||
242 | #if PP_DEBUG == 1 |
||
243 | kern_printf("ppNRTRxOneByte: DR received, send ER\n"); |
||
244 | #endif |
||
245 | |||
246 | port = inp(RX_PORT); /* read nibble */ |
||
247 | ppSendER(); /* End Read */ |
||
248 | *c = (*c & ~MSN); /* set 0 c MSN nibble... */ |
||
249 | *c = (*c | ((port >> 3) << 4)); /* read MSN */ |
||
250 | |||
251 | return TRUE; |
||
252 | } |
||
253 | |||
254 | |||
255 | /************************************************************************* |
||
256 | ------------------------------------------------------------------------*/ |
||
257 | BOOL ppNRTOpenComm(void) |
||
258 | { |
||
259 | BYTE c,port,rx,tx; |
||
260 | TIME start = clock(); |
||
261 | |||
262 | outp(TX_PORT,0); |
||
263 | outp(TX_CTR,0); |
||
264 | |||
265 | do |
||
266 | { |
||
267 | port = inp(RX_PORT); /* read nibble */ |
||
268 | /* x4321x xx */ |
||
269 | c = (port >> 3); /* xxxx 4321 */ |
||
270 | c = c & 0xF; /* 0000 4321 */ |
||
271 | if(clock() > start + CLK_TIMEOUT*20) return TIMEOUT; |
||
272 | |||
273 | } while (c != 0); /* test nibble 4321 == 0000 */ |
||
274 | |||
275 | /* the other also is laying down his TX_PORT (==my RX_PORT...) */ |
||
276 | |||
277 | rx = FALSE; tx = FALSE; start = clock(); |
||
278 | do /* try if it also on line... */ |
||
279 | { |
||
280 | |||
281 | if((rx == FALSE) && (ppNRTRxOneByte(&c)==TRUE) && (c == BYTE_CTR)) rx = TRUE; |
||
282 | if((tx == FALSE) && (ppNRTTxOneByte(BYTE_CTR) == TRUE)) tx = TRUE; |
||
283 | |||
284 | if(clock() > start + CLK_TIMEOUT*20) return TIMEOUT; |
||
285 | |||
286 | } while(tx==FALSE || rx==FALSE); |
||
287 | |||
288 | ppSendER(); |
||
289 | ppNRTWaitER(); |
||
290 | |||
291 | return TRUE; |
||
292 | |||
293 | } |
||
294 | |||
295 |