FreeCalypso > hg > fc-usbser-tools
annotate cp2102/decode_baudtab.c @ 58:4890ded06a8b
cp2102-decode-baudtab program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 20:33:26 +0000 |
parents | |
children | 672c7adc8bc9 |
rev | line source |
---|---|
58
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function implemented in this module decodes the baud rate table |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * contained in the captured CP2102 EEPROM image. |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "cp210x_defs.h" |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern u_char eeprom[SIZE_EEPROM]; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 void |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 decode_baud_table(outf) |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 FILE *outf; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned entry; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char *dp; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unsigned baudrate, baudgen, timegen, prescaler, sparebyte; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned baud_div, calc_baud, time_us; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 dp = eeprom; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 for (entry = 0; entry < SIZE_BAUDRATES; entry++) { |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 baudgen = (dp[0] << 8) | dp[1]; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 timegen = (dp[2] << 8) | dp[3]; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 prescaler = dp[4]; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 sparebyte = dp[5]; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 baudrate = dp[6] | (dp[7] << 8) | (dp[8] << 16) | (dp[9] << 24); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fprintf(outf, "baud-entry %2u: %7u = %04X, %04X, %u, %u", |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 entry, baudrate, baudgen, timegen, prescaler, |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 sparebyte); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (prescaler) { |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 baud_div = (0x10000 - baudgen) * prescaler; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 calc_baud = 24000000 / baud_div; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(outf, "\t# %u baud, ", calc_baud); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 time_us = (0x10000 - timegen) * 2; |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (time_us >= 1000) |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 fprintf(outf, "%u.%03u ms", time_us / 1000, |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 time_us % 1000); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 else |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(outf, "%u us", time_us); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 putc('\n', outf); |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
4890ded06a8b
cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |