freeRTOS 在 BlackFin533 平台上的移植 (3) 预备的知识

本文介绍了FreeRTOS中链表结构的关系,包括List_t结构、任务数量和xItemValue的重要性。此外,文章阐述了FreeRTOS的任务调度机制,通过任务状态转换图展示了任务之间的状态切换,并详细描述了不同任务列表如Ready、Delayed和Pending等的用途。xTaskIncrementTick()函数在检查和管理延迟任务列表中的关键作用也得到了强调。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




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.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值