From 15ce2c438b7ca78b55e9f9a633f6de60bda51d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Th=C3=B6rnblad?= Date: Mon, 25 Nov 2024 15:37:19 +0100 Subject: [PATCH] Add needed changes to firmware for simulation. --- hw/application_fpga/fw/tk1/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index 524b0dc..fc50c4b 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -54,7 +54,9 @@ static enum state loading_commands(const struct frame_header *hdr, const uint8_t *cmd, enum state state, struct context *ctx); static void run(const struct context *ctx); +#if !defined(SIMULATION) static uint32_t xorwow(uint32_t state, uint32_t acc); +#endif static void scramble_ram(void); static void print_hw_version(void) @@ -364,6 +366,7 @@ static void run(const struct context *ctx) __builtin_unreachable(); } +#if !defined(SIMULATION) static uint32_t xorwow(uint32_t state, uint32_t acc) { state ^= state << 13; @@ -372,9 +375,13 @@ static uint32_t xorwow(uint32_t state, uint32_t acc) state += acc; return state; } +#endif static void scramble_ram(void) { + // Can't fill RAM if we are simulating, data has already been loaded + // into RAM. +#if !defined(SIMULATION) uint32_t *ram = (uint32_t *)(TK1_RAM_BASE); // Fill RAM with random data @@ -386,6 +393,7 @@ static void scramble_ram(void) data_state = xorwow(data_state, data_acc); ram[w] = data_state; } +#endif // Set RAM address and data scrambling parameters *ram_addr_rand = rnd_word(); @@ -414,6 +422,10 @@ int main(void) scramble_ram(); +#if defined(SIMULATION) + run(&ctx); +#endif + for (;;) { switch (state) { case FW_STATE_INITIAL: