1. 下图是FreeRTOS中的链表的基本结构关系
几点说明:
-
List_t {}structureis the list header.
-
UxNumberOfItemsindicatesthe number of item in the list. In this example it has three item.
-
The list order is based on the xItemValuein thexList_ITEM{} from small value to largevalue.
-
You could refer to the vListInsert (),vListInsertEnd () and uxListRemove ()function in the List.c file for studying.
-
The pointer pvOwnerpoints tothe TCB block.
-
PvContainerpointersto the header of list.
2. 任务与调度:
下图是从网上抄来的,应该是FreeRTOS官网出来的图,在此借用,
从下图可以很清楚看到FreeRTOS中各个任务状态间的转换。状态的
转换需要调用特定的系统API函数才能完成。
-
FreeRTOS has several task lists below:
PxCurrentTCB point to current running task
PxReadyTasksLists[configMAX_PRIORITIES = 5]
xDelayedTaskList1 <- *pxDelayedTaskList
xDelayedTaskList2 <- *pxOverflowDelayedTaskList
xPendingReadyList
xTasksWaitingTermination
xSuspendedTaskList
UxTaskNumber is ready task number
-
The biggeruxPriority value, the higher taskpriority.
-
The macro taskYIELD_IF_USING_PREEMPTIONdo the task switch.
The macro portYIELD_WITHIN_API do the task switch.
-
The element “xStateListItem” in the “tskTCB{}”could be used to insert different task list
-
This is the “tskTCB” structure:
-
xStateListItem– can be used to be linked into other list (run, delay, blocked, suspend)
xEventListItem– can be used to be linked into Event list
xItemValue– represent the task’s priority and time to unblocked
下图是一个任务的结构,每个任务的TCB内部都包含了xStateListItem 与 xEventListItem项,
便于将任务的TCB挂到特定的链表上。
-
The function “xTaskIncrementTick()” is called tocheck the “pxDelayedTaskList” tasklist, if the wake time is reached, the task TCB will be moved from delayed tasklist “pxDelayedTaskList” to readytask list “pxReadyTasksLists”.
-
In the FreeRTOS, the timerISR will cause the task switching process, the timerISR willcall the “xTaskIncrementTick()”.
-
When “uxSchedulerSuspended== pdFALSE”, the scheduler is working, theReady and Delay tasklist can be accessed.
-
When “uxSchedulerSuspended!= pdFALSE”, the scheduler is disabled, only thePending task list can be accessed.
-
The “uxTopReadyPriority”holds the highest priority of thefiveready task lists.
-
The task added in the Delay task list is ordered fromshort to long blocked time, the header of theDelay task list has the shortestdelay time, this time copy into “xNextTaskUnblockTime”.
-
When the scheduler is suspended, the task in thepending list will be move to ready task list.
-
The “uxCurrentNumberOfTasks” represents the number oftask in the system.
-
When scheduler is suspended, theready and delayed task listcannot be accessed, only thependingtask list can be accessed.
-
The task can be added into Pending task listonly with the xEventListItem.