FreeCalypso > hg > leo2moko-debug
comparison chipsetsw/drivers/drv_app/sim/sim32.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /* | |
2 * SIM32.C | |
3 * | |
4 * Pole Star SIM | |
5 * | |
6 * Target : ARM | |
7 * | |
8 * Copyright (c) Texas Instruments 1995 | |
9 * | |
10 */ | |
11 | |
12 #define SIM32_C 1 | |
13 | |
14 #include "chipset.cfg" | |
15 | |
16 #include "main/sys_types.h" | |
17 #include <assert.h> | |
18 #include "inth/iq.h" | |
19 #include "sim.h" | |
20 | |
21 | |
22 #ifdef SIM_DEBUG_TRACE | |
23 /* working buffer for NULL BYTE */ | |
24 extern SYS_UWORD8 SIM_dbg_null[]; | |
25 /* Nucleus variable given the current number of TDMA frames */ | |
26 extern SYS_UWORD32 IQ_FrameCount; | |
27 /* working variable to calculate the TDMA ecart */ | |
28 extern SYS_UWORD16 SIM_dbg_tdma_diff; | |
29 /* working variable storing the current number of TDMA frames elapsed */ | |
30 SYS_UWORD32 SIM_dbg_local_count; | |
31 #endif | |
32 | |
33 /* | |
34 * SIM_IntHandler | |
35 * | |
36 * Read cause of SIM interrupt : | |
37 * | |
38 * if receive buffer full, read char | |
39 * if transmitter empty, change direction, transmit a dummy char | |
40 * | |
41 */ | |
42 void SIM_IntHandler(void) | |
43 { | |
44 volatile unsigned short it, i, stat, conf1; | |
45 volatile SYS_UWORD8 ins; | |
46 volatile SYS_UWORD8 rx; | |
47 volatile SYS_UWORD8 nack; | |
48 volatile SYS_UWORD8 nack1; | |
49 | |
50 | |
51 SIM_PORT *p; | |
52 | |
53 p = &(Sim[0]); | |
54 | |
55 p->rxParityErr = 0; | |
56 it = p->c->it; | |
57 | |
58 if ((it & SIM_IT_ITRX) && !(p->c->maskit & SIM_MASK_RX)) // int on reception | |
59 { | |
60 stat = p->c->rx; | |
61 conf1 = p->conf1; | |
62 | |
63 #ifdef SIM_DEBUG_TRACE | |
64 if ((IQ_FrameCount - SIM_dbg_local_count) > SIM_dbg_tdma_diff) { | |
65 SIM_dbg_tdma_diff = IQ_FrameCount - SIM_dbg_local_count; | |
66 } | |
67 SIM_dbg_local_count = IQ_FrameCount; | |
68 #endif | |
69 | |
70 // Check if reception parity is enable | |
71 if (((conf1 & SIM_CONF1_CHKPAR) && ((stat & SIM_DRX_STATRXPAR) != 0))\ | |
72 || ((conf1 & SIM_CONF1_CHKPAR) == 0)) | |
73 { | |
74 rx = (SYS_UWORD8) (stat & 0x00FF); | |
75 ins = p->xbuf[1] & p->hw_mask; | |
76 nack = (~p->xbuf[1]) & p->hw_mask; | |
77 | |
78 switch (p->moderx) | |
79 { | |
80 case 0: //mode of normal reception without proc char (like PTS proc) | |
81 p->rbuf[p->rx_index++] = rx; | |
82 break; | |
83 | |
84 case 1: //mode wait for ACK | |
85 if ((rx & p->hw_mask) == ins) | |
86 { | |
87 p->moderx = 2; | |
88 } | |
89 else if ((rx & p->hw_mask) == nack) | |
90 { | |
91 p->moderx = 4; | |
92 } | |
93 else if (((rx & 0xF0) == 0x60) || ((rx & 0xF0) == 0x90)) | |
94 { | |
95 if (rx != 0x60) //in case of error code (SW1/SW2) returned by sim card | |
96 { | |
97 p->rSW12[p->SWcount++] = rx; | |
98 p->moderx = 5; | |
99 } | |
100 else | |
101 { | |
102 p->null_received = 1; | |
103 #ifdef SIM_DEBUG_TRACE | |
104 SIM_dbg_null[0]++; | |
105 #endif | |
106 } | |
107 } | |
108 else | |
109 { | |
110 p->errorSIM = SIM_ERR_ABNORMAL_CASE2; | |
111 } | |
112 //if rx = 0x60 wait for ACK | |
113 break; | |
114 | |
115 case 2: //mode reception by block | |
116 p->rbuf[p->rx_index++] = rx; | |
117 | |
118 if(p->expected_data == 256) | |
119 { | |
120 if (p->rx_index == 0) | |
121 { | |
122 p->moderx = 5; | |
123 } | |
124 } | |
125 else | |
126 { | |
127 if (p->rx_index == p->expected_data) | |
128 { | |
129 p->moderx = 5; | |
130 } | |
131 } | |
132 break; | |
133 | |
134 case 3: //mode reception char by char. reception of proc char | |
135 if ((rx & p->hw_mask) == ins) | |
136 { | |
137 p->moderx = 2; | |
138 } | |
139 else if ((rx & p->hw_mask) == nack) | |
140 { | |
141 p->moderx = 4; | |
142 } //if rx = 0x60 wait for ACK | |
143 else if (rx == 0x60) | |
144 { | |
145 p->null_received == 1; | |
146 #ifdef SIM_DEBUG_TRACE | |
147 SIM_dbg_null[1]++; | |
148 #endif | |
149 } | |
150 | |
151 break; | |
152 | |
153 case 4: //mode reception char by char. reception of data | |
154 p->rbuf[p->rx_index++] = rx; | |
155 p->moderx = 3; //switch to receive proc char mode | |
156 | |
157 if(p->expected_data == 256) | |
158 { | |
159 if (p->rx_index == 0) | |
160 { | |
161 p->moderx = 5; | |
162 } | |
163 } | |
164 else | |
165 { | |
166 if (p->rx_index == p->expected_data) | |
167 { | |
168 p->moderx = 5; | |
169 } | |
170 } | |
171 break; | |
172 | |
173 case 5: //mode wait for procedure character except NULL | |
174 if ((rx != 0x60) || (p->SWcount != 0)) //treat NULL character only if arriving before SW1 SW2 | |
175 { | |
176 p->rSW12[p->SWcount++] = rx; | |
177 } | |
178 else | |
179 { | |
180 p->null_received = 1; | |
181 #ifdef SIM_DEBUG_TRACE | |
182 SIM_dbg_null[2]++; | |
183 #endif | |
184 } | |
185 | |
186 | |
187 break; | |
188 | |
189 case 6: //give the acknowledge char | |
190 if (((rx & 0xF0) == 0x60) || ((rx & 0xF0) == 0x90)) | |
191 { | |
192 if (rx != 0x60) //in case of error code (SW1/SW2) returned by sim card | |
193 { | |
194 p->rSW12[p->SWcount++] = rx; | |
195 p->moderx = 5; | |
196 } | |
197 else | |
198 { | |
199 p->null_received = 1; | |
200 #ifdef SIM_DEBUG_TRACE | |
201 SIM_dbg_null[3]++; | |
202 #endif | |
203 } | |
204 } | |
205 else | |
206 { | |
207 p->ack = rx; | |
208 } | |
209 } | |
210 } | |
211 else | |
212 { | |
213 p->rxParityErr = 1; | |
214 } | |
215 } | |
216 | |
217 if ((it & SIM_IT_ITTX) && !(p->c->maskit & SIM_MASK_TX)) | |
218 { | |
219 #ifdef SIM_DEBUG_TRACE | |
220 SIM_dbg_local_count = IQ_FrameCount; | |
221 #endif | |
222 // check the transmit parity | |
223 stat = p->c->stat; | |
224 | |
225 | |
226 if ((stat & SIM_STAT_TXPAR) || ((p->conf1 & SIM_CONF1_CHKPAR) == 0)) //parity disable | |
227 { | |
228 if (p->xOut != (p->xIn - 1)) //if only one char transmitted (already transmitted) | |
229 { //just need to have confirmation of reception | |
230 if (p->xOut == (p->xIn - 2)) | |
231 { | |
232 p->xOut++; | |
233 p->c->tx = *(p->xOut); // transmit | |
234 | |
235 p->conf1 &= ~SIM_CONF1_TXRX; // return the direction | |
236 p->c->conf1 = p->conf1; | |
237 } | |
238 | |
239 if (p->xOut < (p->xIn - 2)) | |
240 { | |
241 p->xOut++; | |
242 p->c->tx = *(p->xOut); // transmit | |
243 } | |
244 } | |
245 } | |
246 else | |
247 { | |
248 p->c->tx = *(p->xOut); // transmit same char | |
249 p->txParityErr++; // count number of transmit parity errors | |
250 } | |
251 | |
252 } | |
253 | |
254 // Handle errors | |
255 if ((it & SIM_IT_ITOV) && !(p->c->maskit & SIM_MASK_OV)) | |
256 { | |
257 p->errorSIM = SIM_ERR_OVF; | |
258 | |
259 } | |
260 if ((it & SIM_IT_WT) && !(p->c->maskit & SIM_MASK_WT)) | |
261 { | |
262 p->errorSIM = SIM_ERR_READ; | |
263 } | |
264 | |
265 // Reset the card in case of NATR to let the program continue | |
266 if ((it & SIM_IT_NATR) && !(p->c->maskit & SIM_MASK_NATR)) | |
267 { | |
268 p->c->cmd = SIM_CMD_STOP; | |
269 p->errorSIM = SIM_ERR_NATR; | |
270 } | |
271 | |
272 #if ((CHIPSET == 2) || (CHIPSET == 3)) | |
273 // SIM card insertion / extraction | |
274 if ((it & SIM_IT_CD) && !(p->c->maskit & SIM_MASK_CD)) | |
275 { | |
276 stat = p->c->stat; | |
277 if ((stat & SIM_STAT_CD) != SIM_STAT_CD) | |
278 { | |
279 (p->RemoveFunc)(); | |
280 p->errorSIM = SIM_ERR_NOCARD; | |
281 } | |
282 } | |
283 #endif | |
284 } | |
285 | |
286 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) | |
287 /* | |
288 * SIM_CD_IntHandler | |
289 * | |
290 * Read cause of SIM interrupt : | |
291 * | |
292 */ | |
293 void SIM_CD_IntHandler(void) | |
294 { | |
295 volatile unsigned short it_cd, stat; | |
296 SIM_PORT *p; | |
297 | |
298 p = &(Sim[0]); | |
299 | |
300 p->rxParityErr = 0; | |
301 it_cd = p->c->it_cd; | |
302 | |
303 // SIM card insertion / extraction | |
304 if ((it_cd & SIM_IT_CD) && !(p->c->maskit & SIM_MASK_CD)) | |
305 { | |
306 stat = p->c->stat; | |
307 if ((stat & SIM_STAT_CD) != SIM_STAT_CD) | |
308 { | |
309 (p->RemoveFunc)(); | |
310 p->errorSIM = SIM_ERR_NOCARD; | |
311 } | |
312 } | |
313 } | |
314 #endif | |
315 | |
316 | |
317 // to force this module to be linked | |
318 SYS_UWORD16 SIM_Dummy(void) | |
319 { | |
320 | |
321 } |