freertos的调度过程

一.Preface

理解Freertos的任务调度对理解整个实时操作系统是非常有帮助的,最近抽空又复习了一遍源码,所以在此记录一下。

image



二.freertos的3各任务链表

2.1ready list(array)

a.这是一个链表组,定义了最高优先级为10,则有10个readylist。
b.每隔1个tick,freertos的tick中断就会从里面寻找最高优先级的task链表依次切换,并执行。

2.2delayed list

a.在任务中使用vTaskDelay(or vTaskDelayUntil)会把当前任务放入delayed list。
b.每隔1个tick,freertos的tick中断就会去判断delayed list中任务阻塞时间,如果时间到了,则将任务加入到对应优先级的ready list。

2.3pending list

b.pengding list的用法

点击查看代码
vTaskSuspendAll();	/*确保同一时刻把数据放入队列中*/
			xQueueOverwrite(accelerometerDataQueue, &sensors.acc);
			xQueueOverwrite(gyroDataQueue, &sensors.gyro);
			if (isMagPresent)
			{
				xQueueOverwrite(magnetometerDataQueue, &sensors.mag);
			}
			if (isBaroPresent)
			{
				xQueueOverwrite(barometerDataQueue, &sensors.baro);
			}
			xTaskResumeAll();

2.4对应的链表代码

点击查看代码
PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList1;						/*< Delayed tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList2;						/*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList;				/*< Points to the delayed task list currently being used. */
PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList;		/*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t xPendingReadyList;						/*<
posted @ 2025-10-13 00:05  Charles_hui  阅读(5)  评论(0)    收藏  举报