Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
sysmem.c
Go to the documentation of this file.
1
23/* Includes */
24#include <errno.h>
25#include <stdint.h>
26
30static uint8_t *__sbrk_heap_end = NULL;
31
53void *_sbrk(ptrdiff_t incr)
54{
55 extern uint8_t _end; /* Symbol defined in the linker script */
56 extern uint8_t _estack; /* Symbol defined in the linker script */
57 extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
58 const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
59 const uint8_t *max_heap = (uint8_t *)stack_limit;
60 uint8_t *prev_heap_end;
61
62 /* Initialize heap end at first call */
63 if (NULL == __sbrk_heap_end)
64 {
65 __sbrk_heap_end = &_end;
66 }
67
68 /* Protect heap from growing into the reserved MSP stack */
69 if (__sbrk_heap_end + incr > max_heap)
70 {
71 errno = ENOMEM;
72 return (void *)-1;
73 }
74
75 prev_heap_end = __sbrk_heap_end;
76 __sbrk_heap_end += incr;
77
78 return (void *)prev_heap_end;
79}
static uint8_t * __sbrk_heap_end
Definition: sysmem.c:30
void * _sbrk(ptrdiff_t incr)
_sbrk() allocates memory to the newlib heap and is used by malloc and others from the C library
Definition: sysmem.c:53