aboutsummaryrefslogtreecommitdiff
path: root/02-usart/include
diff options
context:
space:
mode:
Diffstat (limited to '02-usart/include')
-rw-r--r--02-usart/include/arch/arm/arch.h3
-rw-r--r--02-usart/include/arch/x86_64/arch.h6
-rw-r--r--02-usart/include/mem.h23
3 files changed, 32 insertions, 0 deletions
diff --git a/02-usart/include/arch/arm/arch.h b/02-usart/include/arch/arm/arch.h
index 569ca77..f140c97 100644
--- a/02-usart/include/arch/arm/arch.h
+++ b/02-usart/include/arch/arm/arch.h
@@ -33,4 +33,7 @@
_Static_assert(sizeof(void*) == sizeof(uint32_t), "Pointers must be 32 bits");
#endif
+extern uint32_t DATA_SEGMENT_START;
+extern uint32_t DATA_SEGMENT_STOP;
+
#endif /* ARCH_H_ */
diff --git a/02-usart/include/arch/x86_64/arch.h b/02-usart/include/arch/x86_64/arch.h
index 258214e..accc449 100644
--- a/02-usart/include/arch/x86_64/arch.h
+++ b/02-usart/include/arch/x86_64/arch.h
@@ -24,4 +24,10 @@
#define SYSTEM_CONFIG_BLOCK_BASE (load_fake_scb__())
#define NVIC_BASE (load_fake_nvic__())
+// Pretend there's a data segement at the start of SRAM1 for more accurate
+// testing.
+#define GHOST_DATA_SEGMENT_SIZE 1234
+#define DATA_SEGMENT_START SRAM1_BASE
+#define DATA_SEGMENT_STOP (SRAM1_BASE + GHOST_DATA_SEGMENT_SIZE)
+
#endif /* ARCH_H_ */
diff --git a/02-usart/include/mem.h b/02-usart/include/mem.h
index aa4ce12..f376e7d 100644
--- a/02-usart/include/mem.h
+++ b/02-usart/include/mem.h
@@ -1,4 +1,27 @@
#ifndef MEM_H_
#define MEM_H_
+#include "arch.h"
+#include <stddef.h>
+
+#define MAX_HEAP_SIZE \
+ ((16384 - (DATA_SEGMENT_STOP - DATA_SEGMENT_START)) / 4 * 4)
+
+/* allocates memory on the head, which is stored in sram2 */
+void* halloc(size_t n);
+
+/* Frees the memory allocated by halloc. */
+void hfree(void* mem);
+
+#ifdef FOR_TESTING
+
+void* debug_halloc_get_next_ptr(void* ptr);
+
+void* debug_halloc_get_prev_ptr(void* ptr);
+
+int debug_halloc_assert_consistency(char* error, size_t len);
+
+#endif
+
+
#endif