- Task control block, 即任务控制块。任务控制块(TCB)是一个结构体,它会分配给每个任务,其中存储着任务的状态信息,包括指向任务上下文(任务的运行时环境,包括寄存器值)的指针。
- 任务控制块就像是任务的身份ID,必不可少。
- 基于DSP芯片TMS320F28377D上移植到FreeRTOS系统。
1. 源码定义
- 注意,已经根据宏定义,在源码中去除了未用到的部分。
/** Task control block. A task control block (TCB) is allocated for each task,* and stores task state information, including a pointer to the task's context* (the task's run time environment, including register values)*/
typedef struct tskTaskControlBlock
{/* 指向任务堆栈中最后一个项目的位置。这必须是TCB结构的第一个成员 */volatile StackType_t * pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. *//* 任务的状态列表项所引用的列表,用来表示该任务的状态(就绪、阻止、挂起) */ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). *//* 用于从事件列表中引用任务 */ListItem_t xEventListItem; /*< Used to reference a task from an event list. *//* 任务的优先级。0是最低优先级 */UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. *//* 指向堆栈的起点 */StackType_t * pxStack; /*< Points to the start of the stack. *//* 创建任务时为其指定的描述性名称 */char pcTaskName[ configMAX_TASK_NAME_LEN ];#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )/* 指向堆栈的最高有效地址 */StackType_t * pxEndOfStack; /*< Points to the highest valid address for the stack. */#endif#if ( configUSE_TRACE_FACILITY == 1 )/* 存储一个数字,每次创建TCB时递增。它允许调试器确定任务何时被删除,然后重新创建 */UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. *//* 存储一个专门供第三方跟踪代码使用的数字 */UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */#endif#if ( configUSE_MUTEXES == 1 )/* 上次分配给任务的优先级-由优先级继承机制使用。 */UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */UBaseType_t uxMutexesHeld;#endif#if ( configUSE_TASK_NOTIFICATIONS == 1 )volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];#endif#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )/* 如果任务是静态分配的,则设置为pdTRUE,以确保不会尝试释放内存 */uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */#endif
} tskTCB;/* The old tskTCB name is maintained above then typedefed to the new TCB_t name* below to enable the use of older kernel aware debuggers. */
typedef tskTCB TCB_t;typedef struct tskTaskControlBlock * TaskHandle_t; /* 任务句柄是任务控制块指针 */