Skip to content

Commit

Permalink
Fix state loads
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Dec 18, 2024
1 parent ad848c7 commit 211b750
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 18 deletions.
4 changes: 3 additions & 1 deletion include/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef enum {
#define OP_INVALID_SIZE return MEMREG_RESULT_INVALID_SIZE
#endif

#define OP_IGNORE_LOAD_DATA if ((op) == OP_LOAD_DATA) { return MEMREG_RESULT_OK; }

#define OP_ASSERT_SIZE(op, size) if ((op) != OP_READ_##size && (op) != OP_WRITE_##size) { OP_INVALID_SIZE; }
#define OP_ASSERT_READ(op) if ((op) < 0) { OP_INVALID_ACCESS; }
#define OP_ASSERT_WRITE(op) if ((op) > 0) { OP_INVALID_ACCESS; }
Expand Down Expand Up @@ -90,11 +92,11 @@ typedef struct memory_map_t memory_map_t;

memory_map_t *memory_map_new();
void memory_map_free(memory_map_t *);
void memory_map_reset(memory_map_t *);
void memory_map_add_region(memory_map_t *, memreg_t *region);
memreg_t *memory_map_get_region(memory_map_t *, uint32_t addr);

void memory_map_do_operation(memory_map_t *, uint32_t addr, memreg_op_t op, uint32_t *value);
void memory_map_do_operation_all(memory_map_t *, memreg_op_t op);
uint32_t memory_map_find_data(memory_map_t *map, uint32_t start_addr, uint32_t search_length, const uint8_t *data, size_t data_size);

inline static uint32_t memory_map_read(memory_map_t *map, uint32_t addr)
Expand Down
6 changes: 3 additions & 3 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void memory_map_free(memory_map_t *map)
assert(false); // TODO: Implement
}

void memory_map_reset(memory_map_t *map)
void memory_map_do_operation_all(memory_map_t *map, memreg_op_t op)
{
for (size_t i = 0; i < BUCKET_COUNT(1); i++)
{
Expand All @@ -191,7 +191,7 @@ void memory_map_reset(memory_map_t *map)
membucket_t *bucket = &map->buckets[i][j];

for (size_t k = 0; k < bucket->regions_count; k++)
memreg_reset(bucket->regions[k]);
bucket->regions[k]->operation(0, 0, NULL, op, bucket->regions[k]->userdata);
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ void memory_map_do_operation(memory_map_t *map, uint32_t addr, memreg_op_t op, u
}
}

if (handled || op == OP_LOAD_DATA) // OP_LOAD_DATA is optional
if (handled)
return;

switch (result)
Expand Down
4 changes: 2 additions & 2 deletions src/nrf52832.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void nrf52832_reset(NRF52832_t *nrf52832)
{
nrf52832->cycle_counter = 0;

memory_map_reset(nrf52832->mem);
memory_map_do_operation_all(nrf52832->mem, OP_RESET);
pins_reset(nrf52832->pins);
bus_spi_reset(nrf52832->bus_spi);
i2c_reset(nrf52832->bus_i2c);
Expand Down Expand Up @@ -259,5 +259,5 @@ uint64_t nrf52832_get_cycle_counter(NRF52832_t *nrf)

void nrf52832_reload_state(NRF52832_t *nrf)
{
memory_map_do_operation(nrf->mem, 0, OP_LOAD_DATA, NULL);
memory_map_do_operation_all(nrf->mem, OP_LOAD_DATA);
}
1 change: 1 addition & 0 deletions src/peripherals/dcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ OPERATION(dcb)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/dwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OPERATION(dwt)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OPERATION(ccm)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

return MEMREG_RESULT_OK;
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ OPERATION(clock)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OPERATION(comp)
if (op == OP_RESET)
return MEMREG_RESULT_OK;

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

// COMP_t *comp = (COMP_t *)userdata;
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/ecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ OPERATION(ecb)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ OPERATION(gpio)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

// PIN_CNF[n]
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/gpiote.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ OPERATION(gpiote)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
23 changes: 12 additions & 11 deletions src/peripherals/nrf52832/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ OPERATION(power)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
{
case 0x400: // RESETREAS
if (OP_IS_READ(op))
*value = power->resetreason;
else
power->resetreason &= ~*value;

return MEMREG_RESULT_OK;
case 0x578: // DCDCEN
// Do nothing
return MEMREG_RESULT_OK;
case 0x400: // RESETREAS
if (OP_IS_READ(op))
*value = power->resetreason;
else
power->resetreason &= ~*value;

return MEMREG_RESULT_OK;

case 0x578: // DCDCEN
// Do nothing
return MEMREG_RESULT_OK;
}

return MEMREG_RESULT_UNHANDLED;
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/ppi.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ OPERATION(ppi)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ OPERATION(radio)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA //TODO: Implement
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ OPERATION(rng)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

switch (offset)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OPERATION(saadc)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

// TODO: Implement
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ OPERATION(temp)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

if (offset >= 0x520 && offset <= 0x534)
Expand Down
1 change: 1 addition & 0 deletions src/peripherals/nrf52832/wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OPERATION(wdt)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA
OP_ASSERT_SIZE(op, WORD);

// TODO: Make watchdog do something
Expand Down
2 changes: 2 additions & 0 deletions src/peripherals/nvic.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ OPERATION(nvic)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA

// NVIC_ISER[n] and NVIC_ICER[n]
if (offset <= 0x40 || (offset >= 0x80 && offset <= 0xBC))
{
Expand Down
4 changes: 3 additions & 1 deletion src/peripherals/scb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ OPERATION(scb)
return MEMREG_RESULT_OK;
}

OP_IGNORE_LOAD_DATA

switch (offset)
{
case 0x00: // CPUID
Expand All @@ -44,7 +46,7 @@ OPERATION(scb)

*value = 0x410FC241; // ARM Cortex-M4
return MEMREG_RESULT_OK;

case 0x04: // ICSR
OP_ASSERT_SIZE(op, WORD);

Expand Down

0 comments on commit 211b750

Please sign in to comment.