From 649d26e093497991ebc1a89f4a5cfeb29d4602d4 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 19 Jul 2017 23:10:08 -0400 Subject: basecmd: Move low-level alloc code into basecmd.c Implement new dynmem_start() and dynmem_end() functions instead of alloc_chunk() and alloc_chunks() in the board code. This simplifies the board code. Signed-off-by: Kevin O'Connor --- src/pru/main.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'src/pru') diff --git a/src/pru/main.c b/src/pru/main.c index 021bee3f..a95bde1b 100644 --- a/src/pru/main.c +++ b/src/pru/main.c @@ -5,12 +5,11 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include // uint32_t -#include // memset #include // read_r31 #include // CT_IEP #include // CT_INTC #include // resource_table -#include "board/misc.h" // alloc_chunk +#include "board/misc.h" // dynmem_start #include "board/io.h" // readl #include "board/irq.h" // irq_disable #include "command.h" // shutdown @@ -175,39 +174,24 @@ const struct command_parser shutdown_request = { /**************************************************************** - * Allocator + * Dynamic memory ****************************************************************/ -extern char _heap_start; -static void *heap_ptr = &_heap_start; - #define STACK_SIZE 256 -#define END_MEM ((void*)(8*1024 - STACK_SIZE)) -// Allocate an area of memory +// Return the start of memory available for dynamic allocations void * -alloc_chunk(size_t size) +dynmem_start(void) { - if (heap_ptr + size > END_MEM) - shutdown("alloc_chunk failed"); - void *data = heap_ptr; - heap_ptr += size; - memset(data, 0, size); - return data; + extern char _heap_start; + return &_heap_start; } -// Allocate an array of chunks +// Return the end of memory available for dynamic allocations void * -alloc_chunks(size_t size, size_t count, size_t *avail) +dynmem_end(void) { - size_t can_alloc = 0; - void *p = heap_ptr; - for (; can_alloc <= count && p + size <= END_MEM; can_alloc++, p += size) - ; - if (!can_alloc) - shutdown("alloc_chunks failed"); - *avail = can_alloc; - return alloc_chunk(size * can_alloc); + return (void*)(8*1024 - STACK_SIZE); } -- cgit v1.2.3-70-g09d2