From 31ea74f515a01ab0ed6ab775030bc0ac5b977b48 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sat, 2 Oct 2021 11:13:52 -0300 Subject: [PATCH] Start moving MM from local to kernel Co-authored-by: Juan Barmasch Co-authored-by: Ezequiel Bellver --- Kernel/memManagerBuddy.c | 6 ++++- Kernel/memManagerFRT2.c | 51 ++++++++++------------------------------ 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/Kernel/memManagerBuddy.c b/Kernel/memManagerBuddy.c index 58a099f..695ff44 100644 --- a/Kernel/memManagerBuddy.c +++ b/Kernel/memManagerBuddy.c @@ -22,7 +22,11 @@ typedef struct meta { unsigned char size : 6; // ______00 - n where (2^n)-1 is the block size } Meta; -static char myblock[MANAGED_MEMORY_SIZE]; +// static char myblock[MANAGED_MEMORY_SIZE]; +static char *myblock; +void initMemoryManager(void * managedMemory) { + myblock = managedMemory; +} void unpack(Meta * m, int pos); diff --git a/Kernel/memManagerFRT2.c b/Kernel/memManagerFRT2.c index d20112c..c4ce5b6 100644 --- a/Kernel/memManagerFRT2.c +++ b/Kernel/memManagerFRT2.c @@ -1,25 +1,10 @@ -/* - * A sample implementation of pvPortMalloc() and vPortFree() that permits - * allocated blocks to be freed, but does not combine adjacent free blocks - * into a single larger block (and so will fragment memory). See heap_4.c for - * an equivalent that does combine adjacent blocks into single larger blocks. - * - * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the - * memory management pages of http://www.FreeRTOS.org for more information. - */ #include #include #include #include -/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining -all the API functions to use the MPU wrappers. That should only be done when -task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE -// #include "FreeRTOS.h" -// #include "task.h" - #define portCHAR char #define portFLOAT float #define portDOUBLE double @@ -32,7 +17,6 @@ typedef portSTACK_TYPE StackType_t; typedef long BaseType_t; typedef unsigned long UBaseType_t; -/* Memory allocation related definitions. */ #define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 1 #define configTOTAL_HEAP_SIZE 1024 @@ -43,38 +27,27 @@ typedef unsigned long UBaseType_t; #define pdTRUE ( ( BaseType_t ) 1 ) #define portPOINTER_SIZE_TYPE uint32_t -/* -#ifndef configHEAP_ALLOCATION_SCHEME -#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) - #warning The configHEAP_ALLOCATION_SCHEME is not defined in FreeRTOSConfig -#endif -#else -#if(configHEAP_ALLOCATION_SCHEME == HEAP_ALLOCATION_TYPE2) - -#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) - #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 -#endif -*/ - /* A few bytes might be lost to byte aligning the heap start address. */ #define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) /* * Initialises the heap structures before their first use. */ -static void prvHeapInit( void ); +static void prvHeapInit(void); /* Allocate the memory for the heap. */ -#if( configAPPLICATION_ALLOCATED_HEAP == 1 ) - /* The application writer has already defined the array used for the RTOS - heap - probably so it can be placed in a special segment or address. */ - extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; -#else - static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; -#endif /* configAPPLICATION_ALLOCATED_HEAP */ +// #if( configAPPLICATION_ALLOCATED_HEAP == 1 ) +// /* The application writer has already defined the array used for the RTOS +// heap - probably so it can be placed in a special segment or address. */ +// extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +// #else +// static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +// #endif /* configAPPLICATION_ALLOCATED_HEAP */ +static uint8_t *ucHeap; +void initMemoryManager(void * managedMemory) { + ucHeap = managedMemory; +} /* Define the linked list structure. This is used to link free blocks in order of their size. */