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