FreeCalypso > hg > freecalypso-reveng
comparison miscprog/pircalextr.c @ 218:b6a95d35fabc
pircalextr program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 28 May 2017 20:12:14 +0000 |
parents | |
children | e3bbb8cfbbc0 |
comparison
equal
deleted
inserted
replaced
217:7d7a4367ec28 | 218:b6a95d35fabc |
---|---|
1 /* | |
2 * This program extracts the RF calibration tables from a dump of Pirelli's | |
3 * factory sector and saves them in FreeCalypso ASCII format. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/file.h> | |
8 #include <sys/stat.h> | |
9 #include <stdio.h> | |
10 #include <stdint.h> | |
11 #include <endian.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
14 | |
15 u_char factbuf[0x2000]; | |
16 | |
17 read_factory_struct(filename) | |
18 char *filename; | |
19 { | |
20 int fd; | |
21 struct stat st; | |
22 | |
23 fd = open(filename, O_RDONLY); | |
24 if (fd < 0) { | |
25 perror(filename); | |
26 exit(1); | |
27 } | |
28 fstat(fd, &st); | |
29 if (!S_ISREG(st.st_mode)) { | |
30 fprintf(stderr, "error: %s is not a regular file\n", filename); | |
31 exit(1); | |
32 } | |
33 if (st.st_size != 0x10000) { | |
34 fprintf(stderr, | |
35 "error: %s is of the wrong size (64 KiB expected)\n", | |
36 filename); | |
37 exit(1); | |
38 } | |
39 read(fd, factbuf, sizeof factbuf); | |
40 close(fd); | |
41 return(0); | |
42 } | |
43 | |
44 unsigned | |
45 get_u32(bin) | |
46 u_char *bin; | |
47 { | |
48 return le32toh(*(uint32_t *)bin); | |
49 } | |
50 | |
51 unsigned | |
52 get_u16(bin) | |
53 u_char *bin; | |
54 { | |
55 return le16toh(*(uint16_t *)bin); | |
56 } | |
57 | |
58 get_s16(bin) | |
59 u_char *bin; | |
60 { | |
61 int i; | |
62 | |
63 i = le16toh(*(uint16_t *)bin); | |
64 if (i >= 32768) | |
65 i -= 65536; | |
66 return(i); | |
67 } | |
68 | |
69 void | |
70 write_tx_levels_table(bin, outf) | |
71 u_char *bin; | |
72 FILE *outf; | |
73 { | |
74 int i; | |
75 u_char *p = bin; | |
76 | |
77 fputs("rf_table tx-levels\n\n", outf); | |
78 fputs("# Fields in each entry: apc, ramp_index, chan_cal_index\n\n", | |
79 outf); | |
80 for (i = 0; i < 32; i++) { | |
81 fprintf(outf, "%5u %3u %3u\t# entry %d\n", | |
82 get_u16(p), p[2], p[3], i); | |
83 p += 4; | |
84 } | |
85 } | |
86 | |
87 void | |
88 write_tx_calchan_table(bin, outf) | |
89 u_char *bin; | |
90 FILE *outf; | |
91 { | |
92 int i, j; | |
93 u_char *p = bin; | |
94 | |
95 fputs("rf_table tx-calchan\n", outf); | |
96 for (i = 0; i < 4; i++) { | |
97 fprintf(outf, "\n# Channel calibration table %d:\n\n", i); | |
98 for (j = 0; j < 8; j++) { | |
99 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); | |
100 p += 4; | |
101 } | |
102 } | |
103 } | |
104 | |
105 void | |
106 write_rx_calchan_table(bin, outf) | |
107 u_char *bin; | |
108 FILE *outf; | |
109 { | |
110 int i; | |
111 u_char *p = bin; | |
112 | |
113 fputs("rf_table rx-calchan\n\n", outf); | |
114 for (i = 0; i < 10; i++) { | |
115 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); | |
116 p += 4; | |
117 } | |
118 } | |
119 | |
120 void | |
121 write_rx_agcparams_table(bin, outf) | |
122 u_char *bin; | |
123 FILE *outf; | |
124 { | |
125 fputs("rf_table rx-agc-params\n\n", outf); | |
126 fprintf(outf, "%5u\t# g_magic\n", get_u16(bin)); | |
127 fprintf(outf, "%5u\t# lna_att\n", get_u16(bin + 2)); | |
128 fprintf(outf, "%5u\t# lna_switch_thr_low\n", get_u16(bin + 4)); | |
129 fprintf(outf, "%5u\t# lna_switch_thr_high\n", get_u16(bin + 6)); | |
130 } | |
131 | |
132 struct calmap { | |
133 unsigned offset; | |
134 char *outfile; | |
135 void (*fmtfunc)(); | |
136 } pirelli_cal_map[] = { | |
137 {0x092C, "tx-levels.900", write_tx_levels_table}, | |
138 {0x09AD, "tx-calchan.900", write_tx_calchan_table}, | |
139 {0x0C2F, "tx-levels.1800", write_tx_levels_table}, | |
140 {0x0CB0, "tx-calchan.1800", write_tx_calchan_table}, | |
141 {0x0F32, "tx-levels.1900", write_tx_levels_table}, | |
142 {0x0FB3, "tx-calchan.1900", write_tx_calchan_table}, | |
143 {0x10AF, "rx-calchan.900", write_rx_calchan_table}, | |
144 {0x10D8, "rx-agcparams.900", write_rx_agcparams_table}, | |
145 {0x10E1, "rx-calchan.1800", write_rx_calchan_table}, | |
146 {0x110A, "rx-agcparams.1800", write_rx_agcparams_table}, | |
147 {0x1113, "rx-calchan.1900", write_rx_calchan_table}, | |
148 {0x113C, "rx-agcparams.1900", write_rx_agcparams_table}, | |
149 {0, 0, 0} | |
150 }; | |
151 | |
152 main(argc, argv) | |
153 char **argv; | |
154 { | |
155 struct calmap *tp; | |
156 FILE *of; | |
157 | |
158 if (argc != 2) { | |
159 fprintf(stderr, "usage: %s fact.bin\n", argv[0]); | |
160 exit(1); | |
161 } | |
162 read_factory_struct(argv[1]); | |
163 for (tp = pirelli_cal_map; tp->outfile; tp++) { | |
164 of = fopen(tp->outfile, "w"); | |
165 if (!of) { | |
166 perror(tp->outfile); | |
167 exit(1); | |
168 } | |
169 tp->fmtfunc(factbuf + tp->offset, of); | |
170 fclose(of); | |
171 } | |
172 exit(0); | |
173 } |