From 058c283919424ef8b4425cdf74739535dd1d8072 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 1 Jan 2018 17:40:28 -0500 Subject: heap; multitasking --- heap.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 heap.c (limited to 'heap.c') diff --git a/heap.c b/heap.c new file mode 100644 index 0000000..0433a1f --- /dev/null +++ b/heap.c @@ -0,0 +1,38 @@ +#include +#include + +#define RAM_END 0x20018000 + +//extern void *end; +//extern uint32_t _total_ram; +static uint32_t offset = 0; + +__attribute__ ((section(".data"))) +uint8_t heap[8192]; +void *end = heap; + +void heap_init(void) +{ + // what to do... +} + +uint32_t heap_available(void) +{ + return 0;// return _total_ram - offset; +} + +void *hmalloc(uint32_t size) +{ + void *alloc = end + offset; + offset += size; + return alloc; +} + +void *hcalloc(uint32_t count, uint32_t size) +{ + uint32_t total = count * size; + void *alloc = hmalloc(total); + for (uint32_t i = 0; i < total; i++) + ((uint8_t *)alloc)[i] = 0; + return alloc; +} -- cgit v1.2.3