| @@ -1,1104 +1,1104 @@ | | | @@ -1,1104 +1,1104 @@ |
1 | /* $NetBSD: scr.c,v 1.26 2011/07/26 08:56:26 mrg Exp $ */ | | 1 | /* $NetBSD: scr.c,v 1.27 2012/01/31 04:28:50 matt Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 1997 | | 4 | * Copyright 1997 |
5 | * Digital Equipment Corporation. All rights reserved. | | 5 | * Digital Equipment Corporation. All rights reserved. |
6 | * | | 6 | * |
7 | * This software is furnished under license and may be used and | | 7 | * This software is furnished under license and may be used and |
8 | * copied only in accordance with the following terms and conditions. | | 8 | * copied only in accordance with the following terms and conditions. |
9 | * Subject to these conditions, you may download, copy, install, | | 9 | * Subject to these conditions, you may download, copy, install, |
10 | * use, modify and distribute this software in source and/or binary | | 10 | * use, modify and distribute this software in source and/or binary |
11 | * form. No title or ownership is transferred hereby. | | 11 | * form. No title or ownership is transferred hereby. |
12 | * | | 12 | * |
13 | * 1) Any source code used, modified or distributed must reproduce | | 13 | * 1) Any source code used, modified or distributed must reproduce |
14 | * and retain this copyright notice and list of conditions as | | 14 | * and retain this copyright notice and list of conditions as |
15 | * they appear in the source file. | | 15 | * they appear in the source file. |
16 | * | | 16 | * |
17 | * 2) No right is granted to use any trade name, trademark, or logo of | | 17 | * 2) No right is granted to use any trade name, trademark, or logo of |
18 | * Digital Equipment Corporation. Neither the "Digital Equipment | | 18 | * Digital Equipment Corporation. Neither the "Digital Equipment |
19 | * Corporation" name nor any trademark or logo of Digital Equipment | | 19 | * Corporation" name nor any trademark or logo of Digital Equipment |
20 | * Corporation may be used to endorse or promote products derived | | 20 | * Corporation may be used to endorse or promote products derived |
21 | * from this software without the prior written permission of | | 21 | * from this software without the prior written permission of |
22 | * Digital Equipment Corporation. | | 22 | * Digital Equipment Corporation. |
23 | * | | 23 | * |
24 | * 3) This software is provided "AS-IS" and any express or implied | | 24 | * 3) This software is provided "AS-IS" and any express or implied |
25 | * warranties, including but not limited to, any implied warranties | | 25 | * warranties, including but not limited to, any implied warranties |
26 | * of merchantability, fitness for a particular purpose, or | | 26 | * of merchantability, fitness for a particular purpose, or |
27 | * non-infringement are disclaimed. In no event shall DIGITAL be | | 27 | * non-infringement are disclaimed. In no event shall DIGITAL be |
28 | * liable for any damages whatsoever, and in particular, DIGITAL | | 28 | * liable for any damages whatsoever, and in particular, DIGITAL |
29 | * shall not be liable for special, indirect, consequential, or | | 29 | * shall not be liable for special, indirect, consequential, or |
30 | * incidental damages or damages for lost profits, loss of | | 30 | * incidental damages or damages for lost profits, loss of |
31 | * revenue or loss of use, whether such damages arise in contract, | | 31 | * revenue or loss of use, whether such damages arise in contract, |
32 | * negligence, tort, under statute, in equity, at law or otherwise, | | 32 | * negligence, tort, under statute, in equity, at law or otherwise, |
33 | * even if advised of the possibility of such damage. | | 33 | * even if advised of the possibility of such damage. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | /* | | 36 | /* |
37 | **++ | | 37 | **++ |
38 | ** | | 38 | ** |
39 | ** FACILITY: | | 39 | ** FACILITY: |
40 | ** | | 40 | ** |
41 | ** Driver for smart card | | 41 | ** Driver for smart card |
42 | ** | | 42 | ** |
43 | ** ABSTRACT: | | 43 | ** ABSTRACT: |
44 | ** | | 44 | ** |
45 | ** The driver provides access to a Smart Card for the DNARD. | | 45 | ** The driver provides access to a Smart Card for the DNARD. |
46 | ** | | 46 | ** |
47 | ** There is no Smart Card silicon. Several i/o pins | | 47 | ** There is no Smart Card silicon. Several i/o pins |
48 | ** connect to the pads on the Smart Card, and the driver is | | 48 | ** connect to the pads on the Smart Card, and the driver is |
49 | ** is responsible for driving the signals in accordance with | | 49 | ** is responsible for driving the signals in accordance with |
50 | ** ISO 7816-3 (the Smart Card spec) | | 50 | ** ISO 7816-3 (the Smart Card spec) |
51 | ** | | 51 | ** |
52 | ** This driver puts a high load on the system due to the need | | 52 | ** This driver puts a high load on the system due to the need |
53 | ** to interrupt at a high rate (up to 50 kHz) during bit detection. | | 53 | ** to interrupt at a high rate (up to 50 kHz) during bit detection. |
54 | ** | | 54 | ** |
55 | ** | | 55 | ** |
56 | ** The driver is dived into the standard top half ioctl, and bottom | | 56 | ** The driver is dived into the standard top half ioctl, and bottom |
57 | ** half interrupt. The interrupt is FIQ, which requires its own stack. | | 57 | ** half interrupt. The interrupt is FIQ, which requires its own stack. |
58 | ** disable_interrupts and restore_interrupts must be used to protect from | | 58 | ** disable_interrupts and restore_interrupts must be used to protect from |
59 | ** a FIQ. Since splxxx functions do not use this, the bottom half cannot | | 59 | ** a FIQ. Since splxxx functions do not use this, the bottom half cannot |
60 | ** use any standard functions (ie like wakeup, timeout, etc. | | 60 | ** use any standard functions (ie like wakeup, timeout, etc. |
61 | ** Thus the communication from the bottom half | | 61 | ** Thus the communication from the bottom half |
62 | ** to the top half uses a "done" bit called masterDone. This bit | | 62 | ** to the top half uses a "done" bit called masterDone. This bit |
63 | ** is set by the master state machine when all bottom half work is | | 63 | ** is set by the master state machine when all bottom half work is |
64 | ** complete. The top half checks/sleeps on this masterDone bit. | | 64 | ** complete. The top half checks/sleeps on this masterDone bit. |
65 | ** | | 65 | ** |
66 | ** The FIQ is driven by Timer 2 (T2)in the sequoia. All times are | | 66 | ** The FIQ is driven by Timer 2 (T2)in the sequoia. All times are |
67 | ** referenced to T2 counts. | | 67 | ** referenced to T2 counts. |
68 | ** | | 68 | ** |
69 | ** The bottom half is done as a several linked state machines. | | 69 | ** The bottom half is done as a several linked state machines. |
70 | ** The top level machine is the maserSM (ie master State Machine). This | | 70 | ** The top level machine is the maserSM (ie master State Machine). This |
71 | ** machine calls mid level protocol machines, ie ATRSM (Answer To Reset | | 71 | ** machine calls mid level protocol machines, ie ATRSM (Answer To Reset |
72 | ** State Machine), t0SendSM (T=0 Send State Machine), and t0RecvSM (T=0 Recv | | 72 | ** State Machine), t0SendSM (T=0 Send State Machine), and t0RecvSM (T=0 Recv |
73 | ** State Machine). These mid level protocol machines in turn call low level | | 73 | ** State Machine). These mid level protocol machines in turn call low level |
74 | ** bit-bashing machines, ie coldResetSM, t0SendByteSM, T0RecvByteSM. | | 74 | ** bit-bashing machines, ie coldResetSM, t0SendByteSM, T0RecvByteSM. |
75 | ** | | 75 | ** |
76 | ** Smart Cards are driven in a command/response mode. Ie you issue a command | | 76 | ** Smart Cards are driven in a command/response mode. Ie you issue a command |
77 | ** to the Smart Card and it responds. This command/response mode is reflected | | 77 | ** to the Smart Card and it responds. This command/response mode is reflected |
78 | ** in the structure of the driver. Ie the ioctl gets a command, it | | 78 | ** in the structure of the driver. Ie the ioctl gets a command, it |
79 | ** gives it to the bottom half to execute and goes to sleep. The bottom half | | 79 | ** gives it to the bottom half to execute and goes to sleep. The bottom half |
80 | ** executes the command and gets the response to from the card and then | | 80 | ** executes the command and gets the response to from the card and then |
81 | ** notifies the top half that it has completed. Commands usually complete | | 81 | ** notifies the top half that it has completed. Commands usually complete |
82 | ** in under a second. | | 82 | ** in under a second. |
83 | ** | | 83 | ** |
84 | ** | | 84 | ** |
85 | ** | | 85 | ** |
86 | ** AUTHORS: | | 86 | ** AUTHORS: |
87 | ** | | 87 | ** |
88 | ** E. J. Grohn | | 88 | ** E. J. Grohn |
89 | ** Digital Equipment Corporation. | | 89 | ** Digital Equipment Corporation. |
90 | ** | | 90 | ** |
91 | ** CREATION DATE: | | 91 | ** CREATION DATE: |
92 | ** | | 92 | ** |
93 | ** 27-July-97 | | 93 | ** 27-July-97 |
94 | ** | | 94 | ** |
95 | **-- | | 95 | **-- |
96 | */ | | 96 | */ |
97 | | | 97 | |
98 | /* | | 98 | /* |
99 | ** | | 99 | ** |
100 | ** INCLUDE FILES | | 100 | ** INCLUDE FILES |
101 | ** | | 101 | ** |
102 | */ | | 102 | */ |
103 | | | 103 | |
104 | #include <sys/cdefs.h> | | 104 | #include <sys/cdefs.h> |
105 | __KERNEL_RCSID(0, "$NetBSD: scr.c,v 1.26 2011/07/26 08:56:26 mrg Exp $"); | | 105 | __KERNEL_RCSID(0, "$NetBSD: scr.c,v 1.27 2012/01/31 04:28:50 matt Exp $"); |
106 | | | 106 | |
107 | #include "opt_ddb.h" | | 107 | #include "opt_ddb.h" |
108 | | | 108 | |
109 | #include <sys/param.h> | | 109 | #include <sys/param.h> |
110 | #include <sys/systm.h> | | 110 | #include <sys/systm.h> |
111 | #include <sys/ioctl.h> | | 111 | #include <sys/ioctl.h> |
112 | /* #include <sys/select.h> */ | | 112 | /* #include <sys/select.h> */ |
113 | /* #include <sys/tty.h> */ | | 113 | /* #include <sys/tty.h> */ |
114 | #include <sys/proc.h> | | 114 | #include <sys/proc.h> |
115 | #include <sys/conf.h> | | 115 | #include <sys/conf.h> |
116 | /* #include <sys/file.h> */ | | 116 | /* #include <sys/file.h> */ |
117 | /* #include <sys/uio.h> */ | | 117 | /* #include <sys/uio.h> */ |
118 | #include <sys/kernel.h> | | 118 | #include <sys/kernel.h> |
119 | /* #include <sys/syslog.h> */ | | 119 | /* #include <sys/syslog.h> */ |
120 | #include <sys/types.h> | | 120 | #include <sys/types.h> |
121 | #include <sys/device.h> | | 121 | #include <sys/device.h> |
122 | #include <dev/isa/isavar.h> | | 122 | #include <dev/isa/isavar.h> |
123 | #include <arm/cpufunc.h> | | 123 | #include <arm/cpufunc.h> |
124 | | | 124 | |
125 | | | 125 | |
126 | /* SCR_DEBUG is the master switch for turning on debugging */ | | 126 | /* SCR_DEBUG is the master switch for turning on debugging */ |
127 | //#define SCR_DEBUG 1 | | 127 | //#define SCR_DEBUG 1 |
128 | #ifdef SCR_DEBUG | | 128 | #ifdef SCR_DEBUG |
129 | #define KERNEL_DEBUG | | 129 | #define KERNEL_DEBUG |
130 | #ifdef DDB | | 130 | #ifdef DDB |
131 | #define DEBUGGER printf("file = %s, line = %d\n",__FILE__,__LINE__);Debugger() | | 131 | #define DEBUGGER printf("file = %s, line = %d\n",__FILE__,__LINE__);Debugger() |
132 | #else | | 132 | #else |
133 | #define DEBUGGER panic("file = %s, line = %d",__FILE__,__LINE__); | | 133 | #define DEBUGGER panic("file = %s, line = %d",__FILE__,__LINE__); |
134 | #endif | | 134 | #endif |
135 | #else | | 135 | #else |
136 | #define DEBUGGER | | 136 | #define DEBUGGER |
137 | #endif | | 137 | #endif |
138 | | | 138 | |
139 | | | 139 | |
140 | #include <machine/kerndebug.h> | | 140 | #include <machine/kerndebug.h> |
141 | //#include <machine/intr.h> | | 141 | //#include <machine/intr.h> |
142 | #include <dev/ic/i8253reg.h> | | 142 | #include <dev/ic/i8253reg.h> |
143 | #include <shark/shark/hat.h> | | 143 | #include <shark/shark/hat.h> |
144 | #include <shark/shark/sequoia.h> | | 144 | #include <shark/shark/sequoia.h> |
145 | #include <machine/scrio.h> | | 145 | #include <machine/scrio.h> |
146 | | | 146 | |
147 | | | 147 | |
148 | | | 148 | |
149 | | | 149 | |
150 | /* | | 150 | /* |
151 | ** | | 151 | ** |
152 | ** MACRO DEFINITIONS | | 152 | ** MACRO DEFINITIONS |
153 | ** | | 153 | ** |
154 | */ | | 154 | */ |
155 | | | 155 | |
156 | | | 156 | |
157 | #define scr_lcr scr_cfcr | | 157 | #define scr_lcr scr_cfcr |
158 | | | 158 | |
159 | /* | | 159 | /* |
160 | ** Macro to extract the minor device number from the device Identifier | | 160 | ** Macro to extract the minor device number from the device Identifier |
161 | */ | | 161 | */ |
162 | #define SCRUNIT(x) (minor(x)) | | 162 | #define SCRUNIT(x) (minor(x)) |
163 | | | 163 | |
164 | /* | | 164 | /* |
165 | ** some macros to assist in debugging | | 165 | ** some macros to assist in debugging |
166 | */ | | 166 | */ |
167 | #ifdef SCR_DEBUG | | 167 | #ifdef SCR_DEBUG |
168 | #define KERNEL_DEBUG | | 168 | #define KERNEL_DEBUG |
169 | #define ASSERT(f) do { if (!(f)) { DEBUGGER;} }while(0) | | 169 | #define ASSERT(f) do { if (!(f)) { DEBUGGER;} }while(0) |
170 | #define TOGGLE_TEST_PIN() scrToggleTestPin() | | 170 | #define TOGGLE_TEST_PIN() scrToggleTestPin() |
171 | #define INVALID_STATE_CMD(sc,state,cmd) invalidStateCmd(sc,state,cmd,__LINE__); | | 171 | #define INVALID_STATE_CMD(sc,state,cmd) invalidStateCmd(sc,state,cmd,__LINE__); |
172 | #else | | 172 | #else |
173 | #define ASSERT(f) | | 173 | #define ASSERT(f) |
174 | #define TOGGLE_TEST_PIN() | | 174 | #define TOGGLE_TEST_PIN() |
175 | //#define INVALID_STATE_CMD(sc,state,cmd) panic("scr: invalid state/cmd, sc = %X, state = %X, cmd = %X, line = %d",sc,state,cmd,__LINE__); | | 175 | //#define INVALID_STATE_CMD(sc,state,cmd) panic("scr: invalid state/cmd, sc = %X, state = %X, cmd = %X, line = %d",sc,state,cmd,__LINE__); |
176 | #define INVALID_STATE_CMD(sc,state,cmd) sc->bigTrouble = true; | | 176 | #define INVALID_STATE_CMD(sc,state,cmd) sc->bigTrouble = true; |
177 | | | 177 | |
178 | #endif | | 178 | #endif |
179 | | | 179 | |
180 | | | 180 | |
181 | /* | | 181 | /* |
182 | ** The first and last bytes of the debug control variables is reserved for | | 182 | ** The first and last bytes of the debug control variables is reserved for |
183 | ** the standard KERN_DEBUG_xxx macros, so we can tailor the middle two bytes | | 183 | ** the standard KERN_DEBUG_xxx macros, so we can tailor the middle two bytes |
184 | */ | | 184 | */ |
185 | #define SCRPROBE_DEBUG_INFO 0x00000100 | | 185 | #define SCRPROBE_DEBUG_INFO 0x00000100 |
186 | #define SCRATTACH_DEBUG_INFO 0x00000200 | | 186 | #define SCRATTACH_DEBUG_INFO 0x00000200 |
187 | #define SCROPEN_DEBUG_INFO 0x00000400 | | 187 | #define SCROPEN_DEBUG_INFO 0x00000400 |
188 | #define SCRCLOSE_DEBUG_INFO 0x00000800 | | 188 | #define SCRCLOSE_DEBUG_INFO 0x00000800 |
189 | #define SCRREAD_DEBUG_INFO 0x00001000 | | 189 | #define SCRREAD_DEBUG_INFO 0x00001000 |
190 | #define SCRWRITE_DEBUG_INFO 0x00002000 | | 190 | #define SCRWRITE_DEBUG_INFO 0x00002000 |
191 | #define SCRIOCTL_DEBUG_INFO 0x00004000 | | 191 | #define SCRIOCTL_DEBUG_INFO 0x00004000 |
192 | #define MASTER_SM_DEBUG_INFO 0x00008000 | | 192 | #define MASTER_SM_DEBUG_INFO 0x00008000 |
193 | #define COLD_RESET_SM_DEBUG_INFO 0x00010000 | | 193 | #define COLD_RESET_SM_DEBUG_INFO 0x00010000 |
194 | #define ATR_SM_DEBUG_INFO 0x00020000 | | 194 | #define ATR_SM_DEBUG_INFO 0x00020000 |
195 | #define T0_RECV_BYTE_SM_DEBUG_INFO 0x00040000 | | 195 | #define T0_RECV_BYTE_SM_DEBUG_INFO 0x00040000 |
196 | #define T0_SEND_BYTE_SM_DEBUG_INFO 0x00080000 | | 196 | #define T0_SEND_BYTE_SM_DEBUG_INFO 0x00080000 |
197 | #define T0_RECV_SM_DEBUG_INFO 0x00100000 | | 197 | #define T0_RECV_SM_DEBUG_INFO 0x00100000 |
198 | #define T0_SEND_SM_DEBUG_INFO 0x00200000 | | 198 | #define T0_SEND_SM_DEBUG_INFO 0x00200000 |
199 | | | 199 | |
200 | | | 200 | |
201 | int scrdebug = //SCRPROBE_DEBUG_INFO | | | 201 | int scrdebug = //SCRPROBE_DEBUG_INFO | |
202 | //SCRATTACH_DEBUG_INFO | | | 202 | //SCRATTACH_DEBUG_INFO | |
203 | //SCROPEN_DEBUG_INFO | | | 203 | //SCROPEN_DEBUG_INFO | |
204 | //SCRCLOSE_DEBUG_INFO | | | 204 | //SCRCLOSE_DEBUG_INFO | |
205 | //SCRREAD_DEBUG_INFO | | | 205 | //SCRREAD_DEBUG_INFO | |
206 | //SCRWRITE_DEBUG_INFO | | | 206 | //SCRWRITE_DEBUG_INFO | |
207 | //SCRIOCTL_DEBUG_INFO | | | 207 | //SCRIOCTL_DEBUG_INFO | |
208 | //MASTER_SM_DEBUG_INFO | | | 208 | //MASTER_SM_DEBUG_INFO | |
209 | //COLD_RESET_SM_DEBUG_INFO| | | 209 | //COLD_RESET_SM_DEBUG_INFO| |
210 | //ATR_SM_DEBUG_INFO | | | 210 | //ATR_SM_DEBUG_INFO | |
211 | //T0_RECV_BYTE_SM_DEBUG_INFO | | | 211 | //T0_RECV_BYTE_SM_DEBUG_INFO | |
212 | //T0_SEND_BYTE_SM_DEBUG_INFO | | | 212 | //T0_SEND_BYTE_SM_DEBUG_INFO | |
213 | //T0_RECV_SM_DEBUG_INFO | | | 213 | //T0_RECV_SM_DEBUG_INFO | |
214 | //T0_SEND_SM_DEBUG_INFO | | | 214 | //T0_SEND_SM_DEBUG_INFO | |
215 | 0; | | 215 | 0; |
216 | | | 216 | |
217 | | | 217 | |
218 | | | 218 | |
219 | | | 219 | |
220 | | | 220 | |
221 | | | 221 | |
222 | /* | | 222 | /* |
223 | ** the bottom half of the driver is done as several linked state machines | | 223 | ** the bottom half of the driver is done as several linked state machines |
224 | ** below are all the states of the machines, and the commands that are | | 224 | ** below are all the states of the machines, and the commands that are |
225 | ** sent to each machine | | 225 | ** sent to each machine |
226 | */ | | 226 | */ |
227 | | | 227 | |
228 | /* commands to Master State Machine from ioctl */ | | 228 | /* commands to Master State Machine from ioctl */ |
229 | #define mcOn 0x0100 /* ioctl on */ | | 229 | #define mcOn 0x0100 /* ioctl on */ |
230 | #define mcT0DataSend 0x0102 /* ioctl send */ | | 230 | #define mcT0DataSend 0x0102 /* ioctl send */ |
231 | #define mcT0DataRecv 0x0103 /* ioctl recv */ | | 231 | #define mcT0DataRecv 0x0103 /* ioctl recv */ |
232 | | | 232 | |
233 | /* commands to Master State Machine from lower state machines */ | | 233 | /* commands to Master State Machine from lower state machines */ |
234 | #define mcColdReset 0x0105 /* cold reset finished */ | | 234 | #define mcColdReset 0x0105 /* cold reset finished */ |
235 | #define mcATR 0x0106 /* ATR has finished */ | | 235 | #define mcATR 0x0106 /* ATR has finished */ |
236 | #define mcT0Send 0x0108 /* T0 send finished */ | | 236 | #define mcT0Send 0x0108 /* T0 send finished */ |
237 | #define mcT0Recv 0x010a /* T0 recv finished */ | | 237 | #define mcT0Recv 0x010a /* T0 recv finished */ |
238 | | | 238 | |
239 | /* states in Master state machine (ms = Master State) */ | | 239 | /* states in Master state machine (ms = Master State) */ |
240 | #define msIdleOff 0x0200 /* in idle state, card powered off */ | | 240 | #define msIdleOff 0x0200 /* in idle state, card powered off */ |
241 | #define msColdReset 0x0201 /* turning on power, clock, reset */ | | 241 | #define msColdReset 0x0201 /* turning on power, clock, reset */ |
242 | #define msATR 0x0202 /* getting ATR sequence from card */ | | 242 | #define msATR 0x0202 /* getting ATR sequence from card */ |
243 | #define msIdleOn 0x0203 /* idle, put card powered on */ | | 243 | #define msIdleOn 0x0203 /* idle, put card powered on */ |
244 | #define msT0Send 0x0204 /* sending T0 data */ | | 244 | #define msT0Send 0x0204 /* sending T0 data */ |
245 | #define msT0Recv 0x0205 /* recving T0 data */ | | 245 | #define msT0Recv 0x0205 /* recving T0 data */ |
246 | | | 246 | |
247 | | | 247 | |
248 | | | 248 | |
249 | | | 249 | |
250 | /* commands to T0 send state machine */ | | 250 | /* commands to T0 send state machine */ |
251 | #define t0scStart 0x0300 /* start */ | | 251 | #define t0scStart 0x0300 /* start */ |
252 | #define t0scTWorkWaiting 0x0301 /* work waiting timeout */ | | 252 | #define t0scTWorkWaiting 0x0301 /* work waiting timeout */ |
253 | | | 253 | |
254 | /* states in T0 send state machine */ | | 254 | /* states in T0 send state machine */ |
255 | #define t0ssIdle 0x0400 /* idle state */ | | 255 | #define t0ssIdle 0x0400 /* idle state */ |
256 | #define t0ssSendHeader 0x0401 /* send 5 header bytes */ | | 256 | #define t0ssSendHeader 0x0401 /* send 5 header bytes */ |
257 | #define t0ssRecvProcedure 0x0402 /* wait for procedure byte */ | | 257 | #define t0ssRecvProcedure 0x0402 /* wait for procedure byte */ |
258 | #define t0ssSendByte 0x0403 /* send 1 byte */ | | 258 | #define t0ssSendByte 0x0403 /* send 1 byte */ |
259 | #define t0ssSendData 0x0404 /* send all bytes */ | | 259 | #define t0ssSendData 0x0404 /* send all bytes */ |
260 | #define t0ssRecvSW1 0x0405 /* wait for sw1 */ | | 260 | #define t0ssRecvSW1 0x0405 /* wait for sw1 */ |
261 | #define t0ssRecvSW2 0x0406 /* wait for sw2 */ | | 261 | #define t0ssRecvSW2 0x0406 /* wait for sw2 */ |
262 | | | 262 | |
263 | | | 263 | |
264 | | | 264 | |
265 | | | 265 | |
266 | | | 266 | |
267 | /* commands to T0 recv state machine */ | | 267 | /* commands to T0 recv state machine */ |
268 | #define t0rcStart 0x0500 /* start */ | | 268 | #define t0rcStart 0x0500 /* start */ |
269 | #define t0rcTWorkWaiting 0x0501 /* work waiting timeout */ | | 269 | #define t0rcTWorkWaiting 0x0501 /* work waiting timeout */ |
270 | | | 270 | |
271 | /* states in T0 recv state machine */ | | 271 | /* states in T0 recv state machine */ |
272 | #define t0rsIdle 0x0600 /* idle state */ | | 272 | #define t0rsIdle 0x0600 /* idle state */ |
273 | #define t0rsSendHeader 0x0601 /* send 5 header bytes */ | | 273 | #define t0rsSendHeader 0x0601 /* send 5 header bytes */ |
274 | #define t0rsRecvProcedure 0x0602 /* wait for procedure byte */ | | 274 | #define t0rsRecvProcedure 0x0602 /* wait for procedure byte */ |
275 | #define t0rsRecvByte 0x0603 /* recv 1 byte */ | | 275 | #define t0rsRecvByte 0x0603 /* recv 1 byte */ |
276 | #define t0rsRecvData 0x0604 /* recv all bytes */ | | 276 | #define t0rsRecvData 0x0604 /* recv all bytes */ |
277 | #define t0rsRecvSW1 0x0605 /* wait for sw1 */ | | 277 | #define t0rsRecvSW1 0x0605 /* wait for sw1 */ |
278 | #define t0rsRecvSW2 0x0606 /* wait for sw2 */ | | 278 | #define t0rsRecvSW2 0x0606 /* wait for sw2 */ |
279 | | | 279 | |
280 | | | 280 | |
281 | | | 281 | |
282 | /* commands to Cold Reset state machine */ | | 282 | /* commands to Cold Reset state machine */ |
283 | #define crcStart 0x0900 /* start */ | | 283 | #define crcStart 0x0900 /* start */ |
284 | #define crcT2 0x0902 /* timeout T2 ISO 7816-3, P6, Figure 2 */ | | 284 | #define crcT2 0x0902 /* timeout T2 ISO 7816-3, P6, Figure 2 */ |
285 | | | 285 | |
286 | /* states in cold reset state machine */ | | 286 | /* states in cold reset state machine */ |
287 | #define crsIdle 0x0a00 /* idle */ | | 287 | #define crsIdle 0x0a00 /* idle */ |
288 | #define crsT2Wait 0x0a01 /* wait for T2 ISO 7816-3.P6. Figure 2 */ | | 288 | #define crsT2Wait 0x0a01 /* wait for T2 ISO 7816-3.P6. Figure 2 */ |
289 | | | 289 | |
290 | | | 290 | |
291 | | | 291 | |
292 | | | 292 | |
293 | | | 293 | |
294 | /* commands to Answer To Reset (ATR) state machine */ | | 294 | /* commands to Answer To Reset (ATR) state machine */ |
295 | #define atrcStart 0x0b00 /* start */ | | 295 | #define atrcStart 0x0b00 /* start */ |
296 | #define atrcT3 0x0b04 /* got T3 timeout */ | | 296 | #define atrcT3 0x0b04 /* got T3 timeout */ |
297 | #define atrcTWorkWaiting 0x0b05 /* work waiting timeout */ | | 297 | #define atrcTWorkWaiting 0x0b05 /* work waiting timeout */ |
298 | | | 298 | |
299 | /* states in Answer To Reset (ATR) state machine */ | | 299 | /* states in Answer To Reset (ATR) state machine */ |
300 | #define atrsIdle 0x0c00 /* idle */ | | 300 | #define atrsIdle 0x0c00 /* idle */ |
301 | #define atrsTS 0x0c01 /* looking for TS, (initial bytes) */ | | 301 | #define atrsTS 0x0c01 /* looking for TS, (initial bytes) */ |
302 | #define atrsT0 0x0c02 /* looking for T0, (format bytes) */ | | 302 | #define atrsT0 0x0c02 /* looking for T0, (format bytes) */ |
303 | #define atrsTABCD 0x0c03 /* looking for TAx (interface bytes)*/ | | 303 | #define atrsTABCD 0x0c03 /* looking for TAx (interface bytes)*/ |
304 | #define atrsTK 0x0c04 /* looking for TK (history bytes) */ | | 304 | #define atrsTK 0x0c04 /* looking for TK (history bytes) */ |
305 | #define atrsTCK 0x0c05 /* looking for TCK (check bytes */ | | 305 | #define atrsTCK 0x0c05 /* looking for TCK (check bytes */ |
306 | | | 306 | |
307 | | | 307 | |
308 | /* commands to T0 Recv Byte state machine */ | | 308 | /* commands to T0 Recv Byte state machine */ |
309 | #define t0rbcStart 0x0d00 /* start */ | | 309 | #define t0rbcStart 0x0d00 /* start */ |
310 | #define t0rbcAbort 0x0d01 /* abort */ | | 310 | #define t0rbcAbort 0x0d01 /* abort */ |
311 | #define t0rbcTFindStartEdge 0x0d02 /* start bit edge search */ | | 311 | #define t0rbcTFindStartEdge 0x0d02 /* start bit edge search */ |
312 | #define t0rbcTFindStartMid 0x0d03 /* start bit mid search */ | | 312 | #define t0rbcTFindStartMid 0x0d03 /* start bit mid search */ |
313 | #define t0rbcTClockData 0x0d04 /* data bit search */ | | 313 | #define t0rbcTClockData 0x0d04 /* data bit search */ |
314 | #define t0rbcTErrorStart 0x0d05 /* start to send error */ | | 314 | #define t0rbcTErrorStart 0x0d05 /* start to send error */ |
315 | #define t0rbcTErrorStop 0x0d06 /* stop sending error */ | | 315 | #define t0rbcTErrorStop 0x0d06 /* stop sending error */ |
316 | | | 316 | |
317 | /* states in T0 Recv Byte state machine */ | | 317 | /* states in T0 Recv Byte state machine */ |
318 | #define t0rbsIdle 0x0e00 /* idle */ | | 318 | #define t0rbsIdle 0x0e00 /* idle */ |
319 | #define t0rbsFindStartEdge 0x0e01 /* looking for start bit */ | | 319 | #define t0rbsFindStartEdge 0x0e01 /* looking for start bit */ |
320 | #define t0rbsFindStartMid 0x0e02 /* looking for start bit */ | | 320 | #define t0rbsFindStartMid 0x0e02 /* looking for start bit */ |
321 | #define t0rbsClockData 0x0e03 /* looking for data bits */ | | 321 | #define t0rbsClockData 0x0e03 /* looking for data bits */ |
322 | #define t0rbsSendError 0x0e04 /* output error bit */ | | 322 | #define t0rbsSendError 0x0e04 /* output error bit */ |
323 | | | 323 | |
324 | | | 324 | |
325 | | | 325 | |
326 | | | 326 | |
327 | /* commands to T0 Send Byte state machine */ | | 327 | /* commands to T0 Send Byte state machine */ |
328 | #define t0sbcStart 0x0f00 /* start the machine */ | | 328 | #define t0sbcStart 0x0f00 /* start the machine */ |
329 | #define t0sbcAbort 0x0f01 /* abort the machine */ | | 329 | #define t0sbcAbort 0x0f01 /* abort the machine */ |
330 | #define t0sbcTGuardTime 0x0f02 /* guard time finished */ | | 330 | #define t0sbcTGuardTime 0x0f02 /* guard time finished */ |
331 | #define t0sbcTClockData 0x0f03 /* clock time finished */ | | 331 | #define t0sbcTClockData 0x0f03 /* clock time finished */ |
332 | #define t0sbcTError 0x0f04 /* start to send error */ | | 332 | #define t0sbcTError 0x0f04 /* start to send error */ |
333 | #define t0sbcTResend 0x0f05 /* if parity error, then wait unfill we can re-send */ | | 333 | #define t0sbcTResend 0x0f05 /* if parity error, then wait unfill we can re-send */ |
334 | | | 334 | |
335 | | | 335 | |
336 | | | 336 | |
337 | /* states in T0 Send Byte state machine */ | | 337 | /* states in T0 Send Byte state machine */ |
338 | #define t0sbsIdle 0x1000 /* idle */ | | 338 | #define t0sbsIdle 0x1000 /* idle */ |
339 | #define t0sbsWaitGuardTime 0x1001 /* wait for guard time to finish */ | | 339 | #define t0sbsWaitGuardTime 0x1001 /* wait for guard time to finish */ |
340 | #define t0sbsClockData 0x1002 /* clocking out data & parity */ | | 340 | #define t0sbsClockData 0x1002 /* clocking out data & parity */ |
341 | #define t0sbsWaitError 0x1003 /* waiting for error indicator */ | | 341 | #define t0sbsWaitError 0x1003 /* waiting for error indicator */ |
342 | #define t0sbsWaitResend 0x1004 /* waiting to start re-send if error */ | | 342 | #define t0sbsWaitResend 0x1004 /* waiting to start re-send if error */ |
343 | | | 343 | |
344 | | | 344 | |
345 | | | 345 | |
346 | | | 346 | |
347 | /* | | 347 | /* |
348 | ** generic middle level state machine commands | | 348 | ** generic middle level state machine commands |
349 | ** sent by T0 Send Byte & T0 recv Byte to T0 Send and T0 Recv | | 349 | ** sent by T0 Send Byte & T0 recv Byte to T0 Send and T0 Recv |
350 | */ | | 350 | */ |
351 | #define gcT0RecvByte 0x1100 /* receive finished */ | | 351 | #define gcT0RecvByte 0x1100 /* receive finished */ |
352 | #define gcT0RecvByteErr 0x1101 /* receive got error */ | | 352 | #define gcT0RecvByteErr 0x1101 /* receive got error */ |
353 | #define gcT0SendByte 0x1102 /* send finished */ | | 353 | #define gcT0SendByte 0x1102 /* send finished */ |
354 | #define gcT0SendByteErr 0x1103 /* send got error */ | | 354 | #define gcT0SendByteErr 0x1103 /* send got error */ |
355 | | | 355 | |
356 | | | 356 | |
357 | | | 357 | |
358 | | | 358 | |
359 | | | 359 | |
360 | | | 360 | |
361 | /* | | 361 | /* |
362 | ** | | 362 | ** |
363 | ** below are definitions associated with Smart Card | | 363 | ** below are definitions associated with Smart Card |
364 | ** | | 364 | ** |
365 | */ | | 365 | */ |
366 | | | 366 | |
367 | | | 367 | |
368 | /* | | 368 | /* |
369 | ** Frequency of clock sent to card | | 369 | ** Frequency of clock sent to card |
370 | ** NCI's card is running at 1/2 freq, so in debug we can make | | 370 | ** NCI's card is running at 1/2 freq, so in debug we can make |
371 | ** use of this to toggle more debug signals and still be within | | 371 | ** use of this to toggle more debug signals and still be within |
372 | ** interrupt time budget | | 372 | ** interrupt time budget |
373 | */ | | 373 | */ |
374 | #ifdef SCR_DEBUG | | 374 | #ifdef SCR_DEBUG |
375 | #define CARD_FREQ_DEF (3579000/2) | | 375 | #define CARD_FREQ_DEF (3579000/2) |
376 | #else | | 376 | #else |
377 | #define CARD_FREQ_DEF (3579000) | | 377 | #define CARD_FREQ_DEF (3579000) |
378 | #endif | | 378 | #endif |
379 | | | 379 | |
380 | | | 380 | |
381 | | | 381 | |
382 | /* byte logic level and msb/lsb coding */ | | 382 | /* byte logic level and msb/lsb coding */ |
383 | #define CONVENTION_UNKNOWN 0 | | 383 | #define CONVENTION_UNKNOWN 0 |
384 | #define CONVENTION_INVERSE 1 | | 384 | #define CONVENTION_INVERSE 1 |
385 | #define CONVENTION_DIRECT 2 | | 385 | #define CONVENTION_DIRECT 2 |
386 | #define CONVENIONT_INVERSE_ID 0x3f | | 386 | #define CONVENIONT_INVERSE_ID 0x3f |
387 | #define CONVENTION_DIRECT_FIX 0x3b | | 387 | #define CONVENTION_DIRECT_FIX 0x3b |
388 | #define CONVENTION_DIRECT_ID 0x23 | | 388 | #define CONVENTION_DIRECT_ID 0x23 |
389 | | | 389 | |
390 | | | 390 | |
391 | /* macros that help us set the T2 count for bit bashing */ | | 391 | /* macros that help us set the T2 count for bit bashing */ |
392 | #define CLK_COUNT_START (((372 * TIMER_FREQ) / sc->cardFreq) /5) | | 392 | #define CLK_COUNT_START (((372 * TIMER_FREQ) / sc->cardFreq) /5) |
393 | #define CLK_COUNT_DATA (((372 * TIMER_FREQ) / sc->cardFreq) ) | | 393 | #define CLK_COUNT_DATA (((372 * TIMER_FREQ) / sc->cardFreq) ) |
394 | #define START_2_DATA 5 | | 394 | #define START_2_DATA 5 |
395 | | | 395 | |
396 | /* default settings to use if not specified in ATR */ | | 396 | /* default settings to use if not specified in ATR */ |
397 | #define N_DEFAULT 0 /* guard time default */ | | 397 | #define N_DEFAULT 0 /* guard time default */ |
398 | #define Fi_DEFAULT 372 /* clock rate conversion default */ | | 398 | #define Fi_DEFAULT 372 /* clock rate conversion default */ |
399 | #define Di_DEFAULT 1 /* bit rate adjustment factor */ | | 399 | #define Di_DEFAULT 1 /* bit rate adjustment factor */ |
400 | #define Wi_DEFAULT 10 /* waiting time */ | | 400 | #define Wi_DEFAULT 10 /* waiting time */ |
401 | | | 401 | |
402 | | | 402 | |
403 | /* table for clock rate adjustment in ATR */ | | 403 | /* table for clock rate adjustment in ATR */ |
404 | int FI2Fi[16] = {372, 372, 558, 744,1116,1488,1860, 0, | | 404 | int FI2Fi[16] = {372, 372, 558, 744,1116,1488,1860, 0, |
405 | 0, 512, 768,1024,1536,2048, 0, 0}; | | 405 | 0, 512, 768,1024,1536,2048, 0, 0}; |
406 | | | 406 | |
407 | /* table for bit rate adjustment in ATR*/ | | 407 | /* table for bit rate adjustment in ATR*/ |
408 | int DI2Di[16] = { 0, 1, 2, 4, 8, 16, 32, 0, | | 408 | int DI2Di[16] = { 0, 1, 2, 4, 8, 16, 32, 0, |
409 | 12, 20, 0, 0, 0, 0, 0, 0}; | | 409 | 12, 20, 0, 0, 0, 0, 0, 0}; |
410 | | | 410 | |
411 | /* values of atrY in the ATR sequence*/ | | 411 | /* values of atrY in the ATR sequence*/ |
412 | #define ATR_Y_TA 0x10 | | 412 | #define ATR_Y_TA 0x10 |
413 | #define ATR_Y_TB 0x20 | | 413 | #define ATR_Y_TB 0x20 |
414 | #define ATR_Y_TC 0x40 | | 414 | #define ATR_Y_TC 0x40 |
415 | #define ATR_Y_TD 0x80 | | 415 | #define ATR_Y_TD 0x80 |
416 | | | 416 | |
417 | /* T0,T1,etc information in ATR sequence*/ | | 417 | /* T0,T1,etc information in ATR sequence*/ |
418 | #define PROTOCOL_T0 0x0001 /* bit 0 for T0 */ | | 418 | #define PROTOCOL_T0 0x0001 /* bit 0 for T0 */ |
419 | #define PROTOCOL_T1 0x0002 /* bit 1 for T1 */ | | 419 | #define PROTOCOL_T1 0x0002 /* bit 1 for T1 */ |
420 | #define PROTOCOL_T2 0x0004 /* bit 2 for T2*/ | | 420 | #define PROTOCOL_T2 0x0004 /* bit 2 for T2*/ |
421 | #define PROTOCOL_T3 0x0008 /* bit 3 for T3*/ | | 421 | #define PROTOCOL_T3 0x0008 /* bit 3 for T3*/ |
422 | /* etc */ | | 422 | /* etc */ |
423 | | | 423 | |
424 | | | 424 | |
425 | /* timeouts for various places - see ISO 7816-3 */ | | 425 | /* timeouts for various places - see ISO 7816-3 */ |
426 | #define T_t2 ((300 * TIMER_FREQ) / sc->cardFreq) | | 426 | #define T_t2 ((300 * TIMER_FREQ) / sc->cardFreq) |
427 | #define T_t3 ((40000 * (TIMER_FREQ/1024)) / (sc->cardFreq/1024)) | | 427 | #define T_t3 ((40000 * (TIMER_FREQ/1024)) / (sc->cardFreq/1024)) |
428 | #define T_WORK_WAITING (((960 * sc->Wi * sc->Fi ) / (sc->cardFreq/1024)) * (TIMER_FREQ/1024)) | | 428 | #define T_WORK_WAITING (((960 * sc->Wi * sc->Fi ) / (sc->cardFreq/1024)) * (TIMER_FREQ/1024)) |
429 | #define PARITY_ERROR_MAX 3 /* maximum parity errors on 1 byte before giving up */ | | 429 | #define PARITY_ERROR_MAX 3 /* maximum parity errors on 1 byte before giving up */ |
430 | | | 430 | |
431 | /* | | 431 | /* |
432 | ** its possible for the HAT to wedge. If that happens, all timing is sick, so | | 432 | ** its possible for the HAT to wedge. If that happens, all timing is sick, so |
433 | ** we use timeout below (driven of system sleeps) as a "watchdog" | | 433 | ** we use timeout below (driven of system sleeps) as a "watchdog" |
434 | */ | | 434 | */ |
435 | #define MAX_FIQ_TIME 5 /* maximum time we are willing to run the FIQ */ | | 435 | #define MAX_FIQ_TIME 5 /* maximum time we are willing to run the FIQ */ |
436 | | | 436 | |
437 | | | 437 | |
438 | /* used to decode T0 commands */ | | 438 | /* used to decode T0 commands */ |
439 | #define CMD_BUF_INS_OFF 1 /* offset to INS in header */ | | 439 | #define CMD_BUF_INS_OFF 1 /* offset to INS in header */ |
440 | #define CMD_BUF_DATA_LEN_OFF 4 /* offset to data length in header */ | | 440 | #define CMD_BUF_DATA_LEN_OFF 4 /* offset to data length in header */ |
441 | | | 441 | |
442 | | | 442 | |
443 | /* | | 443 | /* |
444 | ** | | 444 | ** |
445 | ** DATA STRUCTURES | | 445 | ** DATA STRUCTURES |
446 | ** | | 446 | ** |
447 | */ | | 447 | */ |
448 | typedef unsigned char BYTE; | | 448 | typedef unsigned char BYTE; |
449 | | | 449 | |
450 | /* our soft c structure */ | | 450 | /* our soft c structure */ |
451 | struct scr_softc | | 451 | struct scr_softc |
452 | { | | 452 | { |
453 | int open; | | 453 | int open; |
454 | | | 454 | |
455 | /* configuration information */ | | 455 | /* configuration information */ |
456 | int status; /* status to be returned */ | | 456 | int status; /* status to be returned */ |
457 | int cardFreq; /* freq supplied to card */ | | 457 | int cardFreq; /* freq supplied to card */ |
458 | int convention; /* ie direct or inverse */ | | 458 | int convention; /* ie direct or inverse */ |
459 | int protocolType; /* bit 0 indicates T0, bit 1 indicates T1,etc */ | | 459 | int protocolType; /* bit 0 indicates T0, bit 1 indicates T1,etc */ |
460 | int N; /* guard time */ | | 460 | int N; /* guard time */ |
461 | int Fi; /* clock rate */ | | 461 | int Fi; /* clock rate */ |
462 | int Di; /* bit rate adjustment */ | | 462 | int Di; /* bit rate adjustment */ |
463 | int Wi; /* work waiting time */ | | 463 | int Wi; /* work waiting time */ |
464 | int clkCountStartRecv; /* count for clock start bits on recv */ | | 464 | int clkCountStartRecv; /* count for clock start bits on recv */ |
465 | int clkCountDataRecv; /* count for clock data bits on recv*/ | | 465 | int clkCountDataRecv; /* count for clock data bits on recv*/ |
466 | int clkCountDataSend; /* count for clock data bits on send */ | | 466 | int clkCountDataSend; /* count for clock data bits on send */ |
467 | | | 467 | |
468 | /* state machines */ | | 468 | /* state machines */ |
469 | int masterS ; | | 469 | int masterS ; |
470 | int t0RecvS; | | 470 | int t0RecvS; |
471 | int t0SendS; | | 471 | int t0SendS; |
472 | int coldResetS; | | 472 | int coldResetS; |
473 | int ATRS; | | 473 | int ATRS; |
474 | int t0RecvByteS; | | 474 | int t0RecvByteS; |
475 | int t0SendByteS; | | 475 | int t0SendByteS; |
476 | | | 476 | |
477 | /* extra stuff kept for t0send state machine */ | | 477 | /* extra stuff kept for t0send state machine */ |
478 | int commandCount; /* number of command bytes sent */ | | 478 | int commandCount; /* number of command bytes sent */ |
479 | int dataCount; /* number of data bytes send/recv */ | | 479 | int dataCount; /* number of data bytes send/recv */ |
480 | int dataMax; /* max number of data bytes to send/recv */ | | 480 | int dataMax; /* max number of data bytes to send/recv */ |
481 | | | 481 | |
482 | /* extra stuff kept for t0RecvByteS, t0SendByteS machines */ | | 482 | /* extra stuff kept for t0RecvByteS, t0SendByteS machines */ |
483 | void (*t0ByteParent)(struct scr_softc *,int); /* state machine that is controlling this SM */ | | 483 | void (*t0ByteParent)(struct scr_softc *,int); /* state machine that is controlling this SM */ |
484 | int shiftBits; /* number of bits shifted */ | | 484 | int shiftBits; /* number of bits shifted */ |
485 | BYTE shiftByte; /* intermediate value of bit being shifted */ | | 485 | BYTE shiftByte; /* intermediate value of bit being shifted */ |
486 | BYTE dataByte; /* actual value of byte */ | | 486 | BYTE dataByte; /* actual value of byte */ |
487 | int shiftParity; /* value of parity */ | | 487 | int shiftParity; /* value of parity */ |
488 | int shiftParityCount; /* number of retries due to parity error */ | | 488 | int shiftParityCount; /* number of retries due to parity error */ |
489 | | | 489 | |
490 | /* extra stuff kept for ATR machine */ | | 490 | /* extra stuff kept for ATR machine */ |
491 | int atrY; /* indicates if TA,TB,TC,TD is to follow */ | | 491 | int atrY; /* indicates if TA,TB,TC,TD is to follow */ |
492 | int atrK; /* number of historical characters*/ | | 492 | int atrK; /* number of historical characters*/ |
493 | int atrKCount; /* progressive could of historical characters*/ | | 493 | int atrKCount; /* progressive could of historical characters*/ |
494 | int atrTABCDx; /* the 'i' in TA(i), TB(i), TC(i) and TD(i) */ | | 494 | int atrTABCDx; /* the 'i' in TA(i), TB(i), TC(i) and TD(i) */ |
495 | int atrFi; /* value of Fi */ | | 495 | int atrFi; /* value of Fi */ |
496 | int atrDi; /* value of Di */ | | 496 | int atrDi; /* value of Di */ |
497 | | | 497 | |
498 | int masterDone; /* flag used by bottom half to tell top half its done */ | | 498 | int masterDone; /* flag used by bottom half to tell top half its done */ |
499 | int bigTrouble; /* david/jim, remove this when the dust settles */ | | 499 | int bigTrouble; /* david/jim, remove this when the dust settles */ |
500 | | | 500 | |
501 | /* pointers used by ioctl */ | | 501 | /* pointers used by ioctl */ |
502 | ScrOn * pIoctlOn; /* pointer to on ioctl data */ | | 502 | ScrOn * pIoctlOn; /* pointer to on ioctl data */ |
503 | ScrT0 * pIoctlT0; /* pointer to T0 ioctl data */ | | 503 | ScrT0 * pIoctlT0; /* pointer to T0 ioctl data */ |
504 | }; | | 504 | }; |
505 | | | 505 | |
506 | /* number of devices */ | | 506 | /* number of devices */ |
507 | static int devices = 0; | | 507 | static int devices = 0; |
508 | | | 508 | |
509 | /* used as reference for tsleep */ | | 509 | /* used as reference for tsleep */ |
510 | static int tsleepIdent; | | 510 | static int tsleepIdent; |
511 | | | 511 | |
512 | | | 512 | |
513 | /* | | 513 | /* |
514 | ** only 1 device is using the hat at any one time | | 514 | ** only 1 device is using the hat at any one time |
515 | ** variable below must be acquired using splhigh before using the hat | | 515 | ** variable below must be acquired using splhigh before using the hat |
516 | */ | | 516 | */ |
517 | static int hatLock = false; | | 517 | static int hatLock = false; |
518 | | | 518 | |
519 | | | 519 | |
520 | | | 520 | |
521 | | | 521 | |
522 | /* | | 522 | /* |
523 | ** data structures associated with our timeout queue that we run for the | | 523 | ** data structures associated with our timeout queue that we run for the |
524 | ** bottom half of the driver | | 524 | ** bottom half of the driver |
525 | */ | | 525 | */ |
526 | | | 526 | |
527 | /* timeout callout structure */ | | 527 | /* timeout callout structure */ |
528 | typedef struct callout_t | | 528 | typedef struct callout_t |
529 | { | | 529 | { |
530 | struct callout_t *c_next; /* next callout in queue */ | | 530 | struct callout_t *c_next; /* next callout in queue */ |
531 | struct scr_softc *c_sc; /* soft c */ | | 531 | struct scr_softc *c_sc; /* soft c */ |
532 | int c_arg; /* function argument */ | | 532 | int c_arg; /* function argument */ |
533 | void (*c_func)(struct scr_softc*,int); /* function to call */ | | 533 | void (*c_func)(struct scr_softc*,int); /* function to call */ |
534 | int c_time; /* ticks to the event */ | | 534 | int c_time; /* ticks to the event */ |
535 | }Callout; | | 535 | }Callout; |
536 | | | 536 | |
537 | /* actual callout array */ | | 537 | /* actual callout array */ |
538 | #define SCR_CLK_CALLOUT_COUNT 10 | | 538 | #define SCR_CLK_CALLOUT_COUNT 10 |
539 | static Callout scrClkCalloutArray[SCR_CLK_CALLOUT_COUNT]; | | 539 | static Callout scrClkCalloutArray[SCR_CLK_CALLOUT_COUNT]; |
540 | | | 540 | |
541 | /* callout lists */ | | 541 | /* callout lists */ |
542 | static Callout *scrClkCallFree; /* free queue */ | | 542 | static Callout *scrClkCallFree; /* free queue */ |
543 | static Callout scrClkCallTodo; /* todo queue */ | | 543 | static Callout scrClkCallTodo; /* todo queue */ |
544 | | | 544 | |
545 | /* | | 545 | /* |
546 | ** information kept for the clock/FIQ that drives our timeout queue | | 546 | ** information kept for the clock/FIQ that drives our timeout queue |
547 | */ | | 547 | */ |
548 | static int scrClkEnable = 0; /* true if clock enabled */ | | 548 | static int scrClkEnable = 0; /* true if clock enabled */ |
549 | static void myHatWedge(int nFIQs); /* callback that informs us if FIQ has wedged */ | | 549 | static void myHatWedge(int nFIQs); /* callback that informs us if FIQ has wedged */ |
550 | static int scrClkCount; /* number used to set t2 that drives FIQ */ | | 550 | static int scrClkCount; /* number used to set t2 that drives FIQ */ |
551 | | | 551 | |
552 | #define HATSTACKSIZE 1024 /* size of stack used during a FIQ */ | | 552 | #define HATSTACKSIZE 1024 /* size of stack used during a FIQ */ |
553 | static unsigned char hatStack[HATSTACKSIZE]; /* actual stack used during a FIQ */ | | 553 | static unsigned char hatStack[HATSTACKSIZE]; /* actual stack used during a FIQ */ |
554 | | | 554 | |
555 | | | 555 | |
556 | | | 556 | |
557 | | | 557 | |
558 | | | 558 | |
559 | | | 559 | |
560 | | | 560 | |
561 | | | 561 | |
562 | | | 562 | |
563 | | | 563 | |
564 | | | 564 | |
565 | | | 565 | |
566 | /* | | 566 | /* |
567 | ** | | 567 | ** |
568 | ** FUNCTIONAL PROTOTYPES | | 568 | ** FUNCTIONAL PROTOTYPES |
569 | ** | | 569 | ** |
570 | */ | | 570 | */ |
571 | | | 571 | |
572 | /* | | 572 | /* |
573 | ** | | 573 | ** |
574 | ** functions in top half of driver | | 574 | ** functions in top half of driver |
575 | ** | | 575 | ** |
576 | */ | | 576 | */ |
577 | | | 577 | |
578 | /* configure routines */ | | 578 | /* configure routines */ |
579 | int scrprobe(device_t, cfdata_t, void *); | | 579 | int scrprobe(device_t, cfdata_t, void *); |
580 | void scrattach(device_t, device_t, void *); | | 580 | void scrattach(device_t, device_t, void *); |
581 | | | 581 | |
582 | static void initStates(struct scr_softc * sc); | | 582 | static void initStates(struct scr_softc * sc); |
583 | | | 583 | |
584 | | | 584 | |
585 | | | 585 | |
586 | | | 586 | |
587 | /* | | 587 | /* |
588 | ** | | 588 | ** |
589 | ** functions in bottom half of driver | | 589 | ** functions in bottom half of driver |
590 | ** | | 590 | ** |
591 | */ | | 591 | */ |
592 | | | 592 | |
593 | /* top level state machine */ | | 593 | /* top level state machine */ |
594 | static void masterSM(struct scr_softc * sc,int cmd); | | 594 | static void masterSM(struct scr_softc * sc,int cmd); |
595 | | | 595 | |
596 | /* mid level state machines, ie protocols */ | | 596 | /* mid level state machines, ie protocols */ |
597 | static void t0SendSM(struct scr_softc * sc,int cnd); | | 597 | static void t0SendSM(struct scr_softc * sc,int cnd); |
598 | static void t0RecvSM(struct scr_softc * sc,int cnd); | | 598 | static void t0RecvSM(struct scr_softc * sc,int cnd); |
599 | static void ATRSM(struct scr_softc * sc,int cnd); | | 599 | static void ATRSM(struct scr_softc * sc,int cnd); |
600 | | | 600 | |
601 | /* low level state machines, ie bash hardware bits */ | | 601 | /* low level state machines, ie bash hardware bits */ |
602 | static void coldResetSM(struct scr_softc * sc,int cnd); | | 602 | static void coldResetSM(struct scr_softc * sc,int cnd); |
603 | | | 603 | |
604 | static void t0SendByteSM(struct scr_softc * sc,int cnd); | | 604 | static void t0SendByteSM(struct scr_softc * sc,int cnd); |
605 | static void t0RecvByteSM(struct scr_softc * sc,int cnd); | | 605 | static void t0RecvByteSM(struct scr_softc * sc,int cnd); |
606 | | | 606 | |
607 | static void cardOff(struct scr_softc * sc); | | 607 | static void cardOff(struct scr_softc * sc); |
608 | | | 608 | |
609 | /* | | 609 | /* |
610 | ** functions used for our own timeout routines. | | 610 | ** functions used for our own timeout routines. |
611 | ** we cannot use system ones as we are running at a spl level | | 611 | ** we cannot use system ones as we are running at a spl level |
612 | ** that can interrupt the system timeout routines | | 612 | ** that can interrupt the system timeout routines |
613 | */ | | 613 | */ |
614 | static void scrClkInit(void); | | 614 | static void scrClkInit(void); |
615 | static void scrClkStart(struct scr_softc* sc,int countPerTick); | | 615 | static void scrClkStart(struct scr_softc* sc,int countPerTick); |
616 | static void scrClkAdj(int count); | | 616 | static void scrClkAdj(int count); |
617 | static void scrClkStop(void); | | 617 | static void scrClkStop(void); |
618 | static void hatClkIrq(int count); | | 618 | static void hatClkIrq(int count); |
619 | | | 619 | |
620 | static void scrTimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg, int count); | | 620 | static void scrTimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg, int count); |
621 | static void scrUntimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg); | | 621 | static void scrUntimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg); |
622 | | | 622 | |
623 | | | 623 | |
624 | /* debug functions */ | | 624 | /* debug functions */ |
625 | #ifdef SCR_DEBUG | | 625 | #ifdef SCR_DEBUG |
626 | static void invalidStateCmd(struct scr_softc* sc,int state,int cmd, int line); | | 626 | static void invalidStateCmd(struct scr_softc* sc,int state,int cmd, int line); |
627 | static char * getText(int x); | | 627 | static char * getText(int x); |
628 | #endif | | 628 | #endif |
629 | | | 629 | |
630 | | | 630 | |
631 | | | 631 | |
632 | | | 632 | |
633 | | | 633 | |
634 | CFATTACH_DECL_NEW(scr, sizeof(struct scr_softc), | | 634 | CFATTACH_DECL_NEW(scr, sizeof(struct scr_softc), |
635 | scrprobe, scrattach, NULL, NULL); | | 635 | scrprobe, scrattach, NULL, NULL); |
636 | | | 636 | |
637 | extern struct cfdriver scr_cd; | | 637 | extern struct cfdriver scr_cd; |
638 | | | 638 | |
639 | dev_type_open(scropen); | | 639 | dev_type_open(scropen); |
640 | dev_type_close(scrclose); | | 640 | dev_type_close(scrclose); |
641 | dev_type_ioctl(scrioctl); | | 641 | dev_type_ioctl(scrioctl); |
642 | | | 642 | |
643 | const struct cdevsw scr_cdevsw = { | | 643 | const struct cdevsw scr_cdevsw = { |
644 | scropen, scrclose, noread, nowrite, scrioctl, | | 644 | scropen, scrclose, noread, nowrite, scrioctl, |
645 | nostop, notty, nopoll, nommap, nokqfilter, D_TTY | | 645 | nostop, notty, nopoll, nommap, nokqfilter, D_TTY |
646 | }; | | 646 | }; |
647 | | | 647 | |
648 | /* | | 648 | /* |
649 | **++ | | 649 | **++ |
650 | ** FUNCTIONAL DESCRIPTION: | | 650 | ** FUNCTIONAL DESCRIPTION: |
651 | ** | | 651 | ** |
652 | ** scrProbe | | 652 | ** scrProbe |
653 | ** | | 653 | ** |
654 | ** This is the probe routine for the Smart Card. Because the | | 654 | ** This is the probe routine for the Smart Card. Because the |
655 | ** Smart Card is hard wired, there is no probing to peform. The | | 655 | ** Smart Card is hard wired, there is no probing to peform. The |
656 | ** function ensures that a succesfull problem occurs only once. | | 656 | ** function ensures that a succesfull problem occurs only once. |
657 | ** | | 657 | ** |
658 | ** FORMAL PARAMETERS: | | 658 | ** FORMAL PARAMETERS: |
659 | ** | | 659 | ** |
660 | ** parent - input : pointer to the parent device | | 660 | ** parent - input : pointer to the parent device |
661 | ** match - not used | | 661 | ** match - not used |
662 | ** aux - output : pointer to an isa_attach_args structure. | | 662 | ** aux - output : pointer to an isa_attach_args structure. |
663 | ** | | 663 | ** |
664 | ** IMPLICIT INPUTS: | | 664 | ** IMPLICIT INPUTS: |
665 | ** | | 665 | ** |
666 | ** none. | | 666 | ** none. |
667 | ** | | 667 | ** |
668 | ** IMPLICIT OUTPUTS: | | 668 | ** IMPLICIT OUTPUTS: |
669 | ** | | 669 | ** |
670 | ** none. | | 670 | ** none. |
671 | ** | | 671 | ** |
672 | ** FUNCTION VALUE: | | 672 | ** FUNCTION VALUE: |
673 | ** | | 673 | ** |
674 | ** 0 - Probe failed to find the requested device. | | 674 | ** 0 - Probe failed to find the requested device. |
675 | ** 1 - Probe successfully talked to the device. | | 675 | ** 1 - Probe successfully talked to the device. |
676 | ** | | 676 | ** |
677 | ** SIDE EFFECTS: | | 677 | ** SIDE EFFECTS: |
678 | ** | | 678 | ** |
679 | ** none. | | 679 | ** none. |
680 | **-- | | 680 | **-- |
681 | */ | | 681 | */ |
682 | int | | 682 | int |
683 | scrprobe(device_t parent, cfdata_t match, void *aux) | | 683 | scrprobe(device_t parent, cfdata_t match, void *aux) |
684 | { | | 684 | { |
685 | struct isa_attach_args *ia = aux; | | 685 | struct isa_attach_args *ia = aux; |
686 | int rv = 0; | | 686 | int rv = 0; |
687 | | | 687 | |
688 | KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: called, name = %s\n", | | 688 | KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: called, name = %s\n", |
689 | device_cfdata(parent)->cf_name)); | | 689 | device_cfdata(parent)->cf_name)); |
690 | | | 690 | |
691 | if (device_is_a(parent, "ofisascr") && devices == 0) | | 691 | if (device_is_a(parent, "ofisascr") && devices == 0) |
692 | { | | 692 | { |
693 | /* set "devices" to ensure that we respond only once */ | | 693 | /* set "devices" to ensure that we respond only once */ |
694 | devices++; | | 694 | devices++; |
695 | | | 695 | |
696 | /* tell the caller that we are not using any resource */ | | 696 | /* tell the caller that we are not using any resource */ |
697 | ia->ia_nio = 0; | | 697 | ia->ia_nio = 0; |
698 | ia->ia_niomem = 0; | | 698 | ia->ia_niomem = 0; |
699 | ia->ia_nirq = 0; | | 699 | ia->ia_nirq = 0; |
700 | ia->ia_ndrq = 0; | | 700 | ia->ia_ndrq = 0; |
701 | rv = 1; | | 701 | rv = 1; |
702 | | | 702 | |
703 | | | 703 | |
704 | KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: successful \n")); | | 704 | KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: successful \n")); |
705 | | | 705 | |
706 | } | | 706 | } |
707 | | | 707 | |
708 | | | 708 | |
709 | return (rv); | | 709 | return (rv); |
710 | | | 710 | |
711 | } /* End scrprobe() */ | | 711 | } /* End scrprobe() */ |
712 | | | 712 | |
713 | | | 713 | |
714 | /* | | 714 | /* |
715 | **++ | | 715 | **++ |
716 | ** FUNCTIONAL DESCRIPTION: | | 716 | ** FUNCTIONAL DESCRIPTION: |
717 | ** | | 717 | ** |
718 | ** scrattach | | 718 | ** scrattach |
719 | ** | | 719 | ** |
720 | ** Initialize the clock and state machines | | 720 | ** Initialize the clock and state machines |
721 | ** | | 721 | ** |
722 | ** FORMAL PARAMETERS: | | 722 | ** FORMAL PARAMETERS: |
723 | ** | | 723 | ** |
724 | ** parent - input : pointer to my parents device structure. | | 724 | ** parent - input : pointer to my parents device structure. |
725 | ** self - output : pointer to my softc with device structure at front. | | 725 | ** self - output : pointer to my softc with device structure at front. |
726 | ** aux - input : pointer to the isa_attach_args structure. | | 726 | ** aux - input : pointer to the isa_attach_args structure. |
727 | ** | | 727 | ** |
728 | ** IMPLICIT INPUTS: | | 728 | ** IMPLICIT INPUTS: |
729 | ** | | 729 | ** |
730 | ** nill | | 730 | ** nill |
731 | ** | | 731 | ** |
732 | ** IMPLICIT OUTPUTS: | | 732 | ** IMPLICIT OUTPUTS: |
733 | ** | | 733 | ** |
734 | ** scrconsinit - clock callout functions set | | 734 | ** scrconsinit - clock callout functions set |
735 | ** state machines all at idle | | 735 | ** state machines all at idle |
736 | ** | | 736 | ** |
737 | ** FUNCTION VALUE: | | 737 | ** FUNCTION VALUE: |
738 | ** | | 738 | ** |
739 | ** none. | | 739 | ** none. |
740 | ** | | 740 | ** |
741 | ** SIDE EFFECTS: | | 741 | ** SIDE EFFECTS: |
742 | ** | | 742 | ** |
743 | ** none. | | 743 | ** none. |
744 | **-- | | 744 | **-- |
745 | */ | | 745 | */ |
746 | void | | 746 | void |
747 | scrattach(device_t parent, device_t self, void *aux) | | 747 | scrattach(device_t parent, device_t self, void *aux) |
748 | { | | 748 | { |
749 | struct scr_softc *sc = (void *)self; | | 749 | struct scr_softc *sc = (void *)self; |
750 | | | 750 | |
751 | printf("\n"); | | 751 | printf("\n"); |
752 | if (device_is_a(parent, "ofisascr")) | | 752 | if (device_is_a(parent, "ofisascr")) |
753 | { | | 753 | { |
754 | KERN_DEBUG (scrdebug, SCRATTACH_DEBUG_INFO,("scrattach: called \n")); | | 754 | KERN_DEBUG (scrdebug, SCRATTACH_DEBUG_INFO,("scrattach: called \n")); |
755 | | | 755 | |
756 | /* set initial state machine values */ | | 756 | /* set initial state machine values */ |
757 | scrClkInit(); | | 757 | scrClkInit(); |
758 | initStates(sc); | | 758 | initStates(sc); |
759 | sc->open = false; | | 759 | sc->open = false; |
760 | } | | 760 | } |
761 | | | 761 | |
762 | else | | 762 | else |
763 | { | | 763 | { |
764 | panic("scrattach: not on an ISA bus, attach impossible"); | | 764 | panic("scrattach: not on an ISA bus, attach impossible"); |
765 | } /* End else we aren't on ISA and we can't handle it */ | | 765 | } /* End else we aren't on ISA and we can't handle it */ |
766 | | | 766 | |
767 | | | 767 | |
768 | return; | | 768 | return; |
769 | } /* End scrattach() */ | | 769 | } /* End scrattach() */ |
770 | | | 770 | |
771 | | | 771 | |
772 | /* | | 772 | /* |
773 | **++ | | 773 | **++ |
774 | ** FUNCTIONAL DESCRIPTION: | | 774 | ** FUNCTIONAL DESCRIPTION: |
775 | ** | | 775 | ** |
776 | ** initStates | | 776 | ** initStates |
777 | ** | | 777 | ** |
778 | ** sets the state of all machines to idle | | 778 | ** sets the state of all machines to idle |
779 | ** | | 779 | ** |
780 | ** FORMAL PARAMETERS: | | 780 | ** FORMAL PARAMETERS: |
781 | ** | | 781 | ** |
782 | ** sc - Pointer to the softc structure. | | 782 | ** sc - Pointer to the softc structure. |
783 | ** | | 783 | ** |
784 | ** IMPLICIT INPUTS: | | 784 | ** IMPLICIT INPUTS: |
785 | ** | | 785 | ** |
786 | ** nill | | 786 | ** nill |
787 | ** | | 787 | ** |
788 | ** IMPLICIT OUTPUTS: | | 788 | ** IMPLICIT OUTPUTS: |
789 | ** | | 789 | ** |
790 | ** nill | | 790 | ** nill |
791 | ** | | 791 | ** |
792 | ** FUNCTION VALUE: | | 792 | ** FUNCTION VALUE: |
793 | ** | | 793 | ** |
794 | ** nill | | 794 | ** nill |
795 | ** | | 795 | ** |
796 | ** SIDE EFFECTS: | | 796 | ** SIDE EFFECTS: |
797 | ** | | 797 | ** |
798 | ** nill | | 798 | ** nill |
799 | **-- | | 799 | **-- |
800 | */ | | 800 | */ |
801 | static void initStates(struct scr_softc * sc) | | 801 | static void initStates(struct scr_softc * sc) |
802 | { | | 802 | { |
803 | sc->masterS = msIdleOff; | | 803 | sc->masterS = msIdleOff; |
804 | sc->t0RecvS = t0rsIdle; | | 804 | sc->t0RecvS = t0rsIdle; |
805 | sc->t0SendS = t0ssIdle; | | 805 | sc->t0SendS = t0ssIdle; |
806 | sc->coldResetS = crsIdle; | | 806 | sc->coldResetS = crsIdle; |
807 | sc->ATRS = atrsIdle; | | 807 | sc->ATRS = atrsIdle; |
808 | sc->t0RecvByteS = t0rbsIdle; | | 808 | sc->t0RecvByteS = t0rbsIdle; |
809 | sc->t0SendByteS = t0sbsIdle; | | 809 | sc->t0SendByteS = t0sbsIdle; |
810 | } | | 810 | } |
811 | | | 811 | |
812 | | | 812 | |
813 | | | 813 | |
814 | /* | | 814 | /* |
815 | **++ | | 815 | **++ |
816 | ** FUNCTIONAL DESCRIPTION: | | 816 | ** FUNCTIONAL DESCRIPTION: |
817 | ** | | 817 | ** |
818 | ** scrOpen | | 818 | ** scrOpen |
819 | ** | | 819 | ** |
820 | ** Opens the driver. We only let the device be opened | | 820 | ** Opens the driver. We only let the device be opened |
821 | ** once for security reasons | | 821 | ** once for security reasons |
822 | ** | | 822 | ** |
823 | ** FORMAL PARAMETERS: | | 823 | ** FORMAL PARAMETERS: |
824 | ** | | 824 | ** |
825 | ** dev - input : Device identifier consisting of major and minor numbers. | | 825 | ** dev - input : Device identifier consisting of major and minor numbers. |
826 | ** flag - input : Indicates if this is a blocking I/O call. | | 826 | ** flag - input : Indicates if this is a blocking I/O call. |
827 | ** mode - not used. | | 827 | ** mode - not used. |
828 | ** l - input : Pointer to the lwp structure of the light weight process | | 828 | ** l - input : Pointer to the lwp structure of the light weight process |
829 | ** performing the open. | | 829 | ** performing the open. |
830 | ** | | 830 | ** |
831 | ** IMPLICIT INPUTS: | | 831 | ** IMPLICIT INPUTS: |
832 | ** | | 832 | ** |
833 | ** none. | | 833 | ** none. |
834 | ** | | 834 | ** |
835 | ** IMPLICIT OUTPUTS: | | 835 | ** IMPLICIT OUTPUTS: |
836 | ** | | 836 | ** |
837 | ** none. | | 837 | ** none. |
838 | ** | | 838 | ** |
839 | ** FUNCTION VALUE: | | 839 | ** FUNCTION VALUE: |
840 | ** | | 840 | ** |
841 | ** ENXIO - invalid device specified for open. | | 841 | ** ENXIO - invalid device specified for open. |
842 | ** EBUSY - The unit is already open | | 842 | ** EBUSY - The unit is already open |
843 | ** | | 843 | ** |
844 | ** SIDE EFFECTS: | | 844 | ** SIDE EFFECTS: |
845 | ** | | 845 | ** |
846 | ** none. | | 846 | ** none. |
847 | **-- | | 847 | **-- |
848 | */ | | 848 | */ |
849 | int scropen(dev_t dev, int flag, int mode, struct lwp *l) | | 849 | int scropen(dev_t dev, int flag, int mode, struct lwp *l) |
850 | { | | 850 | { |
851 | struct scr_softc *sc; | | 851 | struct scr_softc *sc; |
852 | | | 852 | |
853 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO, | | 853 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO, |
854 | ("scropen: called with minor device %d and flag 0x%x\n", | | 854 | ("scropen: called with minor device %d and flag 0x%x\n", |
855 | SCRUNIT(dev), flag)); | | 855 | SCRUNIT(dev), flag)); |
856 | | | 856 | |
857 | sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); | | 857 | sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); |
858 | if (!sc) | | 858 | if (!sc) |
859 | { | | 859 | { |
860 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return ENXIO\n")); | | 860 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return ENXIO\n")); |
861 | return (ENXIO); | | 861 | return (ENXIO); |
862 | } | | 862 | } |
863 | | | 863 | |
864 | | | 864 | |
865 | // david,jim - remove ifdef this when NCI can cope with only 1 open | | 865 | // david,jim - remove ifdef this when NCI can cope with only 1 open |
866 | #if 0 | | 866 | #if 0 |
867 | if (sc->open) | | 867 | if (sc->open) |
868 | { | | 868 | { |
869 | | | 869 | |
870 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return EBUSY\n")); | | 870 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return EBUSY\n")); |
871 | return (EBUSY); | | 871 | return (EBUSY); |
872 | } | | 872 | } |
873 | | | 873 | |
874 | | | 874 | |
875 | /* set all initial conditions */ | | 875 | /* set all initial conditions */ |
876 | sc->open = true; | | 876 | sc->open = true; |
877 | #endif | | 877 | #endif |
878 | | | 878 | |
879 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("scropen: success \n")); | | 879 | KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("scropen: success \n")); |
880 | /* Now invoke the line discipline open routine | | 880 | /* Now invoke the line discipline open routine |
881 | */ | | 881 | */ |
882 | | | 882 | |
883 | return 0; | | 883 | return 0; |
884 | | | 884 | |
885 | } /* End scropen() */ | | 885 | } /* End scropen() */ |
886 | | | 886 | |
887 | | | 887 | |
888 | /* | | 888 | /* |
889 | **++ | | 889 | **++ |
890 | ** FUNCTIONAL DESCRIPTION: | | 890 | ** FUNCTIONAL DESCRIPTION: |
891 | ** | | 891 | ** |
892 | ** This function closed the driver | | 892 | ** This function closed the driver |
893 | ** | | 893 | ** |
894 | ** FORMAL PARAMETERS: | | 894 | ** FORMAL PARAMETERS: |
895 | ** | | 895 | ** |
896 | ** dev - input : Device identifier consisting of major and minor numbers. | | 896 | ** dev - input : Device identifier consisting of major and minor numbers. |
897 | ** flag - Not used. | | 897 | ** flag - Not used. |
898 | ** mode - Not used. | | 898 | ** mode - Not used. |
899 | ** p - Not used. | | 899 | ** p - Not used. |
900 | ** | | 900 | ** |
901 | ** IMPLICIT INPUTS: | | 901 | ** IMPLICIT INPUTS: |
902 | ** | | 902 | ** |
903 | ** scr_cd - used to locate the softc structure for the device unit | | 903 | ** scr_cd - used to locate the softc structure for the device unit |
904 | ** identified by dev. | | 904 | ** identified by dev. |
905 | ** | | 905 | ** |
906 | ** IMPLICIT OUTPUTS: | | 906 | ** IMPLICIT OUTPUTS: |
907 | ** | | 907 | ** |
908 | ** The device is put into an idle state. | | 908 | ** The device is put into an idle state. |
909 | ** | | 909 | ** |
910 | ** FUNCTION VALUE: | | 910 | ** FUNCTION VALUE: |
911 | ** | | 911 | ** |
912 | ** 0 - Always returns success. | | 912 | ** 0 - Always returns success. |
913 | ** | | 913 | ** |
914 | ** SIDE EFFECTS: | | 914 | ** SIDE EFFECTS: |
915 | ** | | 915 | ** |
916 | ** none. | | 916 | ** none. |
917 | **-- | | 917 | **-- |
918 | */ | | 918 | */ |
919 | int scrclose(dev_t dev, int flag, int mode, struct lwp *l) | | 919 | int scrclose(dev_t dev, int flag, int mode, struct lwp *l) |
920 | { | | 920 | { |
921 | #if 0 | | 921 | #if 0 |
922 | struct scr_softc *sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); | | 922 | struct scr_softc *sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); |
923 | #endif | | 923 | #endif |
924 | | | 924 | |
925 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO, | | 925 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO, |
926 | ("scrclose: called for minor device %d flag 0x%x\n", | | 926 | ("scrclose: called for minor device %d flag 0x%x\n", |
927 | SCRUNIT(dev), flag)); | | 927 | SCRUNIT(dev), flag)); |
928 | | | 928 | |
929 | // david,jim - remove ifdef this when NCI can cope with only 1 open | | 929 | // david,jim - remove ifdef this when NCI can cope with only 1 open |
930 | #if 0 | | 930 | #if 0 |
931 | /* Check we are open in the first place | | 931 | /* Check we are open in the first place |
932 | */ | | 932 | */ |
933 | if (sc->open) | | 933 | if (sc->open) |
934 | { | | 934 | { |
935 | /* put everything in the idle state */ | | 935 | /* put everything in the idle state */ |
936 | scrClkInit(); | | 936 | scrClkInit(); |
937 | initStates(sc); | | 937 | initStates(sc); |
938 | sc->open = false; | | 938 | sc->open = false; |
939 | | | 939 | |
940 | } | | 940 | } |
941 | | | 941 | |
942 | | | 942 | |
943 | else | | 943 | else |
944 | { | | 944 | { |
945 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("\t scrclose, device not open\n")); | | 945 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("\t scrclose, device not open\n")); |
946 | } | | 946 | } |
947 | #endif | | 947 | #endif |
948 | | | 948 | |
949 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("scrclose exiting\n")); | | 949 | KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("scrclose exiting\n")); |
950 | return(0); | | 950 | return(0); |
951 | } | | 951 | } |
952 | | | 952 | |
953 | /* | | 953 | /* |
954 | **++ | | 954 | **++ |
955 | ** FUNCTIONAL DESCRIPTION: | | 955 | ** FUNCTIONAL DESCRIPTION: |
956 | ** | | 956 | ** |
957 | ** This routine is responsible for performing I/O controls. | | 957 | ** This routine is responsible for performing I/O controls. |
958 | ** | | 958 | ** |
959 | ** There are 4 commands. Status, On, T0 and Off. | | 959 | ** There are 4 commands. Status, On, T0 and Off. |
960 | ** | | 960 | ** |
961 | ** Status checks to see if the card is inserted. This command | | 961 | ** Status checks to see if the card is inserted. This command |
962 | ** does not use the state machines | | 962 | ** does not use the state machines |
963 | ** | | 963 | ** |
964 | ** On turns the card on and gets the ATR sequence from the card. | | 964 | ** On turns the card on and gets the ATR sequence from the card. |
965 | ** This command does use the state machines | | 965 | ** This command does use the state machines |
966 | ** | | 966 | ** |
967 | ** T0 is used to read and write the card. This command does use | | 967 | ** T0 is used to read and write the card. This command does use |
968 | ** the state machines | | 968 | ** the state machines |
969 | ** | | 969 | ** |
970 | ** Off turns the card off. This command does not use the state | | 970 | ** Off turns the card off. This command does not use the state |
971 | ** machines. | | 971 | ** machines. |
972 | ** | | 972 | ** |
973 | ** | | 973 | ** |
974 | ** FORMAL PARAMETERS: | | 974 | ** FORMAL PARAMETERS: |
975 | ** | | 975 | ** |
976 | ** dev - input : Device identifier consisting of major and minor numbers. | | 976 | ** dev - input : Device identifier consisting of major and minor numbers. |
977 | ** cmd - input : The requested IOCTL command to be performed. | | 977 | ** cmd - input : The requested IOCTL command to be performed. |
978 | ** See scrio.h for details | | 978 | ** See scrio.h for details |
979 | ** | | 979 | ** |
980 | ** | | 980 | ** |
981 | ** Bit Position { 3322222222221111111111 | | 981 | ** Bit Position { 3322222222221111111111 |
982 | ** { 10987654321098765432109876543210 | | 982 | ** { 10987654321098765432109876543210 |
983 | ** Meaning | DDDLLLLLLLLLLLLLGGGGGGGGCCCCCCCC | | 983 | ** Meaning | DDDLLLLLLLLLLLLLGGGGGGGGCCCCCCCC |
984 | ** | | 984 | ** |
985 | ** D - Command direction, in/out/both. | | 985 | ** D - Command direction, in/out/both. |
986 | ** L - Command argument length. | | 986 | ** L - Command argument length. |
987 | ** G - Command group, 't' used for tty. | | 987 | ** G - Command group, 't' used for tty. |
988 | ** C - Actual command enumeration. | | 988 | ** C - Actual command enumeration. |
989 | ** | | 989 | ** |
990 | ** data - input/output : Direction depends on the command. | | 990 | ** data - input/output : Direction depends on the command. |
991 | ** flag - input : Not used by us but passed to line discipline and ttioctl | | 991 | ** flag - input : Not used by us but passed to line discipline and ttioctl |
992 | ** l - input : pointer to lwp structure of user. | | 992 | ** l - input : pointer to lwp structure of user. |
993 | ** | | 993 | ** |
994 | ** IMPLICIT INPUTS: | | 994 | ** IMPLICIT INPUTS: |
995 | ** | | 995 | ** |
996 | ** none. | | 996 | ** none. |
997 | ** | | 997 | ** |
998 | ** IMPLICIT OUTPUTS: | | 998 | ** IMPLICIT OUTPUTS: |
999 | ** | | 999 | ** |
1000 | ** sc->masterS state of master state machine | | 1000 | ** sc->masterS state of master state machine |
1001 | ** | | 1001 | ** |
1002 | ** | | 1002 | ** |
1003 | ** FUNCTION VALUE: | | 1003 | ** FUNCTION VALUE: |
1004 | ** | | 1004 | ** |
1005 | ** ENOTTY if not correct ioctl | | 1005 | ** ENOTTY if not correct ioctl |
1006 | ** | | 1006 | ** |
1007 | ** | | 1007 | ** |
1008 | ** SIDE EFFECTS: | | 1008 | ** SIDE EFFECTS: |
1009 | ** | | 1009 | ** |
1010 | **-- | | 1010 | **-- |
1011 | */ | | 1011 | */ |
1012 | int | | 1012 | int |
1013 | scrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) | | 1013 | scrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) |
1014 | { | | 1014 | { |
1015 | struct scr_softc* sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); | | 1015 | struct scr_softc* sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); |
1016 | | | 1016 | |
1017 | int error = 0; /* error value returned */ | | 1017 | int error = 0; /* error value returned */ |
1018 | int masterDoneRetries= 0; /* nuber of times we looked at masterDone */ | | 1018 | int masterDoneRetries= 0; /* nuber of times we looked at masterDone */ |
1019 | int done; /* local copy of masterDone */ | | 1019 | int done; /* local copy of masterDone */ |
1020 | | | 1020 | |
1021 | ScrStatus * pIoctlStatus; /* pointer to status ioctl */ | | 1021 | ScrStatus * pIoctlStatus; /* pointer to status ioctl */ |
1022 | ScrOff * pIoctlOff; /* pointer to off ioctl */ | | 1022 | ScrOff * pIoctlOff; /* pointer to off ioctl */ |
1023 | | | 1023 | |
1024 | u_int savedInts; /* saved interrupts */ | | 1024 | u_int savedInts; /* saved interrupts */ |
1025 | int s; /* saved spl value */ | | 1025 | int s; /* saved spl value */ |
1026 | | | 1026 | |
1027 | | | 1027 | |
1028 | | | 1028 | |
1029 | KERN_DEBUG (scrdebug, SCRIOCTL_DEBUG_INFO, | | 1029 | KERN_DEBUG (scrdebug, SCRIOCTL_DEBUG_INFO, |
1030 | ("scrioctl: called for device 0x%x, command 0x%lx, " | | 1030 | ("scrioctl: called for device 0x%x, command 0x%lx, " |
1031 | "flag 0x%x\n", | | 1031 | "flag 0x%x\n", |
1032 | SCRUNIT(dev), cmd, flag)); | | 1032 | SCRUNIT(dev), cmd, flag)); |
1033 | | | 1033 | |
1034 | | | 1034 | |
1035 | | | 1035 | |
1036 | switch (cmd) | | 1036 | switch (cmd) |
1037 | { | | 1037 | { |
1038 | /* | | 1038 | /* |
1039 | ** get the status of the card, ie is it in, in but off, in and on | | 1039 | ** get the status of the card, ie is it in, in but off, in and on |
1040 | */ | | 1040 | */ |
1041 | case SCRIOSTATUS: | | 1041 | case SCRIOSTATUS: |
1042 | pIoctlStatus = (ScrStatus*)data; | | 1042 | pIoctlStatus = (ScrStatus*)data; |
1043 | if (scrGetDetect()) | | 1043 | if (scrGetDetect()) |
1044 | { | | 1044 | { |
1045 | savedInts = disable_interrupts(I32_bit | F32_bit); | | 1045 | savedInts = disable_interrupts(I32_bit | F32_bit); |
1046 | if (sc->masterS == msIdleOn) | | 1046 | if (sc->masterS == msIdleOn) |
1047 | { | | 1047 | { |
1048 | pIoctlStatus->status = CARD_ON; | | 1048 | pIoctlStatus->status = CARD_ON; |
1049 | } | | 1049 | } |
1050 | else | | 1050 | else |
1051 | { | | 1051 | { |
1052 | ASSERT(sc->masterS == msIdleOff); | | 1052 | ASSERT(sc->masterS == msIdleOff); |
1053 | pIoctlStatus->status = CARD_INSERTED; | | 1053 | pIoctlStatus->status = CARD_INSERTED; |
1054 | } | | 1054 | } |
1055 | restore_interrupts(savedInts); | | 1055 | restore_interrupts(savedInts); |
1056 | } | | 1056 | } |
1057 | | | 1057 | |
1058 | else | | 1058 | else |
1059 | { | | 1059 | { |
1060 | pIoctlStatus->status = CARD_REMOVED; | | 1060 | pIoctlStatus->status = CARD_REMOVED; |
1061 | } | | 1061 | } |
1062 | break; | | 1062 | break; |
1063 | | | 1063 | |
1064 | | | 1064 | |
1065 | | | 1065 | |
1066 | /* | | 1066 | /* |
1067 | ** turn the card on and get the ATR sequence | | 1067 | ** turn the card on and get the ATR sequence |
1068 | */ | | 1068 | */ |
1069 | case SCRIOON: | | 1069 | case SCRIOON: |
1070 | sc->pIoctlOn = (ScrOn*)data; | | 1070 | sc->pIoctlOn = (ScrOn*)data; |
1071 | // acquire the hat lock. | | 1071 | // acquire the hat lock. |
1072 | while (1) | | 1072 | while (1) |
1073 | { | | 1073 | { |
1074 | s = splhigh(); | | 1074 | s = splhigh(); |
1075 | if(!hatLock) | | 1075 | if(!hatLock) |
1076 | { | | 1076 | { |
1077 | hatLock = true; | | 1077 | hatLock = true; |
1078 | splx(s); | | 1078 | splx(s); |
1079 | break; | | 1079 | break; |
1080 | } | | 1080 | } |
1081 | splx(s); | | 1081 | splx(s); |
1082 | | | 1082 | |
1083 | tsleep(&tsleepIdent ,PZERO,"hat", 1); | | 1083 | tsleep(&tsleepIdent ,PZERO,"hat", 1); |
1084 | } | | 1084 | } |
1085 | | | 1085 | |
1086 | | | 1086 | |
1087 | // check to see if the card is in | | 1087 | // check to see if the card is in |
1088 | if(!scrGetDetect()) | | 1088 | if(!scrGetDetect()) |
1089 | { | | 1089 | { |
1090 | initStates(sc); | | 1090 | initStates(sc); |
1091 | cardOff(sc); | | 1091 | cardOff(sc); |
1092 | // do not call scrClkInit() as it is idle already | | 1092 | // do not call scrClkInit() as it is idle already |
1093 | sc->pIoctlOn->status = ERROR_CARD_REMOVED; | | 1093 | sc->pIoctlOn->status = ERROR_CARD_REMOVED; |
1094 | } | | 1094 | } |
1095 | | | 1095 | |
1096 | | | 1096 | |
1097 | // check to see if we are already on | | 1097 | // check to see if we are already on |
1098 | else if(sc->masterS == msIdleOn) | | 1098 | else if(sc->masterS == msIdleOn) |
1099 | { | | 1099 | { |
1100 | sc->pIoctlOn->status = ERROR_CARD_ON; | | 1100 | sc->pIoctlOn->status = ERROR_CARD_ON; |
1101 | } | | 1101 | } |
1102 | | | 1102 | |
1103 | // card was in, card is off, so lets start it | | 1103 | // card was in, card is off, so lets start it |
1104 | else | | 1104 | else |
| @@ -2694,1326 +2694,1328 @@ static void ATRSM (struct scr_softc * sc | | | @@ -2694,1326 +2694,1328 @@ static void ATRSM (struct scr_softc * sc |
2694 | default: | | 2694 | default: |
2695 | INVALID_STATE_CMD(sc,sc->ATRS,cmd); | | 2695 | INVALID_STATE_CMD(sc,sc->ATRS,cmd); |
2696 | break; | | 2696 | break; |
2697 | } | | 2697 | } |
2698 | break; | | 2698 | break; |
2699 | | | 2699 | |
2700 | | | 2700 | |
2701 | | | 2701 | |
2702 | default: | | 2702 | default: |
2703 | INVALID_STATE_CMD(sc,sc->ATRS,cmd); | | 2703 | INVALID_STATE_CMD(sc,sc->ATRS,cmd); |
2704 | break; | | 2704 | break; |
2705 | } | | 2705 | } |
2706 | } | | 2706 | } |
2707 | | | 2707 | |
2708 | | | 2708 | |
2709 | | | 2709 | |
2710 | /* | | 2710 | /* |
2711 | **++ | | 2711 | **++ |
2712 | ** FUNCTIONAL DESCRIPTION: | | 2712 | ** FUNCTIONAL DESCRIPTION: |
2713 | ** | | 2713 | ** |
2714 | ** t0RecvByteSM | | 2714 | ** t0RecvByteSM |
2715 | ** | | 2715 | ** |
2716 | ** This state machine attempts to read 1 byte from a card. | | 2716 | ** This state machine attempts to read 1 byte from a card. |
2717 | ** It is a low level bit-bashing state machine. | | 2717 | ** It is a low level bit-bashing state machine. |
2718 | ** | | 2718 | ** |
2719 | ** Data from the card is async, so the machine scans at | | 2719 | ** Data from the card is async, so the machine scans at |
2720 | ** 5 times the data rate looking for a state bit. Once | | 2720 | ** 5 times the data rate looking for a state bit. Once |
2721 | ** a start bit has been found, it waits for the middle of | | 2721 | ** a start bit has been found, it waits for the middle of |
2722 | ** the bit and starts sampling at the bit rate. | | 2722 | ** the bit and starts sampling at the bit rate. |
2723 | ** | | 2723 | ** |
2724 | ** Several mid level machines can use this machine, so the value | | 2724 | ** Several mid level machines can use this machine, so the value |
2725 | ** sc->t0ByteParent is used to point to back to the mid level machine | | 2725 | ** sc->t0ByteParent is used to point to back to the mid level machine |
2726 | ** | | 2726 | ** |
2727 | ** | | 2727 | ** |
2728 | ** FORMAL PARAMETERS: | | 2728 | ** FORMAL PARAMETERS: |
2729 | ** | | 2729 | ** |
2730 | ** sc - Pointer to the softc structure. | | 2730 | ** sc - Pointer to the softc structure. |
2731 | ** cmd - command to this machine | | 2731 | ** cmd - command to this machine |
2732 | ** | | 2732 | ** |
2733 | ** IMPLICIT INPUTS: | | 2733 | ** IMPLICIT INPUTS: |
2734 | ** | | 2734 | ** |
2735 | ** sc->t0RecvByteS state of this machine | | 2735 | ** sc->t0RecvByteS state of this machine |
2736 | ** sc->t0ByteParent mid level machine that started this machine | | 2736 | ** sc->t0ByteParent mid level machine that started this machine |
2737 | ** | | 2737 | ** |
2738 | ** IMPLICIT OUTPUTS: | | 2738 | ** IMPLICIT OUTPUTS: |
2739 | ** | | 2739 | ** |
2740 | ** sc->shiftByte byte read from the card | | 2740 | ** sc->shiftByte byte read from the card |
2741 | ** sc->status error value if could not read byte | | 2741 | ** sc->status error value if could not read byte |
2742 | ** | | 2742 | ** |
2743 | ** FUNCTION VALUE: | | 2743 | ** FUNCTION VALUE: |
2744 | ** | | 2744 | ** |
2745 | ** nill | | 2745 | ** nill |
2746 | ** | | 2746 | ** |
2747 | ** SIDE EFFECTS: | | 2747 | ** SIDE EFFECTS: |
2748 | ** | | 2748 | ** |
2749 | ** nill | | 2749 | ** nill |
2750 | **-- | | 2750 | **-- |
2751 | */ | | 2751 | */ |
2752 | static void t0RecvByteSM(struct scr_softc* sc,int cmd) | | 2752 | static void t0RecvByteSM(struct scr_softc* sc,int cmd) |
2753 | { | | 2753 | { |
2754 | if (sc->bigTrouble) return; // david,jim , remove this when dust settles | | 2754 | if (sc->bigTrouble) return; // david,jim , remove this when dust settles |
2755 | | | 2755 | |
2756 | if (cmd == t0rbcAbort) | | 2756 | if (cmd == t0rbcAbort) |
2757 | { | | 2757 | { |
2758 | /* kill all the timers */ | | 2758 | /* kill all the timers */ |
2759 | scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartEdge); | | 2759 | scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartEdge); |
2760 | scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartMid); | | 2760 | scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartMid); |
2761 | scrUntimeout(t0RecvByteSM, sc,t0rbcTClockData); | | 2761 | scrUntimeout(t0RecvByteSM, sc,t0rbcTClockData); |
2762 | scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStart); | | 2762 | scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStart); |
2763 | scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStop); | | 2763 | scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStop); |
2764 | | | 2764 | |
2765 | scrSetDataHighZ(); | | 2765 | scrSetDataHighZ(); |
2766 | sc->t0RecvByteS = t0rbsIdle; | | 2766 | sc->t0RecvByteS = t0rbsIdle; |
2767 | return; | | 2767 | return; |
2768 | } | | 2768 | } |
2769 | | | 2769 | |
2770 | | | 2770 | |
2771 | switch (sc->t0RecvByteS) | | 2771 | switch (sc->t0RecvByteS) |
2772 | { | | 2772 | { |
2773 | case t0rbsIdle: | | 2773 | case t0rbsIdle: |
2774 | switch (cmd) | | 2774 | switch (cmd) |
2775 | { | | 2775 | { |
2776 | case t0rbcStart: | | 2776 | case t0rbcStart: |
2777 | /* set initial conditions */ | | 2777 | /* set initial conditions */ |
2778 | sc->shiftBits = 0; | | 2778 | sc->shiftBits = 0; |
2779 | sc->shiftByte = 0; | | 2779 | sc->shiftByte = 0; |
2780 | sc->shiftParity = 0; | | 2780 | sc->shiftParity = 0; |
2781 | sc->shiftParityCount = 0; | | 2781 | sc->shiftParityCount = 0; |
2782 | scrClkAdj(sc->clkCountStartRecv); /* recv data clock running at 5 times */ | | 2782 | scrClkAdj(sc->clkCountStartRecv); /* recv data clock running at 5 times */ |
2783 | | | 2783 | |
2784 | /* check if start bit is already here */ | | 2784 | /* check if start bit is already here */ |
2785 | //if (scrGetData()) | | 2785 | //if (scrGetData()) |
2786 | if (1) | | 2786 | if (1) |
2787 | { | | 2787 | { |
2788 | /* didn't find it, keep looking */ | | 2788 | /* didn't find it, keep looking */ |
2789 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); | | 2789 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); |
2790 | sc->t0RecvByteS = t0rbsFindStartEdge; | | 2790 | sc->t0RecvByteS = t0rbsFindStartEdge; |
2791 | } | | 2791 | } |
2792 | else | | 2792 | else |
2793 | { | | 2793 | { |
2794 | /* found start bit, look for mid bit */ | | 2794 | /* found start bit, look for mid bit */ |
2795 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv); | | 2795 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv); |
2796 | sc->t0RecvByteS = t0rbsFindStartMid; | | 2796 | sc->t0RecvByteS = t0rbsFindStartMid; |
2797 | } | | 2797 | } |
2798 | break; | | 2798 | break; |
2799 | | | 2799 | |
2800 | | | 2800 | |
2801 | | | 2801 | |
2802 | default: | | 2802 | default: |
2803 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 2803 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
2804 | break; | | 2804 | break; |
2805 | } | | 2805 | } |
2806 | break; | | 2806 | break; |
2807 | | | 2807 | |
2808 | | | 2808 | |
2809 | case t0rbsFindStartEdge: | | 2809 | case t0rbsFindStartEdge: |
2810 | switch (cmd) | | 2810 | switch (cmd) |
2811 | { | | 2811 | { |
2812 | case t0rbcTFindStartEdge: | | 2812 | case t0rbcTFindStartEdge: |
2813 | if (scrGetData()) | | 2813 | if (scrGetData()) |
2814 | { | | 2814 | { |
2815 | /* didn't find it, keep looking */ | | 2815 | /* didn't find it, keep looking */ |
2816 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); | | 2816 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); |
2817 | } | | 2817 | } |
2818 | else | | 2818 | else |
2819 | { | | 2819 | { |
2820 | /* found start bit, look for mid bit */ | | 2820 | /* found start bit, look for mid bit */ |
2821 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv * 2); | | 2821 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv * 2); |
2822 | sc->t0RecvByteS = t0rbsFindStartMid; | | 2822 | sc->t0RecvByteS = t0rbsFindStartMid; |
2823 | } | | 2823 | } |
2824 | break; | | 2824 | break; |
2825 | | | 2825 | |
2826 | | | 2826 | |
2827 | default: | | 2827 | default: |
2828 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 2828 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
2829 | break; | | 2829 | break; |
2830 | } | | 2830 | } |
2831 | break; | | 2831 | break; |
2832 | | | 2832 | |
2833 | case t0rbsFindStartMid: | | 2833 | case t0rbsFindStartMid: |
2834 | switch (cmd) | | 2834 | switch (cmd) |
2835 | { | | 2835 | { |
2836 | case t0rbcTFindStartMid: | | 2836 | case t0rbcTFindStartMid: |
2837 | if (scrGetData()) | | 2837 | if (scrGetData()) |
2838 | { | | 2838 | { |
2839 | /* found glitch, so just go back to hunting */ | | 2839 | /* found glitch, so just go back to hunting */ |
2840 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); | | 2840 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); |
2841 | sc->t0RecvByteS = t0rbsFindStartEdge; | | 2841 | sc->t0RecvByteS = t0rbsFindStartEdge; |
2842 | } | | 2842 | } |
2843 | else | | 2843 | else |
2844 | { | | 2844 | { |
2845 | /* found start bit, start clocking in data */ | | 2845 | /* found start bit, start clocking in data */ |
2846 | TOGGLE_TEST_PIN(); | | 2846 | TOGGLE_TEST_PIN(); |
2847 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); | | 2847 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); |
2848 | sc->t0RecvByteS = t0rbsClockData; | | 2848 | sc->t0RecvByteS = t0rbsClockData; |
2849 | } | | 2849 | } |
2850 | break; | | 2850 | break; |
2851 | | | 2851 | |
2852 | | | 2852 | |
2853 | default: | | 2853 | default: |
2854 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 2854 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
2855 | break; | | 2855 | break; |
2856 | } | | 2856 | } |
2857 | break; | | 2857 | break; |
2858 | | | 2858 | |
2859 | | | 2859 | |
2860 | case t0rbsClockData: | | 2860 | case t0rbsClockData: |
2861 | TOGGLE_TEST_PIN(); | | 2861 | TOGGLE_TEST_PIN(); |
2862 | switch (cmd) | | 2862 | switch (cmd) |
2863 | { | | 2863 | { |
2864 | case t0rbcTClockData: | | 2864 | case t0rbcTClockData: |
2865 | if (sc->shiftBits < 8) | | 2865 | if (sc->shiftBits < 8) |
2866 | { | | 2866 | { |
2867 | if (sc->convention == CONVENTION_INVERSE || | | 2867 | if (sc->convention == CONVENTION_INVERSE || |
2868 | sc->convention == CONVENTION_UNKNOWN) | | 2868 | sc->convention == CONVENTION_UNKNOWN) |
2869 | { | | 2869 | { |
2870 | /* logic 1 is low, msb is first */ | | 2870 | /* logic 1 is low, msb is first */ |
2871 | sc->shiftByte <<= 1; | | 2871 | sc->shiftByte <<= 1; |
2872 | sc->shiftByte &= 0xfe; | | 2872 | sc->shiftByte &= 0xfe; |
2873 | if (!scrGetData()) | | 2873 | if (!scrGetData()) |
2874 | { | | 2874 | { |
2875 | sc->shiftByte |= 0x01; | | 2875 | sc->shiftByte |= 0x01; |
2876 | sc->shiftParity++; | | 2876 | sc->shiftParity++; |
2877 | } | | 2877 | } |
2878 | } | | 2878 | } |
2879 | else | | 2879 | else |
2880 | { | | 2880 | { |
2881 | ASSERT(sc->convention == CONVENTION_DIRECT); | | 2881 | ASSERT(sc->convention == CONVENTION_DIRECT); |
2882 | /* logic 1 is high, lsb is first */ | | 2882 | /* logic 1 is high, lsb is first */ |
2883 | sc->shiftByte = sc->shiftByte >> 1; | | 2883 | sc->shiftByte = sc->shiftByte >> 1; |
2884 | sc->shiftByte &= 0x7f; | | 2884 | sc->shiftByte &= 0x7f; |
2885 | if (scrGetData()) | | 2885 | if (scrGetData()) |
2886 | { | | 2886 | { |
2887 | sc->shiftParity++; | | 2887 | sc->shiftParity++; |
2888 | sc->shiftByte |= 0x80; | | 2888 | sc->shiftByte |= 0x80; |
2889 | } | | 2889 | } |
2890 | } | | 2890 | } |
2891 | sc->shiftBits++; | | 2891 | sc->shiftBits++; |
2892 | | | 2892 | |
2893 | | | 2893 | |
2894 | /* in TS byte, check if we have a card that works at 1/2 freq */ | | 2894 | /* in TS byte, check if we have a card that works at 1/2 freq */ |
2895 | if (sc->convention == CONVENTION_UNKNOWN && /* in TS byte */ | | 2895 | if (sc->convention == CONVENTION_UNKNOWN && /* in TS byte */ |
2896 | sc->shiftBits == 3 && /* test at bit 3 in word */ | | 2896 | sc->shiftBits == 3 && /* test at bit 3 in word */ |
2897 | sc->shiftByte == 4 && /* check for 1/2 freq pattern */ | | 2897 | sc->shiftByte == 4 && /* check for 1/2 freq pattern */ |
2898 | sc->cardFreq == CARD_FREQ_DEF) /* only do this if at full freq */ | | 2898 | sc->cardFreq == CARD_FREQ_DEF) /* only do this if at full freq */ |
2899 | { | | 2899 | { |
2900 | /* adjust counts down to 1/2 freq */ | | 2900 | /* adjust counts down to 1/2 freq */ |
2901 | sc->cardFreq = CARD_FREQ_DEF / 2; | | 2901 | sc->cardFreq = CARD_FREQ_DEF / 2; |
2902 | sc->clkCountStartRecv = sc->clkCountStartRecv *2; | | 2902 | sc->clkCountStartRecv = sc->clkCountStartRecv *2; |
2903 | sc->clkCountDataRecv = sc->clkCountDataRecv *2; | | 2903 | sc->clkCountDataRecv = sc->clkCountDataRecv *2; |
2904 | sc->clkCountDataSend = sc->clkCountDataSend *2; | | 2904 | sc->clkCountDataSend = sc->clkCountDataSend *2; |
2905 | | | 2905 | |
2906 | | | 2906 | |
2907 | /* adjust this so that we have clocked in only fist bit of TS */ | | 2907 | /* adjust this so that we have clocked in only fist bit of TS */ |
2908 | sc->shiftParity = 0; | | 2908 | sc->shiftParity = 0; |
2909 | sc->shiftByte = 0; | | 2909 | sc->shiftByte = 0; |
2910 | sc->shiftBits = 1; | | 2910 | sc->shiftBits = 1; |
2911 | | | 2911 | |
2912 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,(sc->clkCountDataRecv * 3) /4); | | 2912 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,(sc->clkCountDataRecv * 3) /4); |
2913 | } | | 2913 | } |
2914 | else | | 2914 | else |
2915 | { | | 2915 | { |
2916 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); | | 2916 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); |
2917 | } | | 2917 | } |
2918 | } | | 2918 | } |
2919 | | | 2919 | |
2920 | /* clock in parity bit */ | | 2920 | /* clock in parity bit */ |
2921 | else if (sc->shiftBits == 8) | | 2921 | else if (sc->shiftBits == 8) |
2922 | { | | 2922 | { |
2923 | if (sc->convention == CONVENTION_INVERSE) | | 2923 | if (sc->convention == CONVENTION_INVERSE) |
2924 | { | | 2924 | { |
2925 | if (!scrGetData()) | | 2925 | if (!scrGetData()) |
2926 | { | | 2926 | { |
2927 | sc->shiftParity++; | | 2927 | sc->shiftParity++; |
2928 | } | | 2928 | } |
2929 | } | | 2929 | } |
2930 | else if (sc->convention == CONVENTION_DIRECT) | | 2930 | else if (sc->convention == CONVENTION_DIRECT) |
2931 | { | | 2931 | { |
2932 | if (scrGetData()) | | 2932 | if (scrGetData()) |
2933 | { | | 2933 | { |
2934 | sc->shiftParity++; | | 2934 | sc->shiftParity++; |
2935 | } | | 2935 | } |
2936 | } | | 2936 | } |
2937 | | | 2937 | |
2938 | | | 2938 | |
2939 | else | | 2939 | else |
2940 | { | | 2940 | { |
2941 | /* sc->convention not set so sort it out */ | | 2941 | /* sc->convention not set so sort it out */ |
2942 | ASSERT(sc->convention == CONVENTION_UNKNOWN); | | 2942 | ASSERT(sc->convention == CONVENTION_UNKNOWN); |
2943 | if (sc->shiftByte == CONVENIONT_INVERSE_ID && scrGetData()) | | 2943 | if (sc->shiftByte == CONVENIONT_INVERSE_ID && scrGetData()) |
2944 | { | | 2944 | { |
2945 | sc->convention = CONVENTION_INVERSE; | | 2945 | sc->convention = CONVENTION_INVERSE; |
2946 | sc->shiftParity = 0; /* force good parity */ | | 2946 | sc->shiftParity = 0; /* force good parity */ |
2947 | } | | 2947 | } |
2948 | | | 2948 | |
2949 | else if (sc->shiftByte == CONVENTION_DIRECT_ID && scrGetData()) | | 2949 | else if (sc->shiftByte == CONVENTION_DIRECT_ID && scrGetData()) |
2950 | { | | 2950 | { |
2951 | sc->shiftByte = CONVENTION_DIRECT_FIX; | | 2951 | sc->shiftByte = CONVENTION_DIRECT_FIX; |
2952 | sc->convention = CONVENTION_DIRECT; | | 2952 | sc->convention = CONVENTION_DIRECT; |
2953 | sc->shiftParity = 0; /* force good parity */ | | 2953 | sc->shiftParity = 0; /* force good parity */ |
2954 | } | | 2954 | } |
2955 | | | 2955 | |
2956 | else | | 2956 | else |
2957 | { | | 2957 | { |
2958 | sc->shiftParity = 1; /* force bad parity */ | | 2958 | sc->shiftParity = 1; /* force bad parity */ |
2959 | } | | 2959 | } |
2960 | } | | 2960 | } |
2961 | | | 2961 | |
2962 | | | 2962 | |
2963 | if ((sc->shiftParity & 01) == 0) | | 2963 | if ((sc->shiftParity & 01) == 0) |
2964 | { | | 2964 | { |
2965 | sc->shiftBits++; | | 2965 | sc->shiftBits++; |
2966 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); | | 2966 | scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); |
2967 | } | | 2967 | } |
2968 | else | | 2968 | else |
2969 | { | | 2969 | { |
2970 | /* got parity error */ | | 2970 | /* got parity error */ |
2971 | if (sc->shiftParityCount < PARITY_ERROR_MAX) | | 2971 | if (sc->shiftParityCount < PARITY_ERROR_MAX) |
2972 | { | | 2972 | { |
2973 | sc->shiftParityCount++; | | 2973 | sc->shiftParityCount++; |
2974 | scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStart,sc->clkCountDataRecv); | | 2974 | scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStart,sc->clkCountDataRecv); |
2975 | sc->t0RecvByteS = t0rbsSendError; | | 2975 | sc->t0RecvByteS = t0rbsSendError; |
2976 | } | | 2976 | } |
2977 | else | | 2977 | else |
2978 | | | 2978 | |
2979 | { | | 2979 | { |
2980 | /* too many parity errors, just give up on this sc->dataByte */ | | 2980 | /* too many parity errors, just give up on this sc->dataByte */ |
2981 | sc->status = ERROR_PARITY; | | 2981 | sc->status = ERROR_PARITY; |
2982 | sc->t0RecvByteS = t0rbsIdle; | | 2982 | sc->t0RecvByteS = t0rbsIdle; |
2983 | sc->t0ByteParent(sc,gcT0RecvByteErr); | | 2983 | sc->t0ByteParent(sc,gcT0RecvByteErr); |
2984 | } | | 2984 | } |
2985 | } | | 2985 | } |
2986 | } | | 2986 | } |
2987 | | | 2987 | |
2988 | else | | 2988 | else |
2989 | { | | 2989 | { |
2990 | sc->dataByte = sc->shiftByte; | | 2990 | sc->dataByte = sc->shiftByte; |
2991 | sc->t0RecvByteS = t0rbsIdle; | | 2991 | sc->t0RecvByteS = t0rbsIdle; |
2992 | sc->t0ByteParent(sc,gcT0RecvByte); | | 2992 | sc->t0ByteParent(sc,gcT0RecvByte); |
2993 | } | | 2993 | } |
2994 | break; | | 2994 | break; |
2995 | | | 2995 | |
2996 | default: | | 2996 | default: |
2997 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 2997 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
2998 | break; | | 2998 | break; |
2999 | } | | 2999 | } |
3000 | break; | | 3000 | break; |
3001 | | | 3001 | |
3002 | | | 3002 | |
3003 | case t0rbsSendError: | | 3003 | case t0rbsSendError: |
3004 | TOGGLE_TEST_PIN(); | | 3004 | TOGGLE_TEST_PIN(); |
3005 | switch (cmd) | | 3005 | switch (cmd) |
3006 | { | | 3006 | { |
3007 | case t0rbcTErrorStart: | | 3007 | case t0rbcTErrorStart: |
3008 | /* start sending error bit */ | | 3008 | /* start sending error bit */ |
3009 | scrSetData(false); | | 3009 | scrSetData(false); |
3010 | scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStop,sc->clkCountDataRecv * 2); | | 3010 | scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStop,sc->clkCountDataRecv * 2); |
3011 | break; | | 3011 | break; |
3012 | | | 3012 | |
3013 | case t0rbcTErrorStop: | | 3013 | case t0rbcTErrorStop: |
3014 | /* stop sending parity error & reset information*/ | | 3014 | /* stop sending parity error & reset information*/ |
3015 | scrSetData(true); | | 3015 | scrSetData(true); |
3016 | sc->shiftBits = 0; | | 3016 | sc->shiftBits = 0; |
3017 | sc->shiftByte = 0; | | 3017 | sc->shiftByte = 0; |
3018 | sc->shiftParity = 0; | | 3018 | sc->shiftParity = 0; |
3019 | | | 3019 | |
3020 | /* start looking for start bit */ | | 3020 | /* start looking for start bit */ |
3021 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,1); | | 3021 | scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,1); |
3022 | sc->t0RecvByteS = t0rbsFindStartEdge; | | 3022 | sc->t0RecvByteS = t0rbsFindStartEdge; |
3023 | break; | | 3023 | break; |
3024 | | | 3024 | |
3025 | default: | | 3025 | default: |
3026 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 3026 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
3027 | break; | | 3027 | break; |
3028 | } | | 3028 | } |
3029 | break; | | 3029 | break; |
3030 | | | 3030 | |
3031 | | | 3031 | |
3032 | default: | | 3032 | default: |
3033 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); | | 3033 | INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); |
3034 | break; | | 3034 | break; |
3035 | } | | 3035 | } |
3036 | } | | 3036 | } |
3037 | | | 3037 | |
3038 | /* | | 3038 | /* |
3039 | **++ | | 3039 | **++ |
3040 | ** FUNCTIONAL DESCRIPTION: | | 3040 | ** FUNCTIONAL DESCRIPTION: |
3041 | ** | | 3041 | ** |
3042 | ** t0SendByteSM | | 3042 | ** t0SendByteSM |
3043 | ** | | 3043 | ** |
3044 | ** This state machine writes 1 byte to a card. | | 3044 | ** This state machine writes 1 byte to a card. |
3045 | ** It is a low level bit-bashing state machine. | | 3045 | ** It is a low level bit-bashing state machine. |
3046 | ** | | 3046 | ** |
3047 | ** | | 3047 | ** |
3048 | ** Several mid level machines can use this machine, so the value | | 3048 | ** Several mid level machines can use this machine, so the value |
3049 | ** sc->t0ByteParent is used to point to back to the mid level machine | | 3049 | ** sc->t0ByteParent is used to point to back to the mid level machine |
3050 | ** | | 3050 | ** |
3051 | ** FORMAL PARAMETERS: | | 3051 | ** FORMAL PARAMETERS: |
3052 | ** | | 3052 | ** |
3053 | ** sc - Pointer to the softc structure. | | 3053 | ** sc - Pointer to the softc structure. |
3054 | ** cmd - command to this machine | | 3054 | ** cmd - command to this machine |
3055 | ** | | 3055 | ** |
3056 | ** IMPLICIT INPUTS: | | 3056 | ** IMPLICIT INPUTS: |
3057 | ** | | 3057 | ** |
3058 | ** sc->t0SendByteS state of this machine | | 3058 | ** sc->t0SendByteS state of this machine |
3059 | ** sc->shiftByte byte to write to the card | | 3059 | ** sc->shiftByte byte to write to the card |
3060 | ** | | 3060 | ** |
3061 | ** IMPLICIT OUTPUTS: | | 3061 | ** IMPLICIT OUTPUTS: |
3062 | ** | | 3062 | ** |
3063 | ** sc->status error value if could not read byte | | 3063 | ** sc->status error value if could not read byte |
3064 | ** | | 3064 | ** |
3065 | ** FUNCTION VALUE: | | 3065 | ** FUNCTION VALUE: |
3066 | ** | | 3066 | ** |
3067 | ** nill | | 3067 | ** nill |
3068 | ** | | 3068 | ** |
3069 | ** SIDE EFFECTS: | | 3069 | ** SIDE EFFECTS: |
3070 | ** | | 3070 | ** |
3071 | ** nill | | 3071 | ** nill |
3072 | **-- | | 3072 | **-- |
3073 | */ | | 3073 | */ |
3074 | //int bigTroubleTest = 0; | | 3074 | //int bigTroubleTest = 0; |
3075 | static void t0SendByteSM (struct scr_softc * sc,int cmd) | | 3075 | static void t0SendByteSM (struct scr_softc * sc,int cmd) |
3076 | { | | 3076 | { |
3077 | //if(bigTroubleTest == 2000) | | 3077 | //if(bigTroubleTest == 2000) |
3078 | //{ | | 3078 | //{ |
3079 | // INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3079 | // INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3080 | // bigTroubleTest = 0; | | 3080 | // bigTroubleTest = 0; |
3081 | //} | | 3081 | //} |
3082 | // | | 3082 | // |
3083 | //bigTroubleTest++; | | 3083 | //bigTroubleTest++; |
3084 | | | 3084 | |
3085 | if (sc->bigTrouble) return; // david,jim , remove this when dust settles | | 3085 | if (sc->bigTrouble) return; // david,jim , remove this when dust settles |
3086 | | | 3086 | |
3087 | if (cmd == t0sbcAbort) | | 3087 | if (cmd == t0sbcAbort) |
3088 | { | | 3088 | { |
3089 | /* kill all the timers */ | | 3089 | /* kill all the timers */ |
3090 | scrUntimeout(t0SendByteSM, sc, t0sbcTGuardTime); | | 3090 | scrUntimeout(t0SendByteSM, sc, t0sbcTGuardTime); |
3091 | scrUntimeout(t0SendByteSM, sc, t0sbcTClockData); | | 3091 | scrUntimeout(t0SendByteSM, sc, t0sbcTClockData); |
3092 | scrUntimeout(t0SendByteSM, sc, t0sbcTError); | | 3092 | scrUntimeout(t0SendByteSM, sc, t0sbcTError); |
3093 | | | 3093 | |
3094 | scrSetDataHighZ(); | | 3094 | scrSetDataHighZ(); |
3095 | return; | | 3095 | return; |
3096 | } | | 3096 | } |
3097 | | | 3097 | |
3098 | | | 3098 | |
3099 | switch (sc->t0SendByteS) | | 3099 | switch (sc->t0SendByteS) |
3100 | { | | 3100 | { |
3101 | case t0sbsIdle: | | 3101 | case t0sbsIdle: |
3102 | switch (cmd) | | 3102 | switch (cmd) |
3103 | { | | 3103 | { |
3104 | case t0sbcStart: | | 3104 | case t0sbcStart: |
3105 | /* set initial conditions */ | | 3105 | /* set initial conditions */ |
3106 | sc->shiftBits = 0; | | 3106 | sc->shiftBits = 0; |
3107 | sc->shiftParity = 0; | | 3107 | sc->shiftParity = 0; |
3108 | sc->shiftParityCount = 0; | | 3108 | sc->shiftParityCount = 0; |
3109 | sc->shiftByte = sc->dataByte; | | 3109 | sc->shiftByte = sc->dataByte; |
3110 | | | 3110 | |
3111 | scrClkAdj(sc->clkCountDataSend); /* send data clock running at 1 ETU */ | | 3111 | scrClkAdj(sc->clkCountDataSend); /* send data clock running at 1 ETU */ |
3112 | | | 3112 | |
3113 | /* check if we have to wait for guard time */ | | 3113 | /* check if we have to wait for guard time */ |
3114 | if (0) /* possible optimization here */ | | 3114 | if (0) /* possible optimization here */ |
3115 | { | | 3115 | { |
3116 | /* can send start bit now */ | | 3116 | /* can send start bit now */ |
3117 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); | | 3117 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); |
3118 | scrSetData(false); | | 3118 | scrSetData(false); |
3119 | sc->t0SendByteS = t0sbsClockData; | | 3119 | sc->t0SendByteS = t0sbsClockData; |
3120 | } | | 3120 | } |
3121 | else | | 3121 | else |
3122 | { | | 3122 | { |
3123 | /* need to wait for guard time */ | | 3123 | /* need to wait for guard time */ |
3124 | scrTimeout(t0SendByteSM,sc,t0sbcTGuardTime,sc->clkCountDataSend * (12 + sc->N)); | | 3124 | scrTimeout(t0SendByteSM,sc,t0sbcTGuardTime,sc->clkCountDataSend * (12 + sc->N)); |
3125 | sc->t0SendByteS = t0sbsWaitGuardTime; | | 3125 | sc->t0SendByteS = t0sbsWaitGuardTime; |
3126 | | | 3126 | |
3127 | } | | 3127 | } |
3128 | break; | | 3128 | break; |
3129 | | | 3129 | |
3130 | default: | | 3130 | default: |
3131 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3131 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3132 | break; | | 3132 | break; |
3133 | } | | 3133 | } |
3134 | break; | | 3134 | break; |
3135 | | | 3135 | |
3136 | | | 3136 | |
3137 | case t0sbsWaitGuardTime: | | 3137 | case t0sbsWaitGuardTime: |
3138 | switch (cmd) | | 3138 | switch (cmd) |
3139 | { | | 3139 | { |
3140 | case t0sbcTGuardTime: | | 3140 | case t0sbcTGuardTime: |
3141 | TOGGLE_TEST_PIN(); | | 3141 | TOGGLE_TEST_PIN(); |
3142 | /* set start bit */ | | 3142 | /* set start bit */ |
3143 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); | | 3143 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); |
3144 | scrSetData(false); | | 3144 | scrSetData(false); |
3145 | sc->t0SendByteS = t0sbsClockData; | | 3145 | sc->t0SendByteS = t0sbsClockData; |
3146 | break; | | 3146 | break; |
3147 | | | 3147 | |
3148 | default: | | 3148 | default: |
3149 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3149 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3150 | break; | | 3150 | break; |
3151 | } | | 3151 | } |
3152 | break; | | 3152 | break; |
3153 | | | 3153 | |
3154 | | | 3154 | |
3155 | case t0sbsClockData: | | 3155 | case t0sbsClockData: |
3156 | switch (cmd) | | 3156 | switch (cmd) |
3157 | { | | 3157 | { |
3158 | case t0sbcTClockData: | | 3158 | case t0sbcTClockData: |
3159 | TOGGLE_TEST_PIN(); | | 3159 | TOGGLE_TEST_PIN(); |
3160 | /* clock out data bit */ | | 3160 | /* clock out data bit */ |
3161 | if (sc->shiftBits < 8) | | 3161 | if (sc->shiftBits < 8) |
3162 | { | | 3162 | { |
3163 | if (sc->convention == CONVENTION_INVERSE) | | 3163 | if (sc->convention == CONVENTION_INVERSE) |
3164 | { | | 3164 | { |
3165 | if (sc->shiftByte & 0x80) | | 3165 | if (sc->shiftByte & 0x80) |
3166 | { | | 3166 | { |
3167 | scrSetData(false); | | 3167 | scrSetData(false); |
3168 | sc->shiftParity++; | | 3168 | sc->shiftParity++; |
3169 | } | | 3169 | } |
3170 | else | | 3170 | else |
3171 | { | | 3171 | { |
3172 | scrSetData(true); | | 3172 | scrSetData(true); |
3173 | } | | 3173 | } |
3174 | sc->shiftByte = sc->shiftByte << 1; | | 3174 | sc->shiftByte = sc->shiftByte << 1; |
3175 | } | | 3175 | } |
3176 | else | | 3176 | else |
3177 | { | | 3177 | { |
3178 | ASSERT(sc->convention == CONVENTION_DIRECT); | | 3178 | ASSERT(sc->convention == CONVENTION_DIRECT); |
3179 | if (sc->shiftByte & 0x01) | | 3179 | if (sc->shiftByte & 0x01) |
3180 | { | | 3180 | { |
3181 | scrSetData(true); | | 3181 | scrSetData(true); |
3182 | sc->shiftParity++; | | 3182 | sc->shiftParity++; |
3183 | } | | 3183 | } |
3184 | else | | 3184 | else |
3185 | { | | 3185 | { |
3186 | scrSetData(false); | | 3186 | scrSetData(false); |
3187 | } | | 3187 | } |
3188 | sc->shiftByte = sc->shiftByte >> 1; | | 3188 | sc->shiftByte = sc->shiftByte >> 1; |
3189 | } | | 3189 | } |
3190 | sc->shiftBits++; | | 3190 | sc->shiftBits++; |
3191 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); | | 3191 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); |
3192 | } | | 3192 | } |
3193 | | | 3193 | |
3194 | /* clock out parity bit */ | | 3194 | /* clock out parity bit */ |
3195 | else if (sc->shiftBits == 8) | | 3195 | else if (sc->shiftBits == 8) |
3196 | { | | 3196 | { |
3197 | if ( ((sc->shiftParity & 0x01) && (sc->convention == CONVENTION_INVERSE)) || | | 3197 | if ( ((sc->shiftParity & 0x01) && (sc->convention == CONVENTION_INVERSE)) || |
3198 | (!(sc->shiftParity & 0x01) && (sc->convention == CONVENTION_DIRECT)) ) | | 3198 | (!(sc->shiftParity & 0x01) && (sc->convention == CONVENTION_DIRECT)) ) |
3199 | { | | 3199 | { |
3200 | scrSetData(false); | | 3200 | scrSetData(false); |
3201 | } | | 3201 | } |
3202 | else | | 3202 | else |
3203 | { | | 3203 | { |
3204 | scrSetData(true); | | 3204 | scrSetData(true); |
3205 | } | | 3205 | } |
3206 | sc->shiftBits++; | | 3206 | sc->shiftBits++; |
3207 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); | | 3207 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); |
3208 | } | | 3208 | } |
3209 | | | 3209 | |
3210 | /* all data shifted out, move onto next state */ | | 3210 | /* all data shifted out, move onto next state */ |
3211 | else | | 3211 | else |
3212 | { | | 3212 | { |
3213 | ASSERT(sc->shiftBits > 8); | | 3213 | ASSERT(sc->shiftBits > 8); |
3214 | scrSetData(true); | | 3214 | scrSetData(true); |
3215 | scrTimeout(t0SendByteSM,sc,t0sbcTError,sc->clkCountDataSend); | | 3215 | scrTimeout(t0SendByteSM,sc,t0sbcTError,sc->clkCountDataSend); |
3216 | sc->t0SendByteS = t0sbsWaitError; | | 3216 | sc->t0SendByteS = t0sbsWaitError; |
3217 | } | | 3217 | } |
3218 | break; | | 3218 | break; |
3219 | | | 3219 | |
3220 | default: | | 3220 | default: |
3221 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3221 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3222 | break; | | 3222 | break; |
3223 | } | | 3223 | } |
3224 | break; | | 3224 | break; |
3225 | | | 3225 | |
3226 | case t0sbsWaitError: | | 3226 | case t0sbsWaitError: |
3227 | switch (cmd) | | 3227 | switch (cmd) |
3228 | { | | 3228 | { |
3229 | case t0sbcTError: | | 3229 | case t0sbcTError: |
3230 | /* no error indicated*/ | | 3230 | /* no error indicated*/ |
3231 | if (scrGetData()) | | 3231 | if (scrGetData()) |
3232 | { | | 3232 | { |
3233 | sc->t0SendByteS = t0sbsIdle; | | 3233 | sc->t0SendByteS = t0sbsIdle; |
3234 | sc->t0ByteParent(sc,gcT0SendByte); | | 3234 | sc->t0ByteParent(sc,gcT0SendByte); |
3235 | } | | 3235 | } |
3236 | | | 3236 | |
3237 | /* got error */ | | 3237 | /* got error */ |
3238 | else | | 3238 | else |
3239 | { | | 3239 | { |
3240 | /* got parity error */ | | 3240 | /* got parity error */ |
3241 | if (sc->shiftParityCount < PARITY_ERROR_MAX) | | 3241 | if (sc->shiftParityCount < PARITY_ERROR_MAX) |
3242 | { | | 3242 | { |
3243 | sc->shiftParityCount++; | | 3243 | sc->shiftParityCount++; |
3244 | scrTimeout(t0SendByteSM,sc,t0sbcTResend,sc->clkCountDataSend * 2); | | 3244 | scrTimeout(t0SendByteSM,sc,t0sbcTResend,sc->clkCountDataSend * 2); |
3245 | sc->t0SendByteS = t0sbsWaitResend; | | 3245 | sc->t0SendByteS = t0sbsWaitResend; |
3246 | } | | 3246 | } |
3247 | else | | 3247 | else |
3248 | { | | 3248 | { |
3249 | /* too many parity errors, just give up on this sc->dataByte */ | | 3249 | /* too many parity errors, just give up on this sc->dataByte */ |
3250 | sc->status = ERROR_PARITY; | | 3250 | sc->status = ERROR_PARITY; |
3251 | sc->t0SendByteS = t0sbsIdle; | | 3251 | sc->t0SendByteS = t0sbsIdle; |
3252 | sc->t0ByteParent(sc,gcT0SendByteErr); | | 3252 | sc->t0ByteParent(sc,gcT0SendByteErr); |
3253 | } | | 3253 | } |
3254 | } | | 3254 | } |
3255 | break; | | 3255 | break; |
3256 | | | 3256 | |
3257 | default: | | 3257 | default: |
3258 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3258 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3259 | break; | | 3259 | break; |
3260 | } | | 3260 | } |
3261 | break; | | 3261 | break; |
3262 | | | 3262 | |
3263 | case t0sbsWaitResend: | | 3263 | case t0sbsWaitResend: |
3264 | switch (cmd) | | 3264 | switch (cmd) |
3265 | { | | 3265 | { |
3266 | case t0sbcTResend: | | 3266 | case t0sbcTResend: |
3267 | sc->shiftBits = 0; | | 3267 | sc->shiftBits = 0; |
3268 | sc->shiftParity = 0; | | 3268 | sc->shiftParity = 0; |
3269 | sc->shiftByte = sc->dataByte; | | 3269 | sc->shiftByte = sc->dataByte; |
3270 | /* set start bit */ | | 3270 | /* set start bit */ |
3271 | | | 3271 | |
3272 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); | | 3272 | scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); |
3273 | scrSetData(false); | | 3273 | scrSetData(false); |
3274 | sc->t0SendByteS = t0sbsClockData; | | 3274 | sc->t0SendByteS = t0sbsClockData; |
3275 | break; | | 3275 | break; |
3276 | | | 3276 | |
3277 | default: | | 3277 | default: |
3278 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3278 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3279 | break; | | 3279 | break; |
3280 | } | | 3280 | } |
3281 | break; | | 3281 | break; |
3282 | | | 3282 | |
3283 | | | 3283 | |
3284 | default: | | 3284 | default: |
3285 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); | | 3285 | INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); |
3286 | break; | | 3286 | break; |
3287 | } | | 3287 | } |
3288 | } | | 3288 | } |
3289 | | | 3289 | |
3290 | | | 3290 | |
3291 | | | 3291 | |
3292 | | | 3292 | |
3293 | | | 3293 | |
3294 | | | 3294 | |
3295 | | | 3295 | |
3296 | | | 3296 | |
3297 | | | 3297 | |
3298 | | | 3298 | |
3299 | | | 3299 | |
3300 | /* | | 3300 | /* |
3301 | **++ | | 3301 | **++ |
3302 | ** FUNCTIONAL DESCRIPTION: | | 3302 | ** FUNCTIONAL DESCRIPTION: |
3303 | ** | | 3303 | ** |
3304 | ** cardOff | | 3304 | ** cardOff |
3305 | ** | | 3305 | ** |
3306 | ** Turn all signals to the card off | | 3306 | ** Turn all signals to the card off |
3307 | ** | | 3307 | ** |
3308 | ** FORMAL PARAMETERS: | | 3308 | ** FORMAL PARAMETERS: |
3309 | ** | | 3309 | ** |
3310 | ** sc - Pointer to the softc structure. | | 3310 | ** sc - Pointer to the softc structure. |
3311 | ** | | 3311 | ** |
3312 | ** IMPLICIT INPUTS: | | 3312 | ** IMPLICIT INPUTS: |
3313 | ** | | 3313 | ** |
3314 | ** nill | | 3314 | ** nill |
3315 | ** | | 3315 | ** |
3316 | ** IMPLICIT OUTPUTS: | | 3316 | ** IMPLICIT OUTPUTS: |
3317 | ** | | 3317 | ** |
3318 | ** nill | | 3318 | ** nill |
3319 | ** | | 3319 | ** |
3320 | ** FUNCTION VALUE: | | 3320 | ** FUNCTION VALUE: |
3321 | ** | | 3321 | ** |
3322 | ** nill | | 3322 | ** nill |
3323 | ** | | 3323 | ** |
3324 | ** SIDE EFFECTS: | | 3324 | ** SIDE EFFECTS: |
3325 | ** | | 3325 | ** |
3326 | ** nill | | 3326 | ** nill |
3327 | **-- | | 3327 | **-- |
3328 | */ | | 3328 | */ |
3329 | static void cardOff (struct scr_softc * sc) | | 3329 | static void cardOff (struct scr_softc * sc) |
3330 | { | | 3330 | { |
3331 | scrSetReset(true); | | 3331 | scrSetReset(true); |
3332 | scrSetDataHighZ(); | | 3332 | scrSetDataHighZ(); |
3333 | scrSetClock(false); | | 3333 | scrSetClock(false); |
3334 | scrSetPower(false); | | 3334 | scrSetPower(false); |
3335 | } | | 3335 | } |
3336 | | | 3336 | |
3337 | | | 3337 | |
3338 | | | 3338 | |
3339 | | | 3339 | |
3340 | /* | | 3340 | /* |
3341 | ** | | 3341 | ** |
3342 | ** | | 3342 | ** |
3343 | ** **************** timer routines *************** | | 3343 | ** **************** timer routines *************** |
3344 | ** | | 3344 | ** |
3345 | */ | | 3345 | */ |
3346 | | | 3346 | |
3347 | /* | | 3347 | /* |
3348 | **++ | | 3348 | **++ |
3349 | ** FUNCTIONAL DESCRIPTION: | | 3349 | ** FUNCTIONAL DESCRIPTION: |
3350 | ** | | 3350 | ** |
3351 | ** scrClkInit | | 3351 | ** scrClkInit |
3352 | ** | | 3352 | ** |
3353 | ** Init the callout queues. The callout queues are used | | 3353 | ** Init the callout queues. The callout queues are used |
3354 | ** by the timeout/untimeout queues | | 3354 | ** by the timeout/untimeout queues |
3355 | ** | | 3355 | ** |
3356 | ** FORMAL PARAMETERS: | | 3356 | ** FORMAL PARAMETERS: |
3357 | ** | | 3357 | ** |
3358 | ** nill | | 3358 | ** nill |
3359 | ** | | 3359 | ** |
3360 | ** IMPLICIT INPUTS: | | 3360 | ** IMPLICIT INPUTS: |
3361 | ** | | 3361 | ** |
3362 | ** nill | | 3362 | ** nill |
3363 | ** | | 3363 | ** |
3364 | ** IMPLICIT OUTPUTS: | | 3364 | ** IMPLICIT OUTPUTS: |
3365 | ** | | 3365 | ** |
3366 | ** nill | | 3366 | ** nill |
3367 | ** | | 3367 | ** |
3368 | ** FUNCTION VALUE: | | 3368 | ** FUNCTION VALUE: |
3369 | ** | | 3369 | ** |
3370 | ** nill | | 3370 | ** nill |
3371 | ** | | 3371 | ** |
3372 | ** SIDE EFFECTS: | | 3372 | ** SIDE EFFECTS: |
3373 | ** | | 3373 | ** |
3374 | ** nill | | 3374 | ** nill |
3375 | **-- | | 3375 | **-- |
3376 | */ | | 3376 | */ |
3377 | static void scrClkInit(void) | | 3377 | static void scrClkInit(void) |
3378 | { | | 3378 | { |
3379 | | | 3379 | |
3380 | int lc; | | 3380 | int lc; |
3381 | Callout *c; | | 3381 | Callout *c; |
3382 | Callout *new; | | 3382 | Callout *new; |
3383 | | | 3383 | |
3384 | scrClkCallTodo.c_next = NULL; | | 3384 | scrClkCallTodo.c_next = NULL; |
3385 | scrClkCallFree = &scrClkCalloutArray[0]; | | 3385 | scrClkCallFree = &scrClkCalloutArray[0]; |
3386 | c = scrClkCallFree; | | 3386 | c = scrClkCallFree; |
3387 | | | 3387 | |
3388 | for (lc = 1; lc < SCR_CLK_CALLOUT_COUNT; lc++) | | 3388 | for (lc = 1; lc < SCR_CLK_CALLOUT_COUNT; lc++) |
3389 | { | | 3389 | { |
3390 | new = &scrClkCalloutArray[lc]; | | 3390 | new = &scrClkCalloutArray[lc]; |
3391 | c->c_next = new; | | 3391 | c->c_next = new; |
3392 | c = new; | | 3392 | c = new; |
3393 | } | | 3393 | } |
3394 | | | 3394 | |
3395 | c->c_next = NULL; | | 3395 | c->c_next = NULL; |
3396 | } | | 3396 | } |
3397 | | | 3397 | |
3398 | | | 3398 | |
3399 | /* | | 3399 | /* |
3400 | **++ | | 3400 | **++ |
3401 | ** FUNCTIONAL DESCRIPTION: | | 3401 | ** FUNCTIONAL DESCRIPTION: |
3402 | ** | | 3402 | ** |
3403 | ** scrClkStart | | 3403 | ** scrClkStart |
3404 | ** | | 3404 | ** |
3405 | ** This function starts the clock running. The clock is reall the | | 3405 | ** This function starts the clock running. The clock is reall the |
3406 | ** HAT clock (High Available Timer) that is using a FIQ (fast interrupt | | 3406 | ** HAT clock (High Available Timer) that is using a FIQ (fast interrupt |
3407 | ** request). | | 3407 | ** request). |
3408 | ** | | 3408 | ** |
3409 | ** FORMAL PARAMETERS: | | 3409 | ** FORMAL PARAMETERS: |
3410 | ** | | 3410 | ** |
3411 | ** sc - Pointer to the softc structure. | | 3411 | ** sc - Pointer to the softc structure. |
3412 | ** countPerTick - value for T2 timer that drives FIQ | | 3412 | ** countPerTick - value for T2 timer that drives FIQ |
3413 | ** | | 3413 | ** |
3414 | ** IMPLICIT INPUTS: | | 3414 | ** IMPLICIT INPUTS: |
3415 | ** | | 3415 | ** |
3416 | ** nill | | 3416 | ** nill |
3417 | ** | | 3417 | ** |
3418 | ** IMPLICIT OUTPUTS: | | 3418 | ** IMPLICIT OUTPUTS: |
3419 | ** | | 3419 | ** |
3420 | ** nill | | 3420 | ** nill |
3421 | ** | | 3421 | ** |
3422 | ** FUNCTION VALUE: | | 3422 | ** FUNCTION VALUE: |
3423 | ** | | 3423 | ** |
3424 | ** nill | | 3424 | ** nill |
3425 | ** | | 3425 | ** |
3426 | ** SIDE EFFECTS: | | 3426 | ** SIDE EFFECTS: |
3427 | ** | | 3427 | ** |
3428 | ** nill | | 3428 | ** nill |
3429 | **-- | | 3429 | **-- |
3430 | */ | | 3430 | */ |
3431 | static void scrClkStart(struct scr_softc * sc,int countPerTick) | | 3431 | static void scrClkStart(struct scr_softc * sc,int countPerTick) |
3432 | { | | 3432 | { |
3433 | u_int savedInts; | | 3433 | u_int savedInts; |
3434 | | | 3434 | |
3435 | savedInts = disable_interrupts(I32_bit | F32_bit); | | 3435 | savedInts = disable_interrupts(I32_bit | F32_bit); |
3436 | | | 3436 | |
3437 | | | 3437 | |
3438 | | | 3438 | |
3439 | ASSERT(scrClkCallTodo.c_next == NULL); | | 3439 | ASSERT(scrClkCallTodo.c_next == NULL); |
3440 | ASSERT(!scrClkEnable); | | 3440 | ASSERT(!scrClkEnable); |
3441 | scrClkEnable = 1; | | 3441 | scrClkEnable = 1; |
3442 | scrClkCount = countPerTick; | | 3442 | scrClkCount = countPerTick; |
3443 | | | 3443 | |
3444 | hatClkOn(countPerTick, | | 3444 | hatClkOn(countPerTick, |
3445 | hatClkIrq, | | 3445 | hatClkIrq, |
3446 | 0xdeadbeef, | | 3446 | 0xdeadbeef, |
3447 | hatStack + HATSTACKSIZE - sizeof(unsigned), | | 3447 | hatStack + HATSTACKSIZE - sizeof(unsigned), |
3448 | myHatWedge); | | 3448 | myHatWedge); |
3449 | | | 3449 | |
3450 | restore_interrupts(savedInts); | | 3450 | restore_interrupts(savedInts); |
3451 | } | | 3451 | } |
3452 | | | 3452 | |
3453 | /* | | 3453 | /* |
3454 | **++ | | 3454 | **++ |
3455 | ** FUNCTIONAL DESCRIPTION: | | 3455 | ** FUNCTIONAL DESCRIPTION: |
3456 | ** | | 3456 | ** |
3457 | ** scrClkAdj | | 3457 | ** scrClkAdj |
3458 | ** | | 3458 | ** |
3459 | ** Adjusts the frequence of the clock | | 3459 | ** Adjusts the frequence of the clock |
3460 | ** | | 3460 | ** |
3461 | ** FORMAL PARAMETERS: | | 3461 | ** FORMAL PARAMETERS: |
3462 | ** | | 3462 | ** |
3463 | ** count - new value for T2 timer that drives FIQ | | 3463 | ** count - new value for T2 timer that drives FIQ |
3464 | ** | | 3464 | ** |
3465 | ** IMPLICIT INPUTS: | | 3465 | ** IMPLICIT INPUTS: |
3466 | ** | | 3466 | ** |
3467 | ** nill | | 3467 | ** nill |
3468 | ** | | 3468 | ** |
3469 | ** IMPLICIT OUTPUTS: | | 3469 | ** IMPLICIT OUTPUTS: |
3470 | ** | | 3470 | ** |
3471 | ** nill | | 3471 | ** nill |
3472 | ** | | 3472 | ** |
3473 | ** FUNCTION VALUE: | | 3473 | ** FUNCTION VALUE: |
3474 | ** | | 3474 | ** |
3475 | ** nill | | 3475 | ** nill |
3476 | ** | | 3476 | ** |
3477 | ** SIDE EFFECTS: | | 3477 | ** SIDE EFFECTS: |
3478 | ** | | 3478 | ** |
3479 | ** nill | | 3479 | ** nill |
3480 | **-- | | 3480 | **-- |
3481 | */ | | 3481 | */ |
3482 | static void scrClkAdj (int count) | | 3482 | static void scrClkAdj (int count) |
3483 | { | | 3483 | { |
3484 | u_int savedInts; | | 3484 | u_int savedInts; |
3485 | | | 3485 | |
3486 | if (count != scrClkCount) | | 3486 | if (count != scrClkCount) |
3487 | { | | 3487 | { |
3488 | savedInts = disable_interrupts(I32_bit | F32_bit); | | 3488 | savedInts = disable_interrupts(I32_bit | F32_bit); |
3489 | | | 3489 | |
3490 | ASSERT(scrClkEnable); | | 3490 | ASSERT(scrClkEnable); |
3491 | | | 3491 | |
3492 | scrClkCount = count; | | 3492 | scrClkCount = count; |
3493 | hatClkAdjust(count); | | 3493 | hatClkAdjust(count); |
3494 | | | 3494 | |
3495 | restore_interrupts(savedInts); | | 3495 | restore_interrupts(savedInts); |
3496 | } | | 3496 | } |
3497 | } | | 3497 | } |
3498 | | | 3498 | |
3499 | /* | | 3499 | /* |
3500 | **++ | | 3500 | **++ |
3501 | ** FUNCTIONAL DESCRIPTION: | | 3501 | ** FUNCTIONAL DESCRIPTION: |
3502 | ** | | 3502 | ** |
3503 | ** scrClkStop | | 3503 | ** scrClkStop |
3504 | ** | | 3504 | ** |
3505 | ** Stops the clock | | 3505 | ** Stops the clock |
3506 | ** | | 3506 | ** |
3507 | ** FORMAL PARAMETERS: | | 3507 | ** FORMAL PARAMETERS: |
3508 | ** | | 3508 | ** |
3509 | ** nill | | 3509 | ** nill |
3510 | ** | | 3510 | ** |
3511 | ** | | 3511 | ** |
3512 | ** IMPLICIT INPUTS: | | 3512 | ** IMPLICIT INPUTS: |
3513 | ** | | 3513 | ** |
3514 | ** nill | | 3514 | ** nill |
3515 | ** | | 3515 | ** |
3516 | ** IMPLICIT OUTPUTS: | | 3516 | ** IMPLICIT OUTPUTS: |
3517 | ** | | 3517 | ** |
3518 | ** nill | | 3518 | ** nill |
3519 | ** | | 3519 | ** |
3520 | ** FUNCTION VALUE: | | 3520 | ** FUNCTION VALUE: |
3521 | ** | | 3521 | ** |
3522 | ** nill | | 3522 | ** nill |
3523 | ** | | 3523 | ** |
3524 | ** SIDE EFFECTS: | | 3524 | ** SIDE EFFECTS: |
3525 | ** | | 3525 | ** |
3526 | ** nill | | 3526 | ** nill |
3527 | **-- | | 3527 | **-- |
3528 | */ | | 3528 | */ |
3529 | static void scrClkStop(void) | | 3529 | static void scrClkStop(void) |
3530 | { | | 3530 | { |
3531 | u_int savedInts; | | 3531 | u_int savedInts; |
3532 | savedInts = disable_interrupts(I32_bit | F32_bit); | | 3532 | savedInts = disable_interrupts(I32_bit | F32_bit); |
3533 | | | 3533 | |
3534 | ASSERT(scrClkEnable); | | 3534 | ASSERT(scrClkEnable); |
3535 | scrClkEnable = 0; | | 3535 | scrClkEnable = 0; |
3536 | ASSERT(scrClkCallTodo.c_next == NULL); | | 3536 | ASSERT(scrClkCallTodo.c_next == NULL); |
3537 | hatClkOff(); | | 3537 | hatClkOff(); |
3538 | | | 3538 | |
3539 | restore_interrupts(savedInts); | | 3539 | restore_interrupts(savedInts); |
3540 | } | | 3540 | } |
3541 | | | 3541 | |
3542 | | | 3542 | |
3543 | | | 3543 | |
3544 | /* | | 3544 | /* |
3545 | **++ | | 3545 | **++ |
3546 | ** FUNCTIONAL DESCRIPTION: | | 3546 | ** FUNCTIONAL DESCRIPTION: |
3547 | ** | | 3547 | ** |
3548 | ** hatClkIrq | | 3548 | ** hatClkIrq |
3549 | ** | | 3549 | ** |
3550 | ** This is what the HAT clock calls. This call drives | | 3550 | ** This is what the HAT clock calls. This call drives |
3551 | ** the timeout queues, which in turn drive the state machines | | 3551 | ** the timeout queues, which in turn drive the state machines |
3552 | ** | | 3552 | ** |
3553 | ** Be very carefully when calling a timeout as the function | | 3553 | ** Be very carefully when calling a timeout as the function |
3554 | ** that is called may in turn do timeout/untimeout calls | | 3554 | ** that is called may in turn do timeout/untimeout calls |
3555 | ** before returning | | 3555 | ** before returning |
3556 | ** | | 3556 | ** |
3557 | ** FORMAL PARAMETERS: | | 3557 | ** FORMAL PARAMETERS: |
3558 | ** | | 3558 | ** |
3559 | ** int x - not used | | 3559 | ** int x - not used |
3560 | ** | | 3560 | ** |
3561 | ** IMPLICIT INPUTS: | | 3561 | ** IMPLICIT INPUTS: |
3562 | ** | | 3562 | ** |
3563 | ** nill | | 3563 | ** nill |
3564 | ** | | 3564 | ** |
3565 | ** IMPLICIT OUTPUTS: | | 3565 | ** IMPLICIT OUTPUTS: |
3566 | ** | | 3566 | ** |
3567 | ** nill | | 3567 | ** nill |
3568 | ** | | 3568 | ** |
3569 | ** FUNCTION VALUE: | | 3569 | ** FUNCTION VALUE: |
3570 | ** | | 3570 | ** |
3571 | ** nill | | 3571 | ** nill |
3572 | ** | | 3572 | ** |
3573 | ** SIDE EFFECTS: | | 3573 | ** SIDE EFFECTS: |
3574 | ** | | 3574 | ** |
3575 | ** a timeout may be called if it is due | | 3575 | ** a timeout may be called if it is due |
3576 | **-- | | 3576 | **-- |
3577 | */ | | 3577 | */ |
3578 | static void hatClkIrq(int x) | | 3578 | static void hatClkIrq(int x) |
3579 | { | | 3579 | { |
3580 | register Callout *p1; | | 3580 | register Callout *p1; |
3581 | register int needsoft =0; | | 3581 | register int needsoft =0; |
3582 | register Callout *c; | | 3582 | register Callout *c; |
3583 | register int arg; | | 3583 | register int arg; |
3584 | register void (*func)(struct scr_softc*,int); | | 3584 | register void (*func)(struct scr_softc*,int); |
3585 | struct scr_softc * sc; | | 3585 | struct scr_softc * sc; |
3586 | | | 3586 | |
3587 | ASSERT(scrClkEnable); | | 3587 | ASSERT(scrClkEnable); |
3588 | for (p1 = scrClkCallTodo.c_next; p1 != NULL; p1 = p1->c_next) | | 3588 | for (p1 = scrClkCallTodo.c_next; p1 != NULL; p1 = p1->c_next) |
3589 | { | | 3589 | { |
3590 | p1->c_time -= scrClkCount; | | 3590 | p1->c_time -= scrClkCount; |
3591 | | | 3591 | |
3592 | if (p1->c_time > 0) | | 3592 | if (p1->c_time > 0) |
3593 | { | | 3593 | { |
3594 | break; | | 3594 | break; |
3595 | } | | 3595 | } |
3596 | needsoft = 1; | | 3596 | needsoft = 1; |
3597 | if (p1->c_time == 0) | | 3597 | if (p1->c_time == 0) |
3598 | { | | 3598 | { |
3599 | break; | | 3599 | break; |
3600 | } | | 3600 | } |
3601 | } | | 3601 | } |
3602 | | | 3602 | |
3603 | | | 3603 | |
3604 | if (needsoft) | | 3604 | if (needsoft) |
3605 | { | | 3605 | { |
3606 | while ((c = scrClkCallTodo.c_next) != NULL && c->c_time <= 0) | | 3606 | while ((c = scrClkCallTodo.c_next) != NULL && c->c_time <= 0) |
3607 | { | | 3607 | { |
3608 | func = c->c_func; | | 3608 | func = c->c_func; |
3609 | sc = c->c_sc; | | 3609 | sc = c->c_sc; |
3610 | arg = c->c_arg; | | 3610 | arg = c->c_arg; |
3611 | scrClkCallTodo.c_next = c->c_next; | | 3611 | scrClkCallTodo.c_next = c->c_next; |
3612 | c->c_next = scrClkCallFree; | | 3612 | c->c_next = scrClkCallFree; |
3613 | scrClkCallFree = c; | | 3613 | scrClkCallFree = c; |
3614 | (*func)(sc,arg); | | 3614 | (*func)(sc,arg); |
3615 | } | | 3615 | } |
3616 | } | | 3616 | } |
3617 | } | | 3617 | } |
3618 | | | 3618 | |
3619 | /* | | 3619 | /* |
3620 | **++ | | 3620 | **++ |
3621 | ** FUNCTIONAL DESCRIPTION: | | 3621 | ** FUNCTIONAL DESCRIPTION: |
3622 | ** | | 3622 | ** |
3623 | ** myHatWedge | | 3623 | ** myHatWedge |
3624 | ** | | 3624 | ** |
3625 | ** Called if the HAT timer becomes clogged/wedged. Not | | 3625 | ** Called if the HAT timer becomes clogged/wedged. Not |
3626 | ** used by this driver, we let upper layers recover | | 3626 | ** used by this driver, we let upper layers recover |
3627 | ** from this condition | | 3627 | ** from this condition |
3628 | ** | | 3628 | ** |
3629 | ** FORMAL PARAMETERS: | | 3629 | ** FORMAL PARAMETERS: |
3630 | ** | | 3630 | ** |
3631 | ** int nFIQs - not used | | 3631 | ** int nFIQs - not used |
3632 | ** | | 3632 | ** |
3633 | ** IMPLICIT INPUTS: | | 3633 | ** IMPLICIT INPUTS: |
3634 | ** | | 3634 | ** |
3635 | ** nill | | 3635 | ** nill |
3636 | ** | | 3636 | ** |
3637 | ** IMPLICIT OUTPUTS: | | 3637 | ** IMPLICIT OUTPUTS: |
3638 | ** | | 3638 | ** |
3639 | ** nill | | 3639 | ** nill |
3640 | ** | | 3640 | ** |
3641 | ** FUNCTION VALUE: | | 3641 | ** FUNCTION VALUE: |
3642 | ** | | 3642 | ** |
3643 | ** nill | | 3643 | ** nill |
3644 | ** | | 3644 | ** |
3645 | ** SIDE EFFECTS: | | 3645 | ** SIDE EFFECTS: |
3646 | ** | | 3646 | ** |
3647 | ** nill | | 3647 | ** nill |
3648 | **-- | | 3648 | **-- |
3649 | */ | | 3649 | */ |
3650 | static void myHatWedge(int nFIQs) | | 3650 | static void myHatWedge(int nFIQs) |
3651 | { | | 3651 | { |
3652 | #ifdef DEBUG | | 3652 | #ifdef DEBUG |
3653 | printf("myHatWedge: nFIQ = %d\n",nFIQs); | | 3653 | printf("myHatWedge: nFIQ = %d\n",nFIQs); |
3654 | #endif | | 3654 | #endif |
3655 | } | | 3655 | } |
3656 | | | 3656 | |
3657 | | | 3657 | |
3658 | | | 3658 | |
3659 | /* | | 3659 | /* |
3660 | **++ | | 3660 | **++ |
3661 | ** FUNCTIONAL DESCRIPTION: | | 3661 | ** FUNCTIONAL DESCRIPTION: |
3662 | ** | | 3662 | ** |
3663 | ** scrTimeout | | 3663 | ** scrTimeout |
3664 | ** | | 3664 | ** |
3665 | ** Execute a function after a specified length of time. | | 3665 | ** Execute a function after a specified length of time. |
3666 | ** | | 3666 | ** |
3667 | ** | | 3667 | ** |
3668 | ** FORMAL PARAMETERS: | | 3668 | ** FORMAL PARAMETERS: |
3669 | ** | | 3669 | ** |
3670 | ** ftn - function to execute | | 3670 | ** ftn - function to execute |
3671 | ** sc - pointer to soft c | | 3671 | ** sc - pointer to soft c |
3672 | ** arg - argument passed to function | | 3672 | ** arg - argument passed to function |
3673 | ** count - number of T2 counts for timeout | | 3673 | ** count - number of T2 counts for timeout |
3674 | ** | | 3674 | ** |
3675 | ** IMPLICIT INPUTS: | | 3675 | ** IMPLICIT INPUTS: |
3676 | ** | | 3676 | ** |
3677 | ** nill | | 3677 | ** nill |
3678 | ** | | 3678 | ** |
3679 | ** IMPLICIT OUTPUTS: | | 3679 | ** IMPLICIT OUTPUTS: |
3680 | ** | | 3680 | ** |
3681 | ** nill | | 3681 | ** nill |
3682 | ** | | 3682 | ** |
3683 | ** FUNCTION VALUE: | | 3683 | ** FUNCTION VALUE: |
3684 | ** | | 3684 | ** |
3685 | ** nill | | 3685 | ** nill |
3686 | ** | | 3686 | ** |
3687 | ** SIDE EFFECTS: | | 3687 | ** SIDE EFFECTS: |
3688 | ** | | 3688 | ** |
3689 | ** nill | | 3689 | ** nill |
3690 | **-- | | 3690 | **-- |
3691 | */ | | 3691 | */ |
3692 | | | 3692 | |
3693 | static void scrTimeout(ftn, sc, arg, count) | | 3693 | static void |
3694 | void (*ftn)(struct scr_softc*,int); | | 3694 | scrTimeout( |
3695 | struct scr_softc* sc; | | 3695 | void (*ftn)(struct scr_softc*,int), |
3696 | int arg; | | 3696 | struct scr_softc* sc, |
3697 | register int count; | | 3697 | int arg, |
| | | 3698 | int count) |
3698 | { | | 3699 | { |
3699 | | | 3700 | |
3700 | register Callout *new, *p, *t; | | 3701 | register Callout *new, *p, *t; |
3701 | ASSERT(scrClkEnable); | | 3702 | ASSERT(scrClkEnable); |
3702 | | | 3703 | |
3703 | | | 3704 | |
3704 | if (count <= 0) | | 3705 | if (count <= 0) |
3705 | { | | 3706 | { |
3706 | count = 1; | | 3707 | count = 1; |
3707 | } | | 3708 | } |
3708 | | | 3709 | |
3709 | | | 3710 | |
3710 | /* Fill in the next free fcallout structure. */ | | 3711 | /* Fill in the next free fcallout structure. */ |
3711 | if (scrClkCallFree == NULL) | | 3712 | if (scrClkCallFree == NULL) |
3712 | { | | 3713 | { |
3713 | panic("timeout table full"); | | 3714 | panic("timeout table full"); |
3714 | } | | 3715 | } |
3715 | | | 3716 | |
3716 | new = scrClkCallFree; | | 3717 | new = scrClkCallFree; |
3717 | scrClkCallFree = new->c_next; | | 3718 | scrClkCallFree = new->c_next; |
3718 | new->c_sc = sc; | | 3719 | new->c_sc = sc; |
3719 | new->c_arg = arg; | | 3720 | new->c_arg = arg; |
3720 | new->c_func = ftn; | | 3721 | new->c_func = ftn; |
3721 | | | 3722 | |
3722 | /* | | 3723 | /* |
3723 | * The time for each event is stored as a difference from the time | | 3724 | * The time for each event is stored as a difference from the time |
3724 | * of the previous event on the queue. Walk the queue, correcting | | 3725 | * of the previous event on the queue. Walk the queue, correcting |
3725 | * the counts argument for queue entries passed. Correct the counts | | 3726 | * the counts argument for queue entries passed. Correct the counts |
3726 | * value for the queue entry immediately after the insertion point | | 3727 | * value for the queue entry immediately after the insertion point |
3727 | * as well. Watch out for negative c_time values; these represent | | 3728 | * as well. Watch out for negative c_time values; these represent |
3728 | * overdue events. | | 3729 | * overdue events. |
3729 | */ | | 3730 | */ |
3730 | for (p = &scrClkCallTodo; (t = p->c_next) != NULL && count > t->c_time; p = t) | | 3731 | for (p = &scrClkCallTodo; (t = p->c_next) != NULL && count > t->c_time; p = t) |
3731 | { | | 3732 | { |
3732 | if (t->c_time > 0) | | 3733 | if (t->c_time > 0) |
3733 | { | | 3734 | { |
3734 | count -= t->c_time; | | 3735 | count -= t->c_time; |
3735 | } | | 3736 | } |
3736 | } | | 3737 | } |
3737 | | | 3738 | |
3738 | | | 3739 | |
3739 | new->c_time = count; | | 3740 | new->c_time = count; |
3740 | if (t != NULL) | | 3741 | if (t != NULL) |
3741 | { | | 3742 | { |
3742 | t->c_time -= count; | | 3743 | t->c_time -= count; |
3743 | } | | 3744 | } |
3744 | | | 3745 | |
3745 | /* Insert the new entry into the queue. */ | | 3746 | /* Insert the new entry into the queue. */ |
3746 | p->c_next = new; | | 3747 | p->c_next = new; |
3747 | new->c_next = t; | | 3748 | new->c_next = t; |
3748 | } | | 3749 | } |
3749 | | | 3750 | |
3750 | /* | | 3751 | /* |
3751 | **++ | | 3752 | **++ |
3752 | ** FUNCTIONAL DESCRIPTION: | | 3753 | ** FUNCTIONAL DESCRIPTION: |
3753 | ** | | 3754 | ** |
3754 | ** scrUntimeout | | 3755 | ** scrUntimeout |
3755 | ** | | 3756 | ** |
3756 | ** Cancel previous timeout function call. | | 3757 | ** Cancel previous timeout function call. |
3757 | ** | | 3758 | ** |
3758 | ** FORMAL PARAMETERS: | | 3759 | ** FORMAL PARAMETERS: |
3759 | ** | | 3760 | ** |
3760 | ** ftn - function of timeout to cancel | | 3761 | ** ftn - function of timeout to cancel |
3761 | ** sc - sc of timeout to cancel | | 3762 | ** sc - sc of timeout to cancel |
3762 | ** arg - arg of timeout to cancel | | 3763 | ** arg - arg of timeout to cancel |
3763 | ** | | 3764 | ** |
3764 | ** IMPLICIT INPUTS: | | 3765 | ** IMPLICIT INPUTS: |
3765 | ** | | 3766 | ** |
3766 | ** nill | | 3767 | ** nill |
3767 | ** | | 3768 | ** |
3768 | ** IMPLICIT OUTPUTS: | | 3769 | ** IMPLICIT OUTPUTS: |
3769 | ** | | 3770 | ** |
3770 | ** nill | | 3771 | ** nill |
3771 | ** | | 3772 | ** |
3772 | ** FUNCTION VALUE: | | 3773 | ** FUNCTION VALUE: |
3773 | ** | | 3774 | ** |
3774 | ** nill | | 3775 | ** nill |
3775 | ** | | 3776 | ** |
3776 | ** SIDE EFFECTS: | | 3777 | ** SIDE EFFECTS: |
3777 | ** | | 3778 | ** |
3778 | ** nill | | 3779 | ** nill |
3779 | **-- | | 3780 | **-- |
3780 | */ | | 3781 | */ |
3781 | static void scrUntimeout(ftn, sc, arg) | | 3782 | static void |
3782 | void (*ftn)(struct scr_softc*,int); | | 3783 | scrUntimeout( |
3783 | struct scr_softc* sc; | | 3784 | void (*ftn)(struct scr_softc*, int), |
3784 | int arg; | | 3785 | struct scr_softc* sc, |
| | | 3786 | int arg) |
3785 | { | | 3787 | { |
3786 | register Callout *p, *t; | | 3788 | register Callout *p, *t; |
3787 | ASSERT(scrClkEnable); | | 3789 | ASSERT(scrClkEnable); |
3788 | | | 3790 | |
3789 | for (p = &scrClkCallTodo; (t = p->c_next) != NULL; p = t) | | 3791 | for (p = &scrClkCallTodo; (t = p->c_next) != NULL; p = t) |
3790 | { | | 3792 | { |
3791 | if (t->c_func == ftn && t->c_sc == sc && t->c_arg == arg) | | 3793 | if (t->c_func == ftn && t->c_sc == sc && t->c_arg == arg) |
3792 | { | | 3794 | { |
3793 | /* Increment next entry's count. */ | | 3795 | /* Increment next entry's count. */ |
3794 | if (t->c_next && t->c_time > 0) | | 3796 | if (t->c_next && t->c_time > 0) |
3795 | { | | 3797 | { |
3796 | t->c_next->c_time += t->c_time; | | 3798 | t->c_next->c_time += t->c_time; |
3797 | } | | 3799 | } |
3798 | | | 3800 | |
3799 | /* Move entry from fcallout queue to scrClkCallFree queue. */ | | 3801 | /* Move entry from fcallout queue to scrClkCallFree queue. */ |
3800 | p->c_next = t->c_next; | | 3802 | p->c_next = t->c_next; |
3801 | t->c_next = scrClkCallFree; | | 3803 | t->c_next = scrClkCallFree; |
3802 | scrClkCallFree = t; | | 3804 | scrClkCallFree = t; |
3803 | break; | | 3805 | break; |
3804 | } | | 3806 | } |
3805 | } | | 3807 | } |
3806 | } | | 3808 | } |
3807 | | | 3809 | |
3808 | | | 3810 | |
3809 | | | 3811 | |
3810 | | | 3812 | |
3811 | | | 3813 | |
3812 | | | 3814 | |
3813 | | | 3815 | |
3814 | | | 3816 | |
3815 | | | 3817 | |
3816 | | | 3818 | |
3817 | | | 3819 | |
3818 | | | 3820 | |
3819 | | | 3821 | |
3820 | | | 3822 | |
3821 | | | 3823 | |
3822 | /******************* routines used only during debugging */ | | 3824 | /******************* routines used only during debugging */ |
3823 | #ifdef SCR_DEBUG | | 3825 | #ifdef SCR_DEBUG |
3824 | | | 3826 | |
3825 | /* | | 3827 | /* |
3826 | **++ | | 3828 | **++ |
3827 | ** FUNCTIONAL DESCRIPTION: | | 3829 | ** FUNCTIONAL DESCRIPTION: |
3828 | ** | | 3830 | ** |
3829 | ** invalidStateCmd | | 3831 | ** invalidStateCmd |
3830 | ** | | 3832 | ** |
3831 | ** Debugging function. Printout information about problem | | 3833 | ** Debugging function. Printout information about problem |
3832 | ** and then kick in the debugger or panic | | 3834 | ** and then kick in the debugger or panic |
3833 | ** | | 3835 | ** |
3834 | ** FORMAL PARAMETERS: | | 3836 | ** FORMAL PARAMETERS: |
3835 | ** | | 3837 | ** |
3836 | ** sc - pointer to soft c | | 3838 | ** sc - pointer to soft c |
3837 | ** state - state of machine | | 3839 | ** state - state of machine |
3838 | ** cmd - command of machine | | 3840 | ** cmd - command of machine |
3839 | ** line - line that problem was detected | | 3841 | ** line - line that problem was detected |
3840 | ** | | 3842 | ** |
3841 | ** | | 3843 | ** |
3842 | ** IMPLICIT INPUTS: | | 3844 | ** IMPLICIT INPUTS: |
3843 | ** | | 3845 | ** |
3844 | ** nill | | 3846 | ** nill |
3845 | ** | | 3847 | ** |
3846 | ** IMPLICIT OUTPUTS: | | 3848 | ** IMPLICIT OUTPUTS: |
3847 | ** | | 3849 | ** |
3848 | ** nill | | 3850 | ** nill |
3849 | ** | | 3851 | ** |
3850 | ** FUNCTION VALUE: | | 3852 | ** FUNCTION VALUE: |
3851 | ** | | 3853 | ** |
3852 | ** nill | | 3854 | ** nill |
3853 | ** | | 3855 | ** |
3854 | ** SIDE EFFECTS: | | 3856 | ** SIDE EFFECTS: |
3855 | ** | | 3857 | ** |
3856 | ** nill | | 3858 | ** nill |
3857 | **-- | | 3859 | **-- |
3858 | */ | | 3860 | */ |
3859 | void invalidStateCmd (struct scr_softc* sc,int state,int cmd,int line) | | 3861 | void invalidStateCmd (struct scr_softc* sc,int state,int cmd,int line) |
3860 | { | | 3862 | { |
3861 | printf("INVALID_STATE_CMD: sc = %X, state = %X, cmd = %X, line = %d\n",sc,state,cmd,line); | | 3863 | printf("INVALID_STATE_CMD: sc = %X, state = %X, cmd = %X, line = %d\n",sc,state,cmd,line); |
3862 | DEBUGGER; | | 3864 | DEBUGGER; |
3863 | } | | 3865 | } |
3864 | | | 3866 | |
3865 | /* | | 3867 | /* |
3866 | **++ | | 3868 | **++ |
3867 | ** FUNCTIONAL DESCRIPTION: | | 3869 | ** FUNCTIONAL DESCRIPTION: |
3868 | ** | | 3870 | ** |
3869 | ** getText | | 3871 | ** getText |
3870 | ** | | 3872 | ** |
3871 | ** Get text representation of state or command | | 3873 | ** Get text representation of state or command |
3872 | ** | | 3874 | ** |
3873 | ** FORMAL PARAMETERS: | | 3875 | ** FORMAL PARAMETERS: |
3874 | ** | | 3876 | ** |
3875 | ** x - state or command | | 3877 | ** x - state or command |
3876 | ** | | 3878 | ** |
3877 | ** IMPLICIT INPUTS: | | 3879 | ** IMPLICIT INPUTS: |
3878 | ** | | 3880 | ** |
3879 | ** nill | | 3881 | ** nill |
3880 | ** | | 3882 | ** |
3881 | ** IMPLICIT OUTPUTS: | | 3883 | ** IMPLICIT OUTPUTS: |
3882 | ** | | 3884 | ** |
3883 | ** nill | | 3885 | ** nill |
3884 | ** | | 3886 | ** |
3885 | ** FUNCTION VALUE: | | 3887 | ** FUNCTION VALUE: |
3886 | ** | | 3888 | ** |
3887 | ** nill | | 3889 | ** nill |
3888 | ** | | 3890 | ** |
3889 | ** SIDE EFFECTS: | | 3891 | ** SIDE EFFECTS: |
3890 | ** | | 3892 | ** |
3891 | ** nill | | 3893 | ** nill |
3892 | **-- | | 3894 | **-- |
3893 | */ | | 3895 | */ |
3894 | char * getText(int x) | | 3896 | char * getText(int x) |
3895 | { | | 3897 | { |
3896 | switch (x) | | 3898 | switch (x) |
3897 | { | | 3899 | { |
3898 | /* commands to Master State Machine (mc = Master Command )*/ | | 3900 | /* commands to Master State Machine (mc = Master Command )*/ |
3899 | case mcOn: return "mcOn"; | | 3901 | case mcOn: return "mcOn"; |
3900 | case mcT0DataSend: return "mcT0DataSend"; | | 3902 | case mcT0DataSend: return "mcT0DataSend"; |
3901 | case mcT0DataRecv: return "mcT0DataRecv"; | | 3903 | case mcT0DataRecv: return "mcT0DataRecv"; |
3902 | case mcColdReset: return "mcColdReset"; | | 3904 | case mcColdReset: return "mcColdReset"; |
3903 | case mcATR: return "mcATR"; | | 3905 | case mcATR: return "mcATR"; |
3904 | case mcT0Send: return "mcT0Send"; | | 3906 | case mcT0Send: return "mcT0Send"; |
3905 | case mcT0Recv: return "mcT0Recv"; | | 3907 | case mcT0Recv: return "mcT0Recv"; |
3906 | | | 3908 | |
3907 | /* states in Master state machine (ms = Master State) */ | | 3909 | /* states in Master state machine (ms = Master State) */ |
3908 | case msIdleOff: return "msIdleOff"; | | 3910 | case msIdleOff: return "msIdleOff"; |
3909 | case msColdReset: return "msColdReset"; | | 3911 | case msColdReset: return "msColdReset"; |
3910 | case msATR: return "msATR"; | | 3912 | case msATR: return "msATR"; |
3911 | case msIdleOn: return "msIdleOn"; | | 3913 | case msIdleOn: return "msIdleOn"; |
3912 | case msT0Send: return "msT0Send"; | | 3914 | case msT0Send: return "msT0Send"; |
3913 | case msT0Recv: return "msT0Recv"; | | 3915 | case msT0Recv: return "msT0Recv"; |
3914 | | | 3916 | |
3915 | | | 3917 | |
3916 | | | 3918 | |
3917 | /* commands to T0 send state machine */ | | 3919 | /* commands to T0 send state machine */ |
3918 | case t0scStart: return "t0scStart"; | | 3920 | case t0scStart: return "t0scStart"; |
3919 | case t0scTWorkWaiting: return "t0scTWorkWaiting"; | | 3921 | case t0scTWorkWaiting: return "t0scTWorkWaiting"; |
3920 | | | 3922 | |
3921 | | | 3923 | |
3922 | /* states in T0 send state machine */ | | 3924 | /* states in T0 send state machine */ |
3923 | case t0ssIdle: return "t0ssIdle"; | | 3925 | case t0ssIdle: return "t0ssIdle"; |
3924 | case t0ssSendHeader: return "t0ssSendHeader"; | | 3926 | case t0ssSendHeader: return "t0ssSendHeader"; |
3925 | case t0ssRecvProcedure: return "t0ssRecvProcedu"; | | 3927 | case t0ssRecvProcedure: return "t0ssRecvProcedu"; |
3926 | case t0ssSendByte: return "t0ssSendByte"; | | 3928 | case t0ssSendByte: return "t0ssSendByte"; |
3927 | case t0ssSendData: return "t0ssSendData"; | | 3929 | case t0ssSendData: return "t0ssSendData"; |
3928 | case t0ssRecvSW1: return "t0ssRecvSW1"; | | 3930 | case t0ssRecvSW1: return "t0ssRecvSW1"; |
3929 | case t0ssRecvSW2: return "t0ssRecvSW2"; | | 3931 | case t0ssRecvSW2: return "t0ssRecvSW2"; |
3930 | | | 3932 | |
3931 | | | 3933 | |
3932 | /* commands to T0 recv state machine */ | | 3934 | /* commands to T0 recv state machine */ |
3933 | case t0rcStart: return "t0rcStart"; | | 3935 | case t0rcStart: return "t0rcStart"; |
3934 | case t0rcTWorkWaiting: return "t0rcTWorkWaiting"; | | 3936 | case t0rcTWorkWaiting: return "t0rcTWorkWaiting"; |
3935 | | | 3937 | |
3936 | /* states in T0 recv state machine */ | | 3938 | /* states in T0 recv state machine */ |
3937 | case t0rsIdle: return "t0rsIdle"; | | 3939 | case t0rsIdle: return "t0rsIdle"; |
3938 | case t0rsSendHeader: return "t0rsSendHeader"; | | 3940 | case t0rsSendHeader: return "t0rsSendHeader"; |
3939 | case t0rsRecvProcedure: return "t0rsRecvProcedure"; | | 3941 | case t0rsRecvProcedure: return "t0rsRecvProcedure"; |
3940 | case t0rsRecvByte: return "t0rsRecvByte"; | | 3942 | case t0rsRecvByte: return "t0rsRecvByte"; |
3941 | case t0rsRecvData: return "t0rsRecvData"; | | 3943 | case t0rsRecvData: return "t0rsRecvData"; |
3942 | case t0rsRecvSW1: return "t0rsRecvSW1"; | | 3944 | case t0rsRecvSW1: return "t0rsRecvSW1"; |
3943 | case t0rsRecvSW2: return "t0rsRecvSW2"; | | 3945 | case t0rsRecvSW2: return "t0rsRecvSW2"; |
3944 | | | 3946 | |
3945 | | | 3947 | |
3946 | | | 3948 | |
3947 | | | 3949 | |
3948 | | | 3950 | |
3949 | /* commands to Answer To Reset (ATR) state machine */ | | 3951 | /* commands to Answer To Reset (ATR) state machine */ |
3950 | case atrcStart: return "atrcStart"; | | 3952 | case atrcStart: return "atrcStart"; |
3951 | case atrcT3: return "0x0b04"; | | 3953 | case atrcT3: return "0x0b04"; |
3952 | case atrcTWorkWaiting: return "atrcTWorkWaiting"; | | 3954 | case atrcTWorkWaiting: return "atrcTWorkWaiting"; |
3953 | | | 3955 | |
3954 | | | 3956 | |
3955 | /* states in in Anser To Reset (ATR) state machine */ | | 3957 | /* states in in Anser To Reset (ATR) state machine */ |
3956 | case atrsIdle: return "atrsIdle"; | | 3958 | case atrsIdle: return "atrsIdle"; |
3957 | case atrsTS: return "atrsTS"; | | 3959 | case atrsTS: return "atrsTS"; |
3958 | case atrsT0: return "atrsT0"; | | 3960 | case atrsT0: return "atrsT0"; |
3959 | case atrsTABCD: return "atrsTABCD"; | | 3961 | case atrsTABCD: return "atrsTABCD"; |
3960 | case atrsTK: return "atrsTK"; | | 3962 | case atrsTK: return "atrsTK"; |
3961 | case atrsTCK: return "atrsTCK"; | | 3963 | case atrsTCK: return "atrsTCK"; |
3962 | | | 3964 | |
3963 | | | 3965 | |
3964 | | | 3966 | |
3965 | /* commands to T0 Recv Byte state machine */ | | 3967 | /* commands to T0 Recv Byte state machine */ |
3966 | case t0rbcStart: return "t0rbcStart"; | | 3968 | case t0rbcStart: return "t0rbcStart"; |
3967 | case t0rbcAbort: return "t0rbcAbort"; | | 3969 | case t0rbcAbort: return "t0rbcAbort"; |
3968 | | | 3970 | |
3969 | case t0rbcTFindStartEdge:return "t0rbcTFindStartEdge"; | | 3971 | case t0rbcTFindStartEdge:return "t0rbcTFindStartEdge"; |
3970 | case t0rbcTFindStartMid: return "t0rbcTFindStartMid"; | | 3972 | case t0rbcTFindStartMid: return "t0rbcTFindStartMid"; |
3971 | case t0rbcTClockData: return "t0rbcTClockData"; | | 3973 | case t0rbcTClockData: return "t0rbcTClockData"; |
3972 | case t0rbcTErrorStart: return "t0rbcTErrorStart"; | | 3974 | case t0rbcTErrorStart: return "t0rbcTErrorStart"; |
3973 | case t0rbcTErrorStop: return "t0rbcTErrorStop"; | | 3975 | case t0rbcTErrorStop: return "t0rbcTErrorStop"; |
3974 | | | 3976 | |
3975 | /* states in in TO Recv Byte state machine */ | | 3977 | /* states in in TO Recv Byte state machine */ |
3976 | case t0rbsIdle: return "t0rbsIdle"; | | 3978 | case t0rbsIdle: return "t0rbsIdle"; |
3977 | case t0rbsFindStartEdge: return "t0rbcFindStartEdge"; | | 3979 | case t0rbsFindStartEdge: return "t0rbcFindStartEdge"; |
3978 | case t0rbsFindStartMid: return "t0rbcFindStartMid"; | | 3980 | case t0rbsFindStartMid: return "t0rbcFindStartMid"; |
3979 | case t0rbsClockData: return "t0rbcClockData"; | | 3981 | case t0rbsClockData: return "t0rbcClockData"; |
3980 | case t0rbsSendError: return "t0rbcSendError"; | | 3982 | case t0rbsSendError: return "t0rbcSendError"; |
3981 | | | 3983 | |
3982 | | | 3984 | |
3983 | /* commands to T0 Send Byte state machine */ | | 3985 | /* commands to T0 Send Byte state machine */ |
3984 | case t0sbcStart: return "t0sbcStart"; | | 3986 | case t0sbcStart: return "t0sbcStart"; |
3985 | case t0sbcAbort: return "t0sbcAbort"; | | 3987 | case t0sbcAbort: return "t0sbcAbort"; |
3986 | case t0sbcTGuardTime: return "t0sbcTGuardTime"; | | 3988 | case t0sbcTGuardTime: return "t0sbcTGuardTime"; |
3987 | case t0sbcTClockData: return "t0sbcTClockData"; | | 3989 | case t0sbcTClockData: return "t0sbcTClockData"; |
3988 | case t0sbcTError: return "t0sbcTError"; | | 3990 | case t0sbcTError: return "t0sbcTError"; |
3989 | case t0sbcTResend: return "t0sbcTResend"; | | 3991 | case t0sbcTResend: return "t0sbcTResend"; |
3990 | | | 3992 | |
3991 | /* states in in T0 Send Byte state machine */ | | 3993 | /* states in in T0 Send Byte state machine */ |
3992 | case t0sbsIdle: return "t0sbsIdle"; | | 3994 | case t0sbsIdle: return "t0sbsIdle"; |
3993 | case t0sbsClockData: return "t0sbsClockData"; | | 3995 | case t0sbsClockData: return "t0sbsClockData"; |
3994 | case t0sbsWaitError: return "t0sbsWaitError"; | | 3996 | case t0sbsWaitError: return "t0sbsWaitError"; |
3995 | case t0sbsWaitResend: return "t0sbsWaitResend"; | | 3997 | case t0sbsWaitResend: return "t0sbsWaitResend"; |
3996 | case t0sbsWaitGuardTime: return "t0sbsWaitGuardTime"; | | 3998 | case t0sbsWaitGuardTime: return "t0sbsWaitGuardTime"; |
3997 | | | 3999 | |
3998 | | | 4000 | |
3999 | case gcT0RecvByte: return "gcT0RecvByte"; | | 4001 | case gcT0RecvByte: return "gcT0RecvByte"; |
4000 | case gcT0RecvByteErr: return "gcT0RecvByteErr"; | | 4002 | case gcT0RecvByteErr: return "gcT0RecvByteErr"; |
4001 | case gcT0SendByte: return "gcT0SendByte"; | | 4003 | case gcT0SendByte: return "gcT0SendByte"; |
4002 | case gcT0SendByteErr: return "gcT0SendByteErr"; | | 4004 | case gcT0SendByteErr: return "gcT0SendByteErr"; |
4003 | | | 4005 | |
4004 | | | 4006 | |
4005 | case crcStart: return "crcStart"; | | 4007 | case crcStart: return "crcStart"; |
4006 | case crcT2: return "crcT2"; | | 4008 | case crcT2: return "crcT2"; |
4007 | | | 4009 | |
4008 | | | 4010 | |
4009 | default: | | 4011 | default: |
4010 | printf("unknown case, %x\n",x); | | 4012 | printf("unknown case, %x\n",x); |
4011 | break; | | 4013 | break; |
4012 | } | | 4014 | } |
4013 | return "???"; | | 4015 | return "???"; |
4014 | } | | 4016 | } |
4015 | | | 4017 | |
4016 | #endif /* SCR_DEBUG */ | | 4018 | #endif /* SCR_DEBUG */ |
4017 | | | 4019 | |
4018 | | | 4020 | |
4019 | | | 4021 | |