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.
This commit is contained in:
Damien George 2016-05-31 17:27:21 +01:00
parent 77e37ff98b
commit 0455755296
5 changed files with 29 additions and 18 deletions

View File

@ -36,6 +36,7 @@
#include "debug.h" #include "debug.h"
#include "antenna.h" #include "antenna.h"
#include "mperror.h" #include "mperror.h"
#include "task.h"
/****************************************************************************** /******************************************************************************
DECLARE PRIVATE CONSTANTS 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 // 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))); 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 DEFINE PUBLIC FUNCTIONS
******************************************************************************/ ******************************************************************************/
@ -77,15 +82,12 @@ int main (void) {
// Init the watchdog // Init the watchdog
pybwdt_init0(); pybwdt_init0();
#ifdef DEBUG #ifndef DEBUG
ASSERT (OSI_OK == osi_TaskCreate(TASK_Micropython, OsiTaskHandle mpTaskHandle;
(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));
#endif #endif
mpTaskHandle = xTaskCreateStatic(TASK_Micropython, "MicroPy",
MICROPY_TASK_STACK_LEN, NULL, MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB);
ASSERT(mpTaskHandle != NULL);
osi_start(); osi_start();

View File

@ -69,6 +69,7 @@
#include "updater.h" #include "updater.h"
#include "moduos.h" #include "moduos.h"
#include "antenna.h" #include "antenna.h"
#include "task.h"
/****************************************************************************** /******************************************************************************
DECLARE PRIVATE CONSTANTS DECLARE PRIVATE CONSTANTS
@ -277,15 +278,12 @@ STATIC void mptask_pre_init (void) {
//CRYPTOHASH_Init(); //CRYPTOHASH_Init();
#ifdef DEBUG #ifndef DEBUG
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers, OsiTaskHandle svTaskHandle;
(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));
#endif #endif
svTaskHandle = xTaskCreateStatic(TASK_Servers, "Servers",
SERVERS_STACK_LEN, NULL, SERVERS_PRIORITY, svTaskStack, &svTaskTCB);
ASSERT(svTaskHandle != NULL);
} }
STATIC void mptask_init_sflash_filesystem (void) { STATIC void mptask_init_sflash_filesystem (void) {

View File

@ -31,7 +31,13 @@
DEFINE CONSTANTS DEFINE CONSTANTS
******************************************************************************/ ******************************************************************************/
#define MICROPY_TASK_PRIORITY (2) #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 DECLARE PUBLIC FUNCTIONS

View File

@ -67,6 +67,8 @@ static volatile bool sleep_sockets = false;
/****************************************************************************** /******************************************************************************
DECLARE PUBLIC DATA 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_user[SERVERS_USER_PASS_LEN_MAX + 1];
char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1]; char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1];

View File

@ -31,7 +31,8 @@
DEFINE CONSTANTS DEFINE CONSTANTS
******************************************************************************/ ******************************************************************************/
#define SERVERS_PRIORITY 2 #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_SSID_LEN_MAX 16
#define SERVERS_KEY_LEN_MAX 16 #define SERVERS_KEY_LEN_MAX 16
@ -52,6 +53,8 @@
/****************************************************************************** /******************************************************************************
EXPORTED DATA EXPORTED DATA
******************************************************************************/ ******************************************************************************/
extern StaticTask_t svTaskTCB;
extern StackType_t svTaskStack[];
extern char servers_user[]; extern char servers_user[];
extern char servers_pass[]; extern char servers_pass[];