annotate target-utils/simagent/simup.c @ 780:8a94593fb7ef

simagent: Tx delays reduced in spenh mode
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Mar 2021 19:53:07 +0000
parents 6ec781e61e68
children badc5399d641
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <strings.h>
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include "types.h"
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include "abbdefs.h"
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include "simregs.h"
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
6 #include "timeout.h"
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
7
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
8 #define MAX_ATR_BYTES 33
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #define WAIT_ONE_TDMA 60000
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern u16 abb_reg_read();
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern void abb_reg_write();
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
15 extern const u8 inverse_coding_table[256];
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
16
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int sim_if_state;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u16 conf1_reg;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
19 u8 atr_buf[MAX_ATR_BYTES];
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
20 unsigned atr_length;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
21 int inverse_coding;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
22
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
23 void
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
24 print_atr()
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
25 {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
26 unsigned n;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
27
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
28 printf("ATR:");
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
29 for (n = 0; n < atr_length; n++)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
30 printf(" %02X", atr_buf[n]);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
31 putchar('\n');
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
32 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
33
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
34 static
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
35 rx_atr_byte()
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
36 {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
37 int rc;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
38
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
39 rc = rx_sim_byte(SIM_WAIT_TIMEOUT);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
40 if (rc < 0) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
41 printf("ERROR: timeout waiting for subsequent byte of ATR\n");
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
42 return(-1);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
43 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
44 rc &= 0xFF;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
45 if (inverse_coding)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
46 rc = inverse_coding_table[rc];
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
47 atr_buf[atr_length++] = rc;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
48 return rc;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
49 }
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 void
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 cmd_sim_up(argbulk)
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 char *argbulk;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 char *argv[2];
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 u16 abb_sim_reg;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
57 unsigned count, y, nhist, have_tck;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
58 int rc;
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (sim_if_state) {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 printf("ERROR: SIM interface is already up\n");
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!strcmp(argv[0], "1.8"))
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 abb_sim_reg = 2;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 else if (!strcmp(argv[0], "3"))
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 abb_sim_reg = 3;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 else {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 printf("ERROR: \"1.8\" or \"3\" argument expected\n");
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 abb_reg_write(VRPCSIM, abb_sim_reg);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 sim_if_state = 1;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 /* wait for regulator like TI's SIM_StartVolt() */
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (count = 0; ; ) {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 abb_sim_reg = abb_reg_read(VRPCSIM);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (abb_sim_reg & 4)
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 break;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (++count >= 5) {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 printf("ERROR: VRSIM is not in proper regulation\n");
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 /* TI's SIM_ManualStart() code follows */
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 SIMREGS.conf1 = conf1_reg = 0x8004;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 SIMREGS.cmd = SIM_CMD_CLKEN;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 SIMREGS.cmd = SIM_CMD_CLKEN | SIM_CMD_STOP;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 wait_ARM_cycles(WAIT_ONE_TDMA * 4);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 SIMREGS.cmd = SIM_CMD_CLKEN | SIM_CMD_SWRST;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 SIMREGS.conf2 = 0x0940;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 //enter in manual mode to start the ATR sequence
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_BYPASS;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SVCCLEV;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 abb_sim_reg |= 8;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 abb_reg_write(VRPCSIM, abb_sim_reg);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_SIOLOW;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 wait_ARM_cycles(WAIT_ONE_TDMA);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SCLKEN;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_TXRX; //set to receive mode
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 wait_ARM_cycles(WAIT_ONE_TDMA * 3);
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 /* flush any garbage in the Rx FIFO */
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 for (count = 0; ; ) {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (SIMREGS.stat & SIM_STAT_FEMPTY)
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 break;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 (void) SIMREGS.drx;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (++count >= 32) {
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 printf("ERROR: Rx FIFO flush does not end\n");
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return;
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 /* lift the card out of reset! */
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SRSTLEV;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
131
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
132 /* first byte of ATR */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
133 rc = rx_sim_byte(SIM_WAIT_TIMEOUT);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
134 if (rc < 0) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
135 printf("ERROR: timeout waiting for first byte of ATR\n");
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
136 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
137 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
138 rc &= 0xFF;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
139 if (rc == 0x3B) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
140 /* direct convention */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
141 inverse_coding = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
142 atr_buf[0] = 0x3B;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
143 } else if (rc == 0x03) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
144 /* inverse convention */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
145 inverse_coding = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
146 atr_buf[0] = 0x3F;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
147 } else {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
148 printf(
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
149 "ERROR: received TS=0x%02X, matches neither convention\n",
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
150 rc);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
151 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
152 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
153 atr_length = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
154
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
155 /* remainder of ATR, starting with T0 */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
156 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
157 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
158 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
159 nhist = rc & 0xF;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
160 y = rc & 0xF0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
161 have_tck = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
162 while (y) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
163 if (y & 0x10) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
164 if (atr_length >= MAX_ATR_BYTES) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
165 atr_too_long: printf("ERROR: ATR exceeds 33 byte limit\n");
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
166 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
167 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
168 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
169 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
170 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
171 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
172 if (y & 0x20) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
173 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
174 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
175 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
176 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
177 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
178 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
179 if (y & 0x40) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
180 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
181 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
182 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
183 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
184 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
185 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
186 if (y & 0x80) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
187 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
188 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
189 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
190 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
191 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
192 y = rc & 0xF0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
193 if (rc & 0x0F)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
194 have_tck = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
195 } else
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
196 y = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
197 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
198 for (count = 0; count < nhist + have_tck; count++) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
199 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
200 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
201 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
202 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
203 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
204 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
205
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
206 /* all good! */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
207 sim_if_state = 2;
775
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
208 if (inverse_coding)
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
209 conf1_reg |= SIM_CONF1_CONV | SIM_CONF1_CHKPAR;
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
210 else
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
211 conf1_reg |= SIM_CONF1_CHKPAR;
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
212 SIMREGS.conf1 = conf1_reg;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
213 print_atr();
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }