From 0455755296b27440e68cad1ca43c342d9a452f88 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 31 May 2016 17:27:21 +0100 Subject: [PATCH] cc3200: Use xTaskCreateStatic instead of osi_TaskCreate. This allows to statically allocate the TCB (thread control block) and thread stack in the BSS segment, reducing the need for dynamic memory allocation. --- cc3200/main.c | 18 ++++++++++-------- cc3200/mptask.c | 14 ++++++-------- cc3200/mptask.h | 8 +++++++- cc3200/serverstask.c | 2 ++ cc3200/serverstask.h | 5 ++++- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/cc3200/main.c b/cc3200/main.c index 2aed70f76b..da6c5211b2 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -36,6 +36,7 @@ #include "debug.h" #include "antenna.h" #include "mperror.h" +#include "task.h" /****************************************************************************** DECLARE PRIVATE CONSTANTS @@ -59,6 +60,10 @@ OsiTaskHandle mpTaskHandle; // This is the FreeRTOS heap, defined here so we can put it in a special segment 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))); + /****************************************************************************** DEFINE PUBLIC FUNCTIONS ******************************************************************************/ @@ -77,15 +82,12 @@ int main (void) { // Init the watchdog pybwdt_init0(); -#ifdef DEBUG - ASSERT (OSI_OK == osi_TaskCreate(TASK_Micropython, - (const signed char *)"MicroPy", - MICROPY_TASK_STACK_SIZE, NULL, MICROPY_TASK_PRIORITY, &mpTaskHandle)); -#else - ASSERT (OSI_OK == osi_TaskCreate(TASK_Micropython, - (const signed char *)"MicroPy", - MICROPY_TASK_STACK_SIZE, NULL, MICROPY_TASK_PRIORITY, NULL)); +#ifndef DEBUG + OsiTaskHandle mpTaskHandle; #endif + mpTaskHandle = xTaskCreateStatic(TASK_Micropython, "MicroPy", + MICROPY_TASK_STACK_LEN, NULL, MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB); + ASSERT(mpTaskHandle != NULL); osi_start(); diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 828263c4a1..80d76f90e9 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -69,6 +69,7 @@ #include "updater.h" #include "moduos.h" #include "antenna.h" +#include "task.h" /****************************************************************************** DECLARE PRIVATE CONSTANTS @@ -277,15 +278,12 @@ STATIC void mptask_pre_init (void) { //CRYPTOHASH_Init(); -#ifdef DEBUG - ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers, - (const signed char *)"Servers", - SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle)); -#else - ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers, - (const signed char *)"Servers", - SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL)); +#ifndef DEBUG + OsiTaskHandle svTaskHandle; #endif + svTaskHandle = xTaskCreateStatic(TASK_Servers, "Servers", + SERVERS_STACK_LEN, NULL, SERVERS_PRIORITY, svTaskStack, &svTaskTCB); + ASSERT(svTaskHandle != NULL); } STATIC void mptask_init_sflash_filesystem (void) { diff --git a/cc3200/mptask.h b/cc3200/mptask.h index 6ac419b9d6..e0d2f0eec1 100644 --- a/cc3200/mptask.h +++ b/cc3200/mptask.h @@ -31,7 +31,13 @@ DEFINE CONSTANTS ******************************************************************************/ #define MICROPY_TASK_PRIORITY (2) -#define MICROPY_TASK_STACK_SIZE ((6 * 1024) + 512) +#define MICROPY_TASK_STACK_SIZE ((6 * 1024) + 512) // in bytes +#define MICROPY_TASK_STACK_LEN (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t)) + +/****************************************************************************** + EXPORTED DATA + ******************************************************************************/ +extern StackType_t mpTaskStack[]; /****************************************************************************** DECLARE PUBLIC FUNCTIONS diff --git a/cc3200/serverstask.c b/cc3200/serverstask.c index 82c43bf8e0..8bac3a756a 100644 --- a/cc3200/serverstask.c +++ b/cc3200/serverstask.c @@ -67,6 +67,8 @@ static volatile bool sleep_sockets = false; /****************************************************************************** DECLARE PUBLIC DATA ******************************************************************************/ +StaticTask_t svTaskTCB; +StackType_t svTaskStack[SERVERS_STACK_LEN] __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/serverstask.h b/cc3200/serverstask.h index 7689cf461b..2786ff6976 100644 --- a/cc3200/serverstask.h +++ b/cc3200/serverstask.h @@ -31,7 +31,8 @@ DEFINE CONSTANTS ******************************************************************************/ #define SERVERS_PRIORITY 2 -#define SERVERS_STACK_SIZE 1024 +#define SERVERS_STACK_SIZE 1024 // in bytes +#define SERVERS_STACK_LEN (SERVERS_STACK_SIZE / sizeof(StackType_t)) #define SERVERS_SSID_LEN_MAX 16 #define SERVERS_KEY_LEN_MAX 16 @@ -52,6 +53,8 @@ /****************************************************************************** EXPORTED DATA ******************************************************************************/ +extern StaticTask_t svTaskTCB; +extern StackType_t svTaskStack[]; extern char servers_user[]; extern char servers_pass[];