diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2018-01-01 17:40:28 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2018-01-01 17:40:28 -0500 |
commit | 058c283919424ef8b4425cdf74739535dd1d8072 (patch) | |
tree | 7aa6c40d7c6aa1dad5b0fba24f22c22759fcab59 /heap.c | |
parent | de7c4fb07d1ac0298e7fc62000c35193e221aaae (diff) |
heap; multitasking
Diffstat (limited to 'heap.c')
-rw-r--r-- | heap.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +#include <heap.h> +#include <stm32l476xx.h> + +#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; +} |