FreeCalypso > hg > fc-usbser-tools
view 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 |
line wrap: on
line source
/* * The function implemented in this module decodes the baud rate table * contained in the captured CP2102 EEPROM image. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include "cp210x_defs.h" extern u_char eeprom[SIZE_EEPROM]; void decode_baud_table(outf) FILE *outf; { unsigned entry; u_char *dp; unsigned baudrate, baudgen, timegen, prescaler, sparebyte; unsigned baud_div, calc_baud, time_us; dp = eeprom; for (entry = 0; entry < SIZE_BAUDRATES; entry++) { baudgen = (dp[0] << 8) | dp[1]; timegen = (dp[2] << 8) | dp[3]; prescaler = dp[4]; sparebyte = dp[5]; baudrate = dp[6] | (dp[7] << 8) | (dp[8] << 16) | (dp[9] << 24); fprintf(outf, "baud-entry %2u: %7u = %04X, %04X, %u, %u", entry, baudrate, baudgen, timegen, prescaler, sparebyte); if (prescaler) { baud_div = (0x10000 - baudgen) * prescaler; calc_baud = 24000000 / baud_div; fprintf(outf, "\t# %u baud, ", calc_baud); time_us = (0x10000 - timegen) * 2; if (time_us >= 1000) fprintf(outf, "%u.%03u ms", time_us / 1000, time_us % 1000); else fprintf(outf, "%u us", time_us); } putc('\n', outf); } }