FreeCalypso > hg > freecalypso-reveng
annotate pircharge/abb.c @ 233:4cd01d1458df
pirelli/fw-disasm: main and init modules located
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 21 Dec 2017 23:12:46 +0000 |
parents | 84a4f6ef2d28 |
children |
rev | line source |
---|---|
229
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <rvinterf/pktmux.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <rvinterf/limits.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <rvinterf/localsock.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <rvinterf/localtypes.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <rvinterf/etm.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <rvinterf/exitcodes.h> |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern u_char rvi_msg[]; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int rvi_msg_len; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int adccal_a, adccal_b; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 struct abbtab { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *name; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int regno; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int special; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } abbtab[] = { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 {"VBAT", 15, 2}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 {"ICHG", 17, 1}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 {"CHGREG", 25, 0}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 {"BCICTL1", 28, 0}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 {"BCICTL2", 29, 0}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 {"BCICONF", 32+13, 0}, |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 {0, 0, 0} |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 }; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int abbr_in_progress, abbr_index; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 void |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 issue_abbr() |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 u_char cmdpkt[5]; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 int i, c; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 cmdpkt[0] = RVT_TM_HEADER; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 cmdpkt[1] = ETM_CORE; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 cmdpkt[2] = TMCORE_OPC_CODEC_RD; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 cmdpkt[3] = abbtab[abbr_index].regno; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 c = 0; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (i = 1; i <= 3; i++) |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 c ^= cmdpkt[i]; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 cmdpkt[i] = c; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 send_pkt_to_target(cmdpkt, 5); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 void |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 adc_end_process() |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (abbr_in_progress) |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 abbr_in_progress = 1; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 abbr_index = 0; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 issue_abbr(); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 void |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 etm_packet_rx() |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 int i, c; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 unsigned val; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (rvi_msg_len != 9) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 printf("Received TM packet of wrong length\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 c = 0; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (i = 2; i < rvi_msg_len; i++) |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 c ^= rvi_msg[i]; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (c) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 printf("Received TM packet with bad checksum\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (rvi_msg[2] != ETM_CORE) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 printf("Received TM packet that isn't ETM_CORE\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (rvi_msg[4] != TMCORE_OPC_CODEC_RD) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 printf("Received ETM_CORE packet that isn't abbr response\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (rvi_msg[3]) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 printf("abbr response has error code %02X\n", rvi_msg[3]); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (!abbr_in_progress) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 printf("abbr response with no abbr in progress\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (rvi_msg[5] != abbtab[abbr_index].regno) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 printf("abbr response for the wrong register\n"); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 abbr_in_progress = 0; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 return; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 val = rvi_msg[6] | rvi_msg[7] << 8; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 printf("%s=%03X", abbtab[abbr_index].name, val); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 switch (abbtab[abbr_index].special) { |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 case 2: |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 val = (val * adccal_a) >> 10; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 val += adccal_b; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 /* FALL THRU */ |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 case 1: |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 printf(" (%u)", val); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 putchar('\n'); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 abbr_index++; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if (abbtab[abbr_index].name) |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 issue_abbr(); |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 else |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 abbr_in_progress = 0; |
84a4f6ef2d28
pirchgdbg: complete enough for first test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |