aboutsummaryrefslogtreecommitdiffstats
path: root/src/pru
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-07-19 23:10:08 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-07-20 10:44:31 -0400
commit649d26e093497991ebc1a89f4a5cfeb29d4602d4 (patch)
tree7efde06f1f198198f1497ceb4b1db1a00ae4690a /src/pru
parent2ee42997e4b8ac4d8ca84cc53ecc9859baafbbbd (diff)
downloadkutter-649d26e093497991ebc1a89f4a5cfeb29d4602d4.tar.gz
kutter-649d26e093497991ebc1a89f4a5cfeb29d4602d4.tar.xz
kutter-649d26e093497991ebc1a89f4a5cfeb29d4602d4.zip
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 <kevin@koconnor.net>
Diffstat (limited to 'src/pru')
-rw-r--r--src/pru/main.c34
1 files changed, 9 insertions, 25 deletions
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 <stdint.h> // uint32_t
-#include <string.h> // memset
#include <pru/io.h> // read_r31
#include <pru_iep.h> // CT_IEP
#include <pru_intc.h> // CT_INTC
#include <rsc_types.h> // 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);
}