A truly modular keyboard
C
sim: fix the suite's failure count, print the bus speed really used
Nathanc82a1b269895
diff --git a/firmware/sim/kw.c b/firmware/sim/kw.cindex 6c46147..572f4b2 100644--- a/firmware/sim/kw.c+++ b/firmware/sim/kw.c@@ -175,8 +175,11 @@ HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *h, uint16_t addr, uint16_return HAL_OK;}+static unsigned top_khz; /* fastest clock the Keyword has used */void sim_i2c_timing(uint32_t t){+ unsigned khz = 2000u / ((t & 0xFF) + 1);+ if (khz > top_khz) top_khz = khz;T_SDADEL = (int64_t)((t >> 16) & 0xF) * 250 * PS_NS;kw_t_low = (int64_t)((t & 0xFF) + 1) * 250 * PS_NS;kw_t_high = (int64_t)(((t >> 8) & 0xFF) + 1) * 250 * PS_NS;@@ -313,6 +316,7 @@ void kw_main(void)}unsigned kw_bus_khz(void) { return fast_steps[fb.step]; }+unsigned kw_top_khz(void) { unsigned k = top_khz; top_khz = 0; return k; }int kw_present(uint32_t uid){diff --git a/firmware/sim/node.c b/firmware/sim/node.cindex 0565d67..8de79c4 100644--- a/firmware/sim/node.c+++ b/firmware/sim/node.c@@ -8,7 +8,13 @@* The status stream works out an event's CRC while the Keyword is clocking* the read, which is where this matters. CRC_CYCLES overrides it. */#include <stdlib.h>-uint8_t link_crc8_real(uint8_t crc, uint8_t v);+/* v10's link.c keeps its CRC to itself and main.c never calls one. */+__attribute__((weak)) uint8_t link_crc8_real(uint8_t crc, uint8_t v)+{+ crc ^= v;+ for (int i = 0; i < 8; i++) crc = (uint8_t)(crc & 0x80 ? (crc << 1) ^ 0x07 : crc << 1);+ return crc;+}uint8_t link_crc8(uint8_t crc, uint8_t v){static int cycles = -1;diff --git a/firmware/sim/sim.c b/firmware/sim/sim.cindex b74cf0b..f5fefe7 100644--- a/firmware/sim/sim.c+++ b/firmware/sim/sim.c@@ -775,8 +775,8 @@ static void settle(const char *name)static void finish(void){- extern unsigned kw_bus_khz(void);- printf(" fast bus at %u kHz by the end%s\n", kw_bus_khz(), glitches ? "" : "");+ extern unsigned kw_bus_khz(void), kw_top_khz(void);+ printf(" bus up to %u kHz, fast step %u kHz by the end\n", kw_top_khz(), kw_bus_khz());if (glitches) printf(" %ld glitches injected\n", glitches);print_diag();printf(" shorts=%ld fights=%ld kb1 main loop pass %.1f us\n", shorts, fights,@@ -992,6 +992,7 @@ int main(int argc, char **argv)if (!all && strcmp(sc, suite[i])) continue;pid_t pid = all ? fork() : 0; /* each scenario in its own process: the Keyword keeps state */if (pid == 0) {+ fails = 0; /* a forked scenario starts with the parent's count */if (i == 0) sc_chain(len, np);if (i == 1) sc_turns(len, np);if (i == 2) sc_square(np);