Skip to content

Commit

Permalink
Enable static idle task
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnycase committed Feb 14, 2019
1 parent 2fb7143 commit 68b5563
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 49 deletions.
5 changes: 3 additions & 2 deletions lib/freertos/conf/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0

/* memory */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 20480 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 1024 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1024 * 1024 ) )
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
Expand All @@ -109,7 +109,7 @@ enum

/* Software timer definitions. */
#define configUSE_TIMERS 0
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_TASK_PRIORITY ( 0 )
#define configTIMER_QUEUE_LENGTH 2
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )

Expand All @@ -128,6 +128,7 @@ enum
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerPendFunctionCall 0

#define INCLUDE_xSemaphoreGetMutexHolder 1

Expand Down
27 changes: 23 additions & 4 deletions lib/freertos/os_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ typedef struct
extern void __libc_init_array(void);
extern void __libc_fini_array(void);

static StaticTask_t s_idle_task;
static StackType_t s_idle_task_stack[configMINIMAL_STACK_SIZE];
static StaticTask_t s_idle_task[portNUM_PROCESSORS];
static StackType_t s_idle_task_stack[portNUM_PROCESSORS][configMINIMAL_STACK_SIZE];
static StaticTask_t s_timer_task[portNUM_PROCESSORS];
static StackType_t s_timer_task_stack[portNUM_PROCESSORS][configMINIMAL_STACK_SIZE];

void start_scheduler(int core_id);

Expand Down Expand Up @@ -91,19 +93,36 @@ void vApplicationIdleHook(void)

void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
{
UBaseType_t uxPsrId = uxPortGetProcessorId();
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */
*ppxIdleTaskTCBBuffer = &s_idle_task;
*ppxIdleTaskTCBBuffer = &s_idle_task[uxPsrId];

/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = s_idle_task_stack;
*ppxIdleTaskStackBuffer = s_idle_task_stack[uxPsrId];

/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}

void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize)
{
UBaseType_t uxPsrId = uxPortGetProcessorId();
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */
*ppxTimerTaskTCBBuffer = &s_timer_task[uxPsrId];

/* Pass out the array that will be used as the Idle task's stack. */
*ppxTimerTaskStackBuffer = s_timer_task_stack[uxPsrId];

/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
{
configASSERT(!"Stackoverflow !");
Expand Down
5 changes: 3 additions & 2 deletions lib/freertos/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ BaseType_t xReturn;
UBaseType_t uxPsrId = uxPortGetProcessorId();

/* Add the idle task at the lowest priority. */
#if( configSUPPORT_STATIC_ALLOCATION == 1 && 0)
#if( configSUPPORT_STATIC_ALLOCATION == 1)
{
StaticTask_t *pxIdleTaskTCBBuffer = NULL;
StackType_t *pxIdleTaskStackBuffer = NULL;
Expand Down Expand Up @@ -3033,6 +3033,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xIte
void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely )
{
configASSERT( pxEventList );
UBaseType_t uxPsrId = uxPortGetProcessorId();

/* This function should not be called by application code hence the
'Restricted' in its name. It is not part of the public API. It is
Expand All @@ -3044,7 +3045,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xIte
In this case it is assume that this is the only task that is going to
be waiting on this event list, so the faster vListInsertEnd() function
can be used in place of vListInsert. */
vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );
vListInsertEnd( pxEventList, &( pxCurrentTCB[uxPsrId]->xEventListItem ) );

/* If the task should block indefinitely then set the block time to a
value that will be recognised as an indefinite delay inside the
Expand Down

0 comments on commit 68b5563

Please sign in to comment.