Add FreeRTOS heap4 intro card
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include "heap4_common.h"
|
||||
|
||||
#define HEAP_BYTES 160U
|
||||
|
||||
static uint8_t heap_area[HEAP_BYTES + HEAP4_ALIGNMENT];
|
||||
static HeapBlock start;
|
||||
static HeapBlock *end_marker;
|
||||
|
||||
volatile size_t g_initial_free_size;
|
||||
volatile uintptr_t g_aligned_offset;
|
||||
volatile int g_end_is_last;
|
||||
|
||||
static void heap_init(void)
|
||||
{
|
||||
uintptr_t raw;
|
||||
uintptr_t aligned;
|
||||
size_t available;
|
||||
HeapBlock *first;
|
||||
|
||||
raw = (uintptr_t)&heap_area[0];
|
||||
aligned = heap4_align_address(raw);
|
||||
available = HEAP_BYTES - (size_t)(aligned - raw);
|
||||
available &= ~HEAP4_ALIGNMENT_MASK;
|
||||
|
||||
first = (HeapBlock *)aligned;
|
||||
end_marker = (HeapBlock *)(aligned + available - sizeof(HeapBlock));
|
||||
end_marker->next = 0;
|
||||
end_marker->size = 0U;
|
||||
|
||||
first->next = end_marker;
|
||||
first->size = (uint8_t *)end_marker - (uint8_t *)first;
|
||||
|
||||
start.next = first;
|
||||
start.size = 0U;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
heap_init();
|
||||
|
||||
g_aligned_offset = (uintptr_t)start.next - (uintptr_t)&heap_area[0];
|
||||
g_initial_free_size = start.next->size;
|
||||
g_end_is_last = (start.next->next == end_marker) && (end_marker->next == 0);
|
||||
|
||||
TRACE_PRINTF("offset=%u free=%u end_last=%d\n",
|
||||
(unsigned)g_aligned_offset, (unsigned)g_initial_free_size,
|
||||
g_end_is_last);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user