任务结构体 typedef struct tskTaskControlBlock { volatile portSTACK_TYPE *pxTopOfStack; //指向任务堆栈结束处 #if ( portUSING_MPU_WRAPPERS == 1 ) xMPU_SETTINGS xMPUSettings; /*接口 TCB STRUCT第二个成员 */ #endif xListItem xGenericListItem; //用于把TCB插入就绪链表或等待链表 xListItem xEventListItem; //用于把TCB插入事件链表(如消息队列) unsigned portBASE_TYPE uxPriority; /*任务优先级 0 is the lowest priority. */ portSTACK_TYPE *pxStack; /*< 指向栈的开始 */ signed char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< 描述建立任务时的名称,便于调试 */ #if ( portSTACK_GROWTH > 0 ) portSTACK_TYPE *pxEndOfStack; /*< 指向栈底内存. */ #endif #if ( portCRITICAL_NESTING_IN_TCB == 1 ) //临界 unsigned portBASE_TYPE uxCriticalNesting; /*< 占着关键的部分nesting depth for ports that do not maintain their own count in the port layer. */ #endif #if ( configUSE_TRACE_FACILITY == 1 ) //追踪功能 unsigned portBASE_TYPE uxTCBNumber; /*< TCB 建立时计数. 调试时记录任务删除和从新建立 */ unsigned portBASE_TYPE uxTaskNumber; /*< 存储一个值供第三方追踪. */ #endif #if ( configUSE_MUTEXES == 1 ) //互斥器 unsigned portBASE_TYPE uxBasePriority; /*< 最后分配给任务的优先级 优先级继承机制 */ #endif #if ( configUSE_APPLICATION_TASK_TAG == 1 ) pdTASK_HOOK_CODE pxTaskTag; //任务标签,用于识别 #endif #if ( configGENERATE_RUN_TIME_STATS == 1 ) //运行时间状态 unsigned long ulRunTimeCounter; /*< 运行状态时的时间 */ #endif #if ( configUSE_NEWLIB_REENTRANT == 1 ) //重入函数 /*分配一个Newlib C语言程式库 */ struct _reent xNewLib_reent; //_reent静态实例 #endif } tskTCB;
一个双向链表 struct xLIST_ITEM { portTickType xItemValue; //链表节点的值 一个任务延时的节拍数 volatile struct xLIST_ITEM * pxNext; volatile struct xLIST_ITEM * pxPrevious; void * pvOwner; //item全部者 一般是任务控制模块 TCB void * pvContainer; //指向链表节点所在地链表 根据这个指针,就能知道任务是在就 绪任务链表中仍是阻塞任务链表中 }; typedef struct xLIST_ITEM xListItem;
struct xMINI_LIST_ITEM { portTickType xItemValue; //值 volatile struct xLIST_ITEM *pxNext; //下一个节点 volatile struct xLIST_ITEM *pxPrevious; //上一个 }; typedef struct xMINI_LIST_ITEM xMiniListItem; //mini
//通用的链表节点 typedef struct xLIST { volatile unsigned portBASE_TYPE uxNumberOfItems; // 链表中有多少元素 volatile xListItem * pxIndex; //用来遍历列表 指向上次访问的节点 volatile xMiniListItem xListEnd; // 链表尾节点 没有链表元素时指向本身 } xList;
队列 typedef struct QueueDefinition { signed char *pcHead; /*< 指向 队列的存储区域开始 */ signed char *pcTail; /*< 指向队列的存储区域的结束字节. 一旦更多的字节被分配要存储的队列项,这是做为一个标记。 */ signed char *pcWriteTo; /*< 指向队列的存储区域下一个空的地方 */ union /* 使用联合编码标准是个例外,以确保两个相互排斥的结构成员不一样时出现(浪费RAM)。 */ { signed char *pcReadFrom; /*< 指向最后一个地方that a queued item was read from 当一个结构体被用做队列. */ unsigned portBASE_TYPE uxRecursiveCallCount;/*< Maintains a count of the numebr of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */ } u; xList xTasksWaitingToSend; /*< 任务列被阻塞等待添加到这个队列. Stored in priority order. */ xList xTasksWaitingToReceive; /*< 任务列被阻塞等待读这个队列 Stored in priority order. */ volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< 目前队列中的项目数 */ unsigned portBASE_TYPE uxLength; /*< 队列的长度 defined as the number of items it will hold, */ unsigned portBASE_TYPE uxItemSize; /*< 队列每一个项目的大小 */ volatile signed portBASE_TYPE xRxLock; /*< 当队列被锁时存储队列接受到的任务的数量 (removed from the queue) . Set to queueUNLOCKED when the queue is not locked. */ volatile signed portBASE_TYPE xTxLock; /*< 当队列被锁时存储队列传输的任务的数量 (added to the queue). Set to queueUNLOCKED when the queue is not locked. */ #if ( configUSE_TRACE_FACILITY == 1 ) unsigned char ucQueueNumber; unsigned char ucQueueType; #endif #if ( configUSE_QUEUE_SETS == 1 ) struct QueueDefinition *pxQueueSetContainer; #endif } xQUEUE;