FreeCalypso > hg > freecalypso-tools
comparison ffstools/caltools/fc-rftab2c.c @ 439:f4a32c1025a2
fc-rftab2c program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 17 Nov 2018 02:15:07 +0000 |
parents | |
children | 5bcf12be0834 |
comparison
equal
deleted
inserted
replaced
438:2ba7512efae5 | 439:f4a32c1025a2 |
---|---|
1 /* | |
2 * This utility reads an RF parameter table of one of the supported types | |
3 * in FreeCalypso ASCII format (it has to be one of the tables that go | |
4 * into the T_RF_BAND structure) and converts it into a C code snippet | |
5 * suitable for insertion into the firmware source in the L1 RF "customization" | |
6 * code where compiled-in default RF parameter tables are defined. | |
7 * | |
8 * This tool is primarily intended for use with tx-ramps tables and maybe | |
9 * tx-levels, but it also supports tx-calchan, tx-caltemp, rx-agc-params, | |
10 * rx-calchan and rx-caltemp tables. | |
11 * | |
12 * This program is based on the calextract tool from 2014 (freecalypso-reveng | |
13 * repository) and the generated C code snippets feature the same style, | |
14 * indentation and comments. | |
15 */ | |
16 | |
17 #include <sys/types.h> | |
18 #include <stdio.h> | |
19 #include <stdint.h> | |
20 #include <endian.h> | |
21 #include <stdlib.h> | |
22 | |
23 u_char binbuf[512]; | |
24 | |
25 static unsigned | |
26 get_u16(bin) | |
27 u_char *bin; | |
28 { | |
29 return le16toh(*(uint16_t *)bin); | |
30 } | |
31 | |
32 static int | |
33 get_s16(bin) | |
34 u_char *bin; | |
35 { | |
36 int i; | |
37 | |
38 i = le16toh(*(uint16_t *)bin); | |
39 if (i >= 32768) | |
40 i -= 65536; | |
41 return(i); | |
42 } | |
43 | |
44 void | |
45 do_rx_cal_params() | |
46 { | |
47 u_char *bp = binbuf; | |
48 int i; | |
49 | |
50 puts(" { /* T_RX_CAL_PARAMS */"); | |
51 for (i = 0; i < 4; i++) { | |
52 printf("%10u,\n", get_u16(bp)); | |
53 bp += 2; | |
54 } | |
55 puts(" },"); | |
56 } | |
57 | |
58 void | |
59 do_rx_agc_bands() | |
60 { | |
61 u_char *bp = binbuf; | |
62 int i, s; | |
63 unsigned u; | |
64 | |
65 puts(" { /* T_RF_AGC_BANDs */"); | |
66 for (i = 0; i < 10; i++) { | |
67 u = get_u16(bp); | |
68 bp += 2; | |
69 s = get_s16(bp); | |
70 bp += 2; | |
71 printf(" {%5u,%6d},\n", u, s); | |
72 } | |
73 puts(" },"); | |
74 } | |
75 | |
76 void | |
77 do_rx_temp_comp() | |
78 { | |
79 u_char *bp = binbuf; | |
80 int i, s1, s2; | |
81 | |
82 puts(" { /* Rx temperature compensation */"); | |
83 for (i = 0; i < 11; i++) { | |
84 s1 = get_s16(bp); | |
85 bp += 2; | |
86 s2 = get_s16(bp); | |
87 bp += 2; | |
88 printf(" {%6d,%6d},\n", s1, s2); | |
89 } | |
90 puts(" },"); | |
91 } | |
92 | |
93 void | |
94 do_tx_levels() | |
95 { | |
96 u_char *bp = binbuf; | |
97 unsigned i, u, b1, b2; | |
98 | |
99 puts(" { /* levels */"); | |
100 for (i = 0; i < 32; i++) { | |
101 u = get_u16(bp); | |
102 bp += 2; | |
103 b1 = *bp++; | |
104 b2 = *bp++; | |
105 printf(" {%5u,%3u,%3u}, /* %u */\n", u, b1, b2, i); | |
106 } | |
107 puts(" },"); | |
108 } | |
109 | |
110 void | |
111 do_tx_calchan() | |
112 { | |
113 u_char *bp = binbuf; | |
114 int i, j, s; | |
115 unsigned u; | |
116 | |
117 puts(" { /* channel calibration tables */"); | |
118 for (i = 0; i < 4; i++) { | |
119 printf(" { /* calibration table %d */\n", i); | |
120 for (j = 0; j < 8; j++) { | |
121 u = get_u16(bp); | |
122 bp += 2; | |
123 s = get_s16(bp); | |
124 bp += 2; | |
125 printf("\t{%5u,%6d},\n", u, s); | |
126 } | |
127 puts(" },"); | |
128 } | |
129 puts(" },"); | |
130 } | |
131 | |
132 static void | |
133 do_ramp_16bytes(bin) | |
134 u_char *bin; | |
135 { | |
136 u_char *bp = bin; | |
137 int i, b; | |
138 | |
139 putchar('\t'); | |
140 putchar('{'); | |
141 for (i = 0; i < 16; i++) { | |
142 b = *bp++; | |
143 printf("%3d%c", b, i == 15 ? '}' : ','); | |
144 } | |
145 putchar(','); | |
146 putchar('\n'); | |
147 } | |
148 | |
149 void | |
150 do_tx_ramps() | |
151 { | |
152 u_char *bp = binbuf; | |
153 int i; | |
154 | |
155 puts(" { /* ramps */"); | |
156 for (i = 0; i < 16; i++) { | |
157 printf(" { /* profile %d */\n", i); | |
158 puts("\t/* ramp-up */"); | |
159 do_ramp_16bytes(bp); | |
160 bp += 16; | |
161 puts("\t/* ramp-down */"); | |
162 do_ramp_16bytes(bp); | |
163 bp += 16; | |
164 puts(" },"); | |
165 } | |
166 puts(" },"); | |
167 } | |
168 | |
169 void | |
170 do_tx_temp_comp() | |
171 { | |
172 u_char *bp = binbuf; | |
173 int i, j, s[4]; | |
174 | |
175 puts(" { /* Tx temperature compensation */"); | |
176 for (i = 0; i < 5; i++) { | |
177 for (j = 0; j < 4; j++) { | |
178 s[j] = get_s16(bp); | |
179 bp += 2; | |
180 } | |
181 printf(" {%6d,%6d,%6d,%6d},\n", s[0], s[1], s[2], s[3]); | |
182 } | |
183 puts(" },"); | |
184 } | |
185 | |
186 static struct map { | |
187 char *format; | |
188 void (*func)(); | |
189 } map_table[] = { | |
190 {"tx-ramps", do_tx_ramps}, | |
191 {"tx-levels", do_tx_levels}, | |
192 {"tx-calchan", do_tx_calchan}, | |
193 {"tx-caltemp", do_tx_temp_comp}, | |
194 {"rx-calchan", do_rx_agc_bands}, | |
195 {"rx-caltemp", do_rx_temp_comp}, | |
196 {"rx-agc-params", do_rx_cal_params}, | |
197 {0, 0} | |
198 }; | |
199 | |
200 main(argc, argv) | |
201 char **argv; | |
202 { | |
203 char *format; | |
204 struct map *map; | |
205 | |
206 if (argc < 2 || argc > 3) { | |
207 fprintf(stderr, "usage: %s ascii-rftab-file [C-output-file]\n", | |
208 argv[0]); | |
209 exit(1); | |
210 } | |
211 if (read_rf_table_ext(argv[1], binbuf, 1, &format, 0)) | |
212 exit(1); | |
213 for (map = map_table; map->format; map++) | |
214 if (!strcmp(map->format, format)) | |
215 break; | |
216 if (!map->func) { | |
217 printf("error: %s tables are not supported\n", format); | |
218 exit(1); | |
219 } | |
220 if (argc >= 3 && !freopen(argv[2], "w", stdout)) { | |
221 perror(argv[2]); | |
222 exit(1); | |
223 } | |
224 map->func(); | |
225 exit(0); | |
226 } |