annotate cp2102/decode_baudtab.c @ 104:866eae65dbea

LICENSE: same as other FreeCalypso tools
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 29 Sep 2023 18:20:04 +0000
parents 672c7adc8bc9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
59
672c7adc8bc9 cp2102-decode-baudtab: works after a little fix
Mychaela Falconia <falcon@freecalypso.org>
parents: 58
diff changeset
29 dp += SIZE_BAUDRATE_CFG;
58
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 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
31 entry, baudrate, baudgen, timegen, prescaler,
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sparebyte);
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (prescaler) {
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 baud_div = (0x10000 - baudgen) * prescaler;
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 calc_baud = 24000000 / baud_div;
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fprintf(outf, "\t# %u baud, ", calc_baud);
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 time_us = (0x10000 - timegen) * 2;
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (time_us >= 1000)
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fprintf(outf, "%u.%03u ms", time_us / 1000,
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 time_us % 1000);
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 else
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(outf, "%u us", time_us);
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 putc('\n', outf);
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
4890ded06a8b cp2102-decode-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }