annotate gsm-fw/bsp/sim32.c @ 753:7f68d2ab0d33

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