FreeCalypso > hg > fc-usbser-tools
view cp2102/decode_baudtab.c @ 70:09da7db45dce
doc/FTDI-EEPROM-format: document FT232R specifics
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 24 Sep 2023 21:31:37 +0000 |
parents | 672c7adc8bc9 |
children |
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); dp += SIZE_BAUDRATE_CFG; 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); } }