FreeCalypso > hg > fc-usbser-tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 57:deba1d5c8024 | 58:4890ded06a8b |
|---|---|
| 1 /* | |
| 2 * The function implemented in this module decodes the baud rate table | |
| 3 * contained in the captured CP2102 EEPROM image. | |
| 4 */ | |
| 5 | |
| 6 #include <sys/types.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include "cp210x_defs.h" | |
| 10 | |
| 11 extern u_char eeprom[SIZE_EEPROM]; | |
| 12 | |
| 13 void | |
| 14 decode_baud_table(outf) | |
| 15 FILE *outf; | |
| 16 { | |
| 17 unsigned entry; | |
| 18 u_char *dp; | |
| 19 unsigned baudrate, baudgen, timegen, prescaler, sparebyte; | |
| 20 unsigned baud_div, calc_baud, time_us; | |
| 21 | |
| 22 dp = eeprom; | |
| 23 for (entry = 0; entry < SIZE_BAUDRATES; entry++) { | |
| 24 baudgen = (dp[0] << 8) | dp[1]; | |
| 25 timegen = (dp[2] << 8) | dp[3]; | |
| 26 prescaler = dp[4]; | |
| 27 sparebyte = dp[5]; | |
| 28 baudrate = dp[6] | (dp[7] << 8) | (dp[8] << 16) | (dp[9] << 24); | |
| 29 fprintf(outf, "baud-entry %2u: %7u = %04X, %04X, %u, %u", | |
| 30 entry, baudrate, baudgen, timegen, prescaler, | |
| 31 sparebyte); | |
| 32 if (prescaler) { | |
| 33 baud_div = (0x10000 - baudgen) * prescaler; | |
| 34 calc_baud = 24000000 / baud_div; | |
| 35 fprintf(outf, "\t# %u baud, ", calc_baud); | |
| 36 time_us = (0x10000 - timegen) * 2; | |
| 37 if (time_us >= 1000) | |
| 38 fprintf(outf, "%u.%03u ms", time_us / 1000, | |
| 39 time_us % 1000); | |
| 40 else | |
| 41 fprintf(outf, "%u us", time_us); | |
| 42 } | |
| 43 putc('\n', outf); | |
| 44 } | |
| 45 } |
