From 469c623bb8e504ca78f1964508579ecefec76a98 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Jun 2016 13:01:16 +0100 Subject: [PATCH] cc3200: Shrink the FreeRTOS heap and place TCB+stack in freed location. The 16k FreeRTOS heap originally had all TCBs and stacks dynamically allocated within it (plus semaphores and some other things). Now that xTaskCreateStatic is used instead of xTaskCreate, the TCBs and stacks are allocated statically and no longer use any of the FreeRTOS heap. Therefore, the FreeRTOS stack can be shrunk by the amount that has been made static. Furthermore, the TCBs and stack that are now static should be placed in the .rtos_heaps section of RAM because this RAM is treated specially by the bootloader (the bootloader executes from the first 16k of RAM and loads the firmware into the section starting after the 16k). After this patch the FreeRTOS heap (ucHeap) is 7200 bytes. The memory available for the MicroPython heap is 54936 bytes (including GC overhead). --- cc3200/FreeRTOS/FreeRTOSConfig.h | 8 +++++++- cc3200/main.c | 11 ++++++----- cc3200/serverstask.c | 7 +++++-- cc3200/simplelink/oslib/osi_freertos.c | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cc3200/FreeRTOS/FreeRTOSConfig.h b/cc3200/FreeRTOS/FreeRTOSConfig.h index c0d50d0c1d..2f25bbd7e8 100644 --- a/cc3200/FreeRTOS/FreeRTOSConfig.h +++ b/cc3200/FreeRTOS/FreeRTOSConfig.h @@ -84,7 +84,13 @@ #define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 72 ) -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16384 ) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( \ + 16384 /* 16kbytes for FreeRTOS data structures and heap */ \ + - sizeof(StaticTask_t) - configMINIMAL_STACK_SIZE * sizeof(StackType_t) /* TCB+stack for idle task */ \ + - sizeof(StaticTask_t) - 1024 /* TCB+stack for servers task */ \ + - sizeof(StaticTask_t) - 6656 /* TCB+stack for main MicroPython task */ \ + - sizeof(StaticTask_t) - 896 /* TCB+stack for simplelink spawn task */ \ + ) ) #define configMAX_TASK_NAME_LEN ( 8 ) #define configUSE_TRACE_FACILITY 0 #define configUSE_16_BIT_TICKS 0 diff --git a/cc3200/main.c b/cc3200/main.c index da6c5211b2..06b3604b67 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -50,6 +50,10 @@ DECLARE PRIVATE DATA ******************************************************************************/ +// This is the static memory (TCB and stack) for the idle task +static StaticTask_t xIdleTaskTCB __attribute__ ((section (".rtos_heap"))); +static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8))); + /****************************************************************************** DECLARE PUBLIC DATA ******************************************************************************/ @@ -61,8 +65,8 @@ OsiTaskHandle mpTaskHandle; uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8))); // This is the static memory (TCB and stack) for the main MicroPython task -StaticTask_t mpTaskTCB; -StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__((aligned (8))); +StaticTask_t mpTaskTCB __attribute__ ((section (".rtos_heap"))); +StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8))); /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -105,9 +109,6 @@ void stoupper (char *str) { void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) { - static StaticTask_t xIdleTaskTCB; - static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; - *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; *ppxIdleTaskStackBuffer = uxIdleTaskStack; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; diff --git a/cc3200/serverstask.c b/cc3200/serverstask.c index 8bac3a756a..1305afda0b 100644 --- a/cc3200/serverstask.c +++ b/cc3200/serverstask.c @@ -67,8 +67,11 @@ static volatile bool sleep_sockets = false; /****************************************************************************** DECLARE PUBLIC DATA ******************************************************************************/ -StaticTask_t svTaskTCB; -StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__((aligned (8))); + +// This is the static memory (TCB and stack) for the servers task +StaticTask_t svTaskTCB __attribute__ ((section (".rtos_heap"))); +StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8))); + char servers_user[SERVERS_USER_PASS_LEN_MAX + 1]; char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1]; diff --git a/cc3200/simplelink/oslib/osi_freertos.c b/cc3200/simplelink/oslib/osi_freertos.c index 90acc2e979..53822add73 100644 --- a/cc3200/simplelink/oslib/osi_freertos.c +++ b/cc3200/simplelink/oslib/osi_freertos.c @@ -62,8 +62,8 @@ TaskHandle_t xSimpleLinkSpawnTaskHndl = NULL; #define SL_SPAWN_MAX_WAIT_MS ( 200 ) // This is the static memory (TCB and stack) for the SL spawn task -static StaticTask_t spawnTaskTCB; -static portSTACK_TYPE spawnTaskStack[896 / sizeof(portSTACK_TYPE)] __attribute__((aligned (8))); +static StaticTask_t spawnTaskTCB __attribute__ ((section (".rtos_heap"))); +static portSTACK_TYPE spawnTaskStack[896 / sizeof(portSTACK_TYPE)] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8))); /*! \brief This function registers an interrupt in NVIC table