Add needed changes to firmware for simulation.

This commit is contained in:
Jonas Thörnblad 2024-11-25 15:37:19 +01:00 committed by Daniel Jobson
parent fe9055ea23
commit 15ce2c438b
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A

View File

@ -54,7 +54,9 @@ static enum state loading_commands(const struct frame_header *hdr,
const uint8_t *cmd, enum state state, const uint8_t *cmd, enum state state,
struct context *ctx); struct context *ctx);
static void run(const struct context *ctx); static void run(const struct context *ctx);
#if !defined(SIMULATION)
static uint32_t xorwow(uint32_t state, uint32_t acc); static uint32_t xorwow(uint32_t state, uint32_t acc);
#endif
static void scramble_ram(void); static void scramble_ram(void);
static void print_hw_version(void) static void print_hw_version(void)
@ -364,6 +366,7 @@ static void run(const struct context *ctx)
__builtin_unreachable(); __builtin_unreachable();
} }
#if !defined(SIMULATION)
static uint32_t xorwow(uint32_t state, uint32_t acc) static uint32_t xorwow(uint32_t state, uint32_t acc)
{ {
state ^= state << 13; state ^= state << 13;
@ -372,9 +375,13 @@ static uint32_t xorwow(uint32_t state, uint32_t acc)
state += acc; state += acc;
return state; return state;
} }
#endif
static void scramble_ram(void) 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); uint32_t *ram = (uint32_t *)(TK1_RAM_BASE);
// Fill RAM with random data // Fill RAM with random data
@ -386,6 +393,7 @@ static void scramble_ram(void)
data_state = xorwow(data_state, data_acc); data_state = xorwow(data_state, data_acc);
ram[w] = data_state; ram[w] = data_state;
} }
#endif
// Set RAM address and data scrambling parameters // Set RAM address and data scrambling parameters
*ram_addr_rand = rnd_word(); *ram_addr_rand = rnd_word();
@ -414,6 +422,10 @@ int main(void)
scramble_ram(); scramble_ram();
#if defined(SIMULATION)
run(&ctx);
#endif
for (;;) { for (;;) {
switch (state) { switch (state) {
case FW_STATE_INITIAL: case FW_STATE_INITIAL: