FreeCalypso > hg > freecalypso-tools
annotate target-utils/simagent/simup.c @ 770:81f9e4b4f55c
simagent: beginning of sim-up command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Mar 2021 20:11:39 +0000 |
parents | |
children | 130c46b83760 |
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" |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #define WAIT_ONE_TDMA 60000 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 extern u16 abb_reg_read(); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern void abb_reg_write(); |
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 int sim_if_state; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u16 conf1_reg; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 void |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 cmd_sim_up(argbulk) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char *argbulk; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *argv[2]; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u16 abb_sim_reg; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned count; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (sim_if_state) { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 printf("ERROR: SIM interface is already up\n"); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (parse_args(argbulk, 1, 1, argv, 0) < 0) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (!strcmp(argv[0], "1.8")) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 abb_sim_reg = 2; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 else if (!strcmp(argv[0], "3")) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 abb_sim_reg = 3; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 else { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 printf("ERROR: \"1.8\" or \"3\" argument expected\n"); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 abb_reg_write(VRPCSIM, abb_sim_reg); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 sim_if_state = 1; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* wait for regulator like TI's SIM_StartVolt() */ |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (count = 0; ; ) { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 abb_sim_reg = abb_reg_read(VRPCSIM); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (abb_sim_reg & 4) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 break; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (++count >= 5) { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 printf("ERROR: VRSIM is not in proper regulation\n"); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 wait_ARM_cycles(WAIT_ONE_TDMA); |
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 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 /* TI's SIM_ManualStart() code follows */ |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 SIMREGS.conf1 = conf1_reg = 0x8004; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 SIMREGS.cmd = SIM_CMD_CLKEN; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 SIMREGS.cmd = SIM_CMD_CLKEN | SIM_CMD_STOP; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 wait_ARM_cycles(WAIT_ONE_TDMA * 4); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 SIMREGS.cmd = SIM_CMD_CLKEN | SIM_CMD_SWRST; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 wait_ARM_cycles(WAIT_ONE_TDMA); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 SIMREGS.conf2 = 0x0940; |
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 //enter in manual mode to start the ATR sequence |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_BYPASS; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 wait_ARM_cycles(WAIT_ONE_TDMA); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SVCCLEV; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 wait_ARM_cycles(WAIT_ONE_TDMA); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 abb_sim_reg |= 8; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 abb_reg_write(VRPCSIM, abb_sim_reg); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 wait_ARM_cycles(WAIT_ONE_TDMA); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_SIOLOW; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 wait_ARM_cycles(WAIT_ONE_TDMA); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SCLKEN; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 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
|
80 wait_ARM_cycles(WAIT_ONE_TDMA * 3); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 /* flush any garbage in the Rx FIFO */ |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 for (count = 0; ; ) { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (SIMREGS.stat & SIM_STAT_FEMPTY) |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 break; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 (void) SIMREGS.drx; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (++count >= 32) { |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 printf("ERROR: Rx FIFO flush does not end\n"); |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
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 #if 0 |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 /* lift the card out of reset! */ |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_SRSTLEV; |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 #endif |
81f9e4b4f55c
simagent: beginning of sim-up command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |