diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 13:46:41 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 13:46:41 -0700 |
commit | 93b063fedfcf7409a67df035170ea5670cad22e1 (patch) | |
tree | a23321a7465d966b1ccf196ca00e65a70c9f9110 /test_harness/fake_env.c | |
parent | b040195d31df6ad759f16ea3456471897f55daa1 (diff) | |
download | stm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.tar.gz stm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.tar.bz2 stm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.zip |
Moved action to top level.
Removed old iterations of the project and moved the files from 02-usart
to the root directory since that's the sole place where the action is
and that subproject has outgrown its initial title.
Diffstat (limited to 'test_harness/fake_env.c')
-rw-r--r-- | test_harness/fake_env.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test_harness/fake_env.c b/test_harness/fake_env.c new file mode 100644 index 0000000..6a32c99 --- /dev/null +++ b/test_harness/fake_env.c @@ -0,0 +1,63 @@ +#include "fake_env.h" + +#include <stdlib.h> +#include <assert.h> + +struct fakeenv_memseg { + const char* name; + void* segment; +}; + +#define DEFINE_MEMORY_SEGMENT(seg, start_addr, end_addr) \ + static __attribute((__section__("fakeenv"))) \ + struct fakeenv_memseg fake_##seg = { \ + .name = #seg, \ + .segment = NULL, \ + }; \ + void* load_fake_##seg##__ () \ + { \ + if (fake_##seg .segment == NULL) { \ + fake_##seg .segment = malloc((end_addr) - (start_addr)); \ + assert(fake_##seg .segment != NULL); \ + } \ + return fake_##seg.segment; \ + } + +extern struct fakeenv_memseg __start_fakeenv; +extern struct fakeenv_memseg __stop_fakeenv; + +void wipeout_fake_env() +{ + for (struct fakeenv_memseg* iter = &__start_fakeenv; + iter < &__stop_fakeenv; + ++ iter) { + free(iter->segment); + iter->segment = NULL; + } +} + +/* Reset and clock control. */ +DEFINE_MEMORY_SEGMENT(rcc, 0x40021000, 0x400210A0) + +/* Peripheral buses */ +DEFINE_MEMORY_SEGMENT(apb1, 0x40000000, 0x40010000) +DEFINE_MEMORY_SEGMENT(apb2, 0x40010000, 0x40020000) +DEFINE_MEMORY_SEGMENT(ahb1, 0x40020000, 0x40024400) +DEFINE_MEMORY_SEGMENT(ahb2, 0x48000000, 0x50060C00) + +/* System Control Block */ +DEFINE_MEMORY_SEGMENT(scb, 0xE000E008, 0xE000EF04) + +/* Nested Vector Interrupt Controller (NVIC) */ +/* Note that this memory space acutally overlaps with the SCB, but + * they are functionally distinct entitites and such are modeled as + * separate structures in memeory. */ +DEFINE_MEMORY_SEGMENT(nvic, 0xE000E004, 0xE000E4F0) + +/* SRAM */ +DEFINE_MEMORY_SEGMENT(sram1, 0x20000000, 0x2000C000) +DEFINE_MEMORY_SEGMENT(sram2, 0x2000C000, 0x20018000) + +/* Serial Peripheral Interface */ +DEFINE_MEMORY_SEGMENT(spi1, 0x40013000, 0x400133FF) +DEFINE_MEMORY_SEGMENT(spi3, 0x40003C00, 0x40003FFF) |