
图3.4:系统节拍计时器下的FreeRTOS就绪列表全貌
pxReadyTasksLists[]列出了在vTaskSwitchContext()中已经操纵完成的内容,是如何使用pxIndex的一个很好的例子。让我们假设我们仅有一个优先级,优先级0,并且有三个任务在此优先级上。这与我们之前看到的基本就绪列表图相,但这一次我们将包括所有的数据结构和字段。
就如你在图3.3中所见,pxCurrentTCB显示我们当前正在运行任务B。下一个时刻,vTaskSwitchContext()运行,它调用listGET_OWNER_OF_NEXT_ENTRY()载入下一个任务来运行。如图3.4所示,这个函数使用pxIndex->pxNext找出下一个任务是任务C,并且pxIndex指向任务C的列表元素,同时pxCurrentTCB指向任务C的TCB。
请注意,每个struct xlistitem对象实际上都是来自相关TCB的xGenericListItem对象。
3.6. 队列
FreeRTOS允许任务使用队列来互相间通信和同步。中断服务程序(ISRs)同样使用队列来通信和同步。
基本队列数据结构如下:
typedef struct QueueDefinition
{
signed char *pcHead; /* Points to the beginning of the queue
storage area. */
signed char *pcTail; /* Points to the byte at the end of the
queue storage area. One more byte is
allocated than necessary to store the
queue items; this is used as a marker. */
signed char *pcWriteTo; /* Points to the free next place in the
storage area. */
signed char *pcReadFrom; /* Points to the last place that a queued
item was read from. */
xList xTasksWaitingToSend; /* List of tasks that are blocked waiting
to post onto this queue. Stored in
priority order. */
xList xTasksWaitingToReceive; /* List of tasks that are blocked waiting
to read from this queue. Stored in
priority order. */
volatile unsigned portBASE_TYPE uxMessagesWaiting; /* The number of items currently
in the queue. */
unsigned portBASE_TYPE uxLength; /* The length of the queue
defined as the number of
items it will hold, not the
number of bytes. */
unsigned portBASE_TYPE uxItemSize; /* The size of each items that
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-30698-8.html
扔股市是血本无归
距离你生日只有一个月啦
踏踏实实对你一百个放心