annotate target-utils/simagent/simup.c @ 975:343552c6c621

doc/Loadtools-usage: add SE J120
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 28 Nov 2023 19:08:53 +0000
parents badc5399d641
children
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 */
782
badc5399d641 simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 775
diff changeset
120 rc = flush_rx_fifo();
badc5399d641 simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 775
diff changeset
121 if (rc < 0)
badc5399d641 simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 775
diff changeset
122 return;
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 /* lift the card out of reset! */
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SRSTLEV;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
125
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
126 /* first byte of ATR */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
127 rc = rx_sim_byte(SIM_WAIT_TIMEOUT);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
128 if (rc < 0) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
129 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
130 return;
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 rc &= 0xFF;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
133 if (rc == 0x3B) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
134 /* direct convention */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
135 inverse_coding = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
136 atr_buf[0] = 0x3B;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
137 } else if (rc == 0x03) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
138 /* inverse convention */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
139 inverse_coding = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
140 atr_buf[0] = 0x3F;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
141 } else {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
142 printf(
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
143 "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
144 rc);
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
145 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
146 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
147 atr_length = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
148
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
149 /* remainder of ATR, starting with T0 */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
150 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
151 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
152 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
153 nhist = rc & 0xF;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
154 y = rc & 0xF0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
155 have_tck = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
156 while (y) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
157 if (y & 0x10) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
158 if (atr_length >= MAX_ATR_BYTES) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
159 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
160 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
161 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
162 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
163 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
164 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
165 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
166 if (y & 0x20) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
167 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
168 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
169 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
170 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
171 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
172 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
173 if (y & 0x40) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
174 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
175 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
176 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
177 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
178 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
179 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
180 if (y & 0x80) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
181 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
182 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
183 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
184 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
185 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
186 y = rc & 0xF0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
187 if (rc & 0x0F)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
188 have_tck = 1;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
189 } else
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
190 y = 0;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
191 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
192 for (count = 0; count < nhist + have_tck; count++) {
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
193 if (atr_length >= MAX_ATR_BYTES)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
194 goto atr_too_long;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
195 rc = rx_atr_byte();
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
196 if (rc < 0)
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
197 return;
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
198 }
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
199
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
200 /* all good! */
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
201 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
202 if (inverse_coding)
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
203 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
204 else
6ec781e61e68 simagent: enable CHKPAR and CONV at the end of sim-up
Mychaela Falconia <falcon@freecalypso.org>
parents: 774
diff changeset
205 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
206 SIMREGS.conf1 = conf1_reg;
774
130c46b83760 simagent: sim-up command fully implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 770
diff changeset
207 print_atr();
770
81f9e4b4f55c simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }