aboutsummaryrefslogtreecommitdiff
path: root/02-usart/test_harness/fake_env.c
blob: 31753174cc33676c8e5d081fbb00c662cecd72de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "fake_env.h"

#include <stdlib.h>
#include <assert.h>

#define DEFINE_MEMORY_SEGMENT(name, start_addr, end_addr) \
  static void* fake_##name = NULL; \
  void* load_fake_##name##__ () \
  { \
    if (fake_##name == NULL) { \
      fake_##name = malloc((end_addr) - (start_addr)); \
      assert(fake_##name != NULL); \
    } \
    return fake_##name; \
  }

/* 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)