FreeRTOS TaskStatus_t结构体翻译

The TaskStatus_t definition

typedef struct xTASK_STATUS
{
   /* The handle of the task to which the rest of the information in the
   structure relates. */
   TaskHandle_t xHandle;

   /* A pointer to the task's name.  This value will be invalid if the task was
   deleted since the structure was populated! */
   const signed char *pcTaskName;//任务名称

   /* A number unique to the task. */
   UBaseType_t xTaskNumber;//任务的唯一序号

   /* The state in which the task existed when the structure was populated. */
   eTaskState eCurrentState;//任务状态

   /* The priority at which the task was running (may be inherited) when the
   structure was populated. */
   UBaseType_t uxCurrentPriority;//任务优先级

   /* The priority to which the task will return if the task's current priority
   has been inherited to avoid unbounded priority inversion when obtaining a
   mutex.  Only valid if configUSE_MUTEXES is defined as 1 in
   FreeRTOSConfig.h. */
   /*uxBasePriority中存储任务的初始优先级。一个任务在它创建的时候被赋予优先级,同时任务的优先级是可以被改变的。
     如果FreeRTOS实现了优先级继承,那么当任务临时提升到“继承的”优先级时,
     它使用uxBasePriority去记住原来的优先级*/
   UBaseType_t uxBasePriority;

   /* The total run time allocated to the task so far, as defined by the run
   time stats clock.  Only valid when configGENERATE_RUN_TIME_STATS is
   defined as 1 in FreeRTOSConfig.h. */
   unsigned long ulRunTimeCounter;

   /* Points to the lowest address of the task's stack area. */
   StackType_t *pxStackBase;

   /* The minimum amount of stack space that has remained for the task since
   the task was created.  The closer this value is to zero the closer the task
   has come to overflowing its stack. */
   unsigned short usStackHighWaterMark;
} TaskStatus_t;

 

TaskHandle_t 其实指向tskTCB——任务上下文,标识一个任务的详细信息和运行时的堆栈等。 
在开始介绍tskTCB前,先看一下task.c中的关键全局变量:

pxCurrentTCB:记录现在运行的任务;
pxReadyTasksLists:记录处于ready状态,等待被调度运行的任务,这是一个链表数组,ready list安装优先级进行分类,这样在调度时就可以从优先级高的readylist中先进行调度。
xDelayedTaskList1:定义了一个delay的task链表。
xDelayedTaskList2:定义了一个delay的task链表,delay的task链表是指调用了taskdelay()或者因为阻塞动作被延时的任务,延时的单位为tick。Delaylist按照delay的tick时间进行排序,之所以定义了两个,是为了防止xTickCount发生反转时,一个list无法完全标识。
xTickCount:无符号数字,标识运行后到现在的系统产生的tick数,每个tick发生时,xTickCount++,当xTickCount发生翻转时,pxDelayedTaskList和pxOverflowDelayedTaskList进行对调,Overflowlist变为正常的delay list。
pxDelayedTaskList和pxOverflowDelayedTaskList是链表指针,分包指向xDelayedTaskList1和xDelayedTaskList2
xPendingReadyList:任务进入就绪状态,但是没有放入readylist链表。这种情况发生在调度器被停止时,有些任务进入到ready状态,这时就讲任务加入到xPendingReadyList,等待调度器开始时,从新进行一次调度。 
我们知道任何操作系统都有临界区或者在执行某段代码时不想被打断,防止破坏某些关键操作的完整性。Freertos可以采取多种方式避免,如果是不希望被中断打断,需要调用:

 

你可能感兴趣的:(FreeRTOS TaskStatus_t结构体翻译)