STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
tasks.c File Reference
#include <stdlib.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "stack_macros.h"
Include dependency graph for tasks.c:

Go to the source code of this file.

Classes

struct  tskTaskControlBlock

Macros

#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#define taskYIELD_IF_USING_PREEMPTION()
#define taskNOT_WAITING_NOTIFICATION   ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */
#define taskWAITING_NOTIFICATION   ( ( uint8_t ) 1 )
#define taskNOTIFICATION_RECEIVED   ( ( uint8_t ) 2 )
#define tskSTACK_FILL_BYTE   ( 0xa5U )
#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB   ( ( uint8_t ) 0 )
#define tskSTATICALLY_ALLOCATED_STACK_ONLY   ( ( uint8_t ) 1 )
#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB   ( ( uint8_t ) 2 )
#define tskSET_NEW_STACKS_TO_KNOWN_VALUE   0
#define tskRUNNING_CHAR   ( 'X' )
#define tskBLOCKED_CHAR   ( 'B' )
#define tskREADY_CHAR   ( 'R' )
#define tskDELETED_CHAR   ( 'D' )
#define tskSUSPENDED_CHAR   ( 'S' )
#define configIDLE_TASK_NAME   "IDLE"
#define taskRECORD_READY_PRIORITY(uxPriority)
#define taskSELECT_HIGHEST_PRIORITY_TASK()
#define taskRESET_READY_PRIORITY(uxPriority)
#define portRESET_READY_PRIORITY(uxPriority, uxTopReadyPriority)
#define taskSWITCH_DELAYED_LISTS()
#define prvAddTaskToReadyList(pxTCB)
#define prvGetTCBFromHandle(pxHandle)
#define taskEVENT_LIST_ITEM_VALUE_IN_USE   0x8000U

Typedefs

typedef struct tskTaskControlBlock tskTCB
typedef tskTCB TCB_t

Functions

static void prvInitialiseTaskLists (static void prvCheckTasksWaitingTermination void)
 Utility task that simply returns pdTRUE if the task referenced by xTask is currently in the Suspended state, or pdFALSE if the task referenced by xTask is in any other state.
static void prvAddNewTaskToReadyList (TCB_t *pxNewTCB)
void vTaskStartScheduler (void)
void vTaskEndScheduler (void)
void vTaskSuspendAll (void)
BaseType_t xTaskResumeAll (void)
TickType_t xTaskGetTickCount (void)
TickType_t xTaskGetTickCountFromISR (void)
UBaseType_t uxTaskGetNumberOfTasks (void)
char * pcTaskGetName (TaskHandle_t xTaskToQuery)
BaseType_t xTaskCatchUpTicks (TickType_t xTicksToCatchUp)
BaseType_t xTaskIncrementTick (void)
void vTaskSwitchContext (void)
void vTaskPlaceOnEventList (List_t *const pxEventList, const TickType_t xTicksToWait)
void vTaskPlaceOnUnorderedEventList (List_t *pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait)
BaseType_t xTaskRemoveFromEventList (const List_t *const pxEventList)
void vTaskRemoveFromUnorderedEventList (ListItem_t *pxEventListItem, const TickType_t xItemValue)
void vTaskSetTimeOutState (TimeOut_t *const pxTimeOut)
void vTaskInternalSetTimeOutState (TimeOut_t *const pxTimeOut)
BaseType_t xTaskCheckForTimeOut (TimeOut_t *const pxTimeOut, TickType_t *const pxTicksToWait)
void vTaskMissedYield (void)
static portTASK_FUNCTION (prvIdleTask, pvParameters)
static void prvInitialiseTaskLists (void)
static void prvCheckTasksWaitingTermination (void)
static void prvResetNextTaskUnblockTime (void)
TickType_t uxTaskResetEventItemValue (void)
static void prvAddCurrentTaskToDelayedList (TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely)

Variables

portDONT_DISCARD PRIVILEGED_DATA TCB_t *volatile pxCurrentTCB = NULL
static PRIVILEGED_DATA List_t pxReadyTasksLists [configMAX_PRIORITIES]
 Prioritised ready tasks.
static PRIVILEGED_DATA List_t xDelayedTaskList1
 Delayed tasks.
static PRIVILEGED_DATA List_t xDelayedTaskList2
 Delayed tasks (two lists are used - one for delays that have overflowed the current tick count.
static PRIVILEGED_DATA List_t *volatile pxDelayedTaskList
 Points to the delayed task list currently being used.
static PRIVILEGED_DATA List_t *volatile pxOverflowDelayedTaskList
 Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count.
static PRIVILEGED_DATA List_t xPendingReadyList
 Tasks that have been readied while the scheduler was suspended.
static PRIVILEGED_DATA volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U
static PRIVILEGED_DATA volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT
static PRIVILEGED_DATA volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY
static PRIVILEGED_DATA volatile BaseType_t xSchedulerRunning = pdFALSE
static PRIVILEGED_DATA volatile TickType_t xPendedTicks = ( TickType_t ) 0U
static PRIVILEGED_DATA volatile BaseType_t xYieldPending = pdFALSE
static PRIVILEGED_DATA volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0
static PRIVILEGED_DATA UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U
static PRIVILEGED_DATA volatile TickType_t xNextTaskUnblockTime = ( TickType_t ) 0U
static PRIVILEGED_DATA TaskHandle_t xIdleTaskHandle = NULL
 Holds the handle of the idle task.
const volatile UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1U
static PRIVILEGED_DATA volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) 0U

Macro Definition Documentation

◆ configIDLE_TASK_NAME

#define configIDLE_TASK_NAME   "IDLE"

Definition at line 115 of file tasks.c.

Referenced by vTaskStartScheduler().

◆ MPU_WRAPPERS_INCLUDED_FROM_API_FILE

#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE

Definition at line 36 of file tasks.c.

◆ portRESET_READY_PRIORITY

#define portRESET_READY_PRIORITY ( uxPriority,
uxTopReadyPriority )

Definition at line 158 of file tasks.c.

Referenced by prvAddCurrentTaskToDelayedList().

◆ prvAddTaskToReadyList

#define prvAddTaskToReadyList ( pxTCB)
Value:
do { \
traceMOVED_TASK_TO_READY_STATE( pxTCB ); \
taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \
listINSERT_END( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \
tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ); \
} while( 0 )
static PRIVILEGED_DATA List_t pxReadyTasksLists[configMAX_PRIORITIES]
Prioritised ready tasks.
Definition tasks.c:338

Definition at line 220 of file tasks.c.

Referenced by prvAddNewTaskToReadyList(), vTaskRemoveFromUnorderedEventList(), xTaskIncrementTick(), xTaskRemoveFromEventList(), and xTaskResumeAll().

◆ prvGetTCBFromHandle

#define prvGetTCBFromHandle ( pxHandle)
Value:
( ( ( pxHandle ) == NULL ) ? pxCurrentTCB : ( pxHandle ) )
#define NULL
Definition usbd_def.h:44
portDONT_DISCARD PRIVILEGED_DATA TCB_t *volatile pxCurrentTCB
Definition tasks.c:332

Definition at line 235 of file tasks.c.

Referenced by pcTaskGetName().

◆ taskEVENT_LIST_ITEM_VALUE_IN_USE

#define taskEVENT_LIST_ITEM_VALUE_IN_USE   0x8000U

Definition at line 246 of file tasks.c.

Referenced by vTaskPlaceOnUnorderedEventList(), and vTaskRemoveFromUnorderedEventList().

◆ taskNOT_WAITING_NOTIFICATION

#define taskNOT_WAITING_NOTIFICATION   ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */

Definition at line 71 of file tasks.c.

◆ taskNOTIFICATION_RECEIVED

#define taskNOTIFICATION_RECEIVED   ( ( uint8_t ) 2 )

Definition at line 73 of file tasks.c.

◆ taskRECORD_READY_PRIORITY

#define taskRECORD_READY_PRIORITY ( uxPriority)
Value:
do { \
if( ( uxPriority ) > uxTopReadyPriority ) \
{ \
uxTopReadyPriority = ( uxPriority ); \
} \
} while( 0 ) /* taskRECORD_READY_PRIORITY */
static PRIVILEGED_DATA volatile UBaseType_t uxTopReadyPriority
Definition tasks.c:367

Definition at line 126 of file tasks.c.

◆ taskRESET_READY_PRIORITY

#define taskRESET_READY_PRIORITY ( uxPriority)

Definition at line 157 of file tasks.c.

◆ taskSELECT_HIGHEST_PRIORITY_TASK

#define taskSELECT_HIGHEST_PRIORITY_TASK ( )
Value:
do { \
UBaseType_t uxTopPriority = uxTopReadyPriority; \
\
/* Find the highest priority queue that contains ready tasks. */ \
while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopPriority ] ) ) ) \
{ \
configASSERT( uxTopPriority ); \
--uxTopPriority; \
} \
\
/* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \
* the same priority get an equal share of the processor time. */ \
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \
uxTopReadyPriority = uxTopPriority; \
} while( 0 ) /* taskSELECT_HIGHEST_PRIORITY_TASK */
#define listLIST_IS_EMPTY(pxList)
Definition list.h:258
unsigned long UBaseType_t
Definition portmacro.h:60

Definition at line 136 of file tasks.c.

Referenced by vTaskSwitchContext().

◆ taskSWITCH_DELAYED_LISTS

#define taskSWITCH_DELAYED_LISTS ( )
Value:
do { \
List_t * pxTemp; \
\
/* The delayed tasks list should be empty when the lists are switched. */ \
configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) ); \
\
pxTemp = pxDelayedTaskList; \
prvResetNextTaskUnblockTime(); \
} while( 0 )
struct xLIST List_t
static PRIVILEGED_DATA List_t *volatile pxOverflowDelayedTaskList
Points to the delayed task list currently being used to hold tasks that have overflowed the current t...
Definition tasks.c:342
static PRIVILEGED_DATA volatile BaseType_t xNumOfOverflows
Definition tasks.c:371
static PRIVILEGED_DATA List_t *volatile pxDelayedTaskList
Points to the delayed task list currently being used.
Definition tasks.c:341

Definition at line 200 of file tasks.c.

Referenced by xTaskIncrementTick().

◆ taskWAITING_NOTIFICATION

#define taskWAITING_NOTIFICATION   ( ( uint8_t ) 1 )

Definition at line 72 of file tasks.c.

◆ taskYIELD_IF_USING_PREEMPTION

#define taskYIELD_IF_USING_PREEMPTION ( )

Definition at line 65 of file tasks.c.

Referenced by prvAddNewTaskToReadyList(), and xTaskResumeAll().

◆ tskBLOCKED_CHAR

#define tskBLOCKED_CHAR   ( 'B' )

Definition at line 99 of file tasks.c.

◆ tskDELETED_CHAR

#define tskDELETED_CHAR   ( 'D' )

Definition at line 101 of file tasks.c.

◆ tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB

#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB   ( ( uint8_t ) 0 )

Definition at line 82 of file tasks.c.

◆ tskREADY_CHAR

#define tskREADY_CHAR   ( 'R' )

Definition at line 100 of file tasks.c.

◆ tskRUNNING_CHAR

#define tskRUNNING_CHAR   ( 'X' )

Definition at line 98 of file tasks.c.

◆ tskSET_NEW_STACKS_TO_KNOWN_VALUE

#define tskSET_NEW_STACKS_TO_KNOWN_VALUE   0

Definition at line 92 of file tasks.c.

◆ tskSTACK_FILL_BYTE

#define tskSTACK_FILL_BYTE   ( 0xa5U )

Definition at line 79 of file tasks.c.

◆ tskSTATICALLY_ALLOCATED_STACK_AND_TCB

#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB   ( ( uint8_t ) 2 )

Definition at line 84 of file tasks.c.

Referenced by prvInitialiseTaskLists().

◆ tskSTATICALLY_ALLOCATED_STACK_ONLY

#define tskSTATICALLY_ALLOCATED_STACK_ONLY   ( ( uint8_t ) 1 )

Definition at line 83 of file tasks.c.

◆ tskSUSPENDED_CHAR

#define tskSUSPENDED_CHAR   ( 'S' )

Definition at line 102 of file tasks.c.

Typedef Documentation

◆ TCB_t

typedef tskTCB TCB_t

Definition at line 328 of file tasks.c.

◆ tskTCB

typedef struct tskTaskControlBlock tskTCB

Function Documentation

◆ pcTaskGetName()

char * pcTaskGetName ( TaskHandle_t xTaskToQuery)

Definition at line 2353 of file tasks.c.

References configASSERT, tskTaskControlBlock::pcTaskName, and prvGetTCBFromHandle.

Referenced by osThreadGetName().

◆ portTASK_FUNCTION()

◆ prvAddCurrentTaskToDelayedList()

◆ prvAddNewTaskToReadyList()

◆ prvCheckTasksWaitingTermination()

void prvCheckTasksWaitingTermination ( void )
static

THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK

Definition at line 3744 of file tasks.c.

References listGET_OWNER_OF_HEAD_ENTRY, taskENTER_CRITICAL, taskEXIT_CRITICAL, uxCurrentNumberOfTasks, uxListRemove(), and tskTaskControlBlock::xStateListItem.

Referenced by portTASK_FUNCTION().

◆ prvInitialiseTaskLists() [1/2]

void prvInitialiseTaskLists ( static void prvCheckTasksWaitingTermination void)
static

Utility task that simply returns pdTRUE if the task referenced by xTask is currently in the Suspended state, or pdFALSE if the task referenced by xTask is in any other state.

Definition at line 421 of file tasks.c.

References configASSERT, configSTACK_DEPTH_TYPE, NULL, PRIVILEGED_FUNCTION, prvAddNewTaskToReadyList(), and tskSTATICALLY_ALLOCATED_STACK_AND_TCB.

◆ prvInitialiseTaskLists() [2/2]

◆ prvResetNextTaskUnblockTime()

void prvResetNextTaskUnblockTime ( void )
static

◆ uxTaskGetNumberOfTasks()

UBaseType_t uxTaskGetNumberOfTasks ( void )

Definition at line 2345 of file tasks.c.

References uxCurrentNumberOfTasks.

Referenced by osThreadEnumerate(), and osThreadGetCount().

◆ uxTaskResetEventItemValue()

TickType_t uxTaskResetEventItemValue ( void )

◆ vTaskEndScheduler()

void vTaskEndScheduler ( void )

Definition at line 2092 of file tasks.c.

References pdFALSE, portDISABLE_INTERRUPTS, vPortEndScheduler(), and xSchedulerRunning.

◆ vTaskInternalSetTimeOutState()

void vTaskInternalSetTimeOutState ( TimeOut_t *const pxTimeOut)

◆ vTaskMissedYield()

void vTaskMissedYield ( void )

Definition at line 3431 of file tasks.c.

References pdTRUE, and xYieldPending.

Referenced by prvUnlockQueue().

◆ vTaskPlaceOnEventList()

void vTaskPlaceOnEventList ( List_t *const pxEventList,
const TickType_t xTicksToWait )

◆ vTaskPlaceOnUnorderedEventList()

void vTaskPlaceOnUnorderedEventList ( List_t * pxEventList,
const TickType_t xItemValue,
const TickType_t xTicksToWait )

◆ vTaskRemoveFromUnorderedEventList()

◆ vTaskSetTimeOutState()

void vTaskSetTimeOutState ( TimeOut_t *const pxTimeOut)

◆ vTaskStartScheduler()

◆ vTaskSuspendAll()

◆ vTaskSwitchContext()

◆ xTaskCatchUpTicks()

BaseType_t xTaskCatchUpTicks ( TickType_t xTicksToCatchUp)

◆ xTaskCheckForTimeOut()

◆ xTaskGetTickCount()

TickType_t xTaskGetTickCount ( void )

◆ xTaskGetTickCountFromISR()

TickType_t xTaskGetTickCountFromISR ( void )

◆ xTaskIncrementTick()

◆ xTaskRemoveFromEventList()

◆ xTaskResumeAll()

Variable Documentation

◆ pxCurrentTCB

◆ pxDelayedTaskList

PRIVILEGED_DATA List_t* volatile pxDelayedTaskList
static

Points to the delayed task list currently being used.

Definition at line 341 of file tasks.c.

Referenced by prvAddCurrentTaskToDelayedList(), prvInitialiseTaskLists(), prvResetNextTaskUnblockTime(), and xTaskIncrementTick().

◆ pxOverflowDelayedTaskList

PRIVILEGED_DATA List_t* volatile pxOverflowDelayedTaskList
static

Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count.

Definition at line 342 of file tasks.c.

Referenced by prvAddCurrentTaskToDelayedList(), and prvInitialiseTaskLists().

◆ pxReadyTasksLists

PRIVILEGED_DATA List_t pxReadyTasksLists[configMAX_PRIORITIES]
static

Prioritised ready tasks.

Definition at line 338 of file tasks.c.

Referenced by portTASK_FUNCTION(), prvInitialiseTaskLists(), and xTaskIncrementTick().

◆ uxCurrentNumberOfTasks

PRIVILEGED_DATA volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U
static

◆ uxSchedulerSuspended

◆ uxTaskNumber

PRIVILEGED_DATA UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U
static

Definition at line 372 of file tasks.c.

Referenced by prvAddNewTaskToReadyList().

◆ uxTopReadyPriority

PRIVILEGED_DATA volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY
static

Definition at line 367 of file tasks.c.

Referenced by prvAddCurrentTaskToDelayedList().

◆ uxTopUsedPriority

const volatile UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1U

Definition at line 379 of file tasks.c.

Referenced by vTaskStartScheduler().

◆ xDelayedTaskList1

PRIVILEGED_DATA List_t xDelayedTaskList1
static

Delayed tasks.

Definition at line 339 of file tasks.c.

Referenced by prvInitialiseTaskLists().

◆ xDelayedTaskList2

PRIVILEGED_DATA List_t xDelayedTaskList2
static

Delayed tasks (two lists are used - one for delays that have overflowed the current tick count.

Definition at line 340 of file tasks.c.

Referenced by prvInitialiseTaskLists().

◆ xIdleTaskHandle

PRIVILEGED_DATA TaskHandle_t xIdleTaskHandle = NULL
static

Holds the handle of the idle task.

The idle task is created automatically when the scheduler is started.

Definition at line 374 of file tasks.c.

Referenced by vTaskStartScheduler().

◆ xNextTaskUnblockTime

◆ xNumOfOverflows

PRIVILEGED_DATA volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0
static

◆ xPendedTicks

PRIVILEGED_DATA volatile TickType_t xPendedTicks = ( TickType_t ) 0U
static

Definition at line 369 of file tasks.c.

Referenced by xTaskCatchUpTicks(), xTaskIncrementTick(), and xTaskResumeAll().

◆ xPendingReadyList

PRIVILEGED_DATA List_t xPendingReadyList
static

Tasks that have been readied while the scheduler was suspended.

They will be moved to the ready list when the scheduler is resumed.

Definition at line 343 of file tasks.c.

Referenced by prvInitialiseTaskLists(), xTaskRemoveFromEventList(), and xTaskResumeAll().

◆ xSchedulerRunning

PRIVILEGED_DATA volatile BaseType_t xSchedulerRunning = pdFALSE
static

Definition at line 368 of file tasks.c.

Referenced by prvAddNewTaskToReadyList(), vTaskEndScheduler(), and vTaskStartScheduler().

◆ xTickCount

◆ xYieldPending