当前位置:网站首页>FreeRTOS (VIII) - time management
FreeRTOS (VIII) - time management
2022-06-29 09:59:00 【Water like ice】
In use , We usually use... In a task function Delay function to delay , When the delay function is executed, the task will be switched , And the task enters the blocking state . Until the delay is completed , The task re enters the ready state . Delay function belongs to FreeRTOS Time management of . In this time management process ,
- What happened after the delay function was called ?
- How the task enters the blocking state ?
- How to restore the task to the ready state after the delay is completed ?
FreeRTOS The time delay function
function vTaskDealy()
stay FreeRTOS The medium delay function has relative mode and absolute mode , among vTaskDealy() It's a relative pattern , function vTaskDelayUntil() Absolute mode . function vTaskDealy() It is defined in the document , If you want to use a minor function, the macro INCLUDE_vTsakDelay It has to be for 1.
function code :
#if ( INCLUDE_vTaskDelay == 1 )
void vTaskDelay( const TickType_t xTicksToDelay )
{
BaseType_t xAlreadyYielded = pdFALSE;
/* A delay time of zero just forces a reschedule. */
if( xTicksToDelay > ( TickType_t ) 0U ) /*(1)*/
{
configASSERT( uxSchedulerSuspended == 0 );
vTaskSuspendAll(); /*(2)*/
{
traceTASK_DELAY();
/* A task that is removed from the event list while the scheduler is suspended will not get placed in the ready list or removed from the blocked list until the scheduler is resumed. This task cannot be in an event list as it is the currently executing task. */
prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE ); /*(3)*/
}
xAlreadyYielded = xTaskResumeAll(); /*(4)*/
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* Force a reschedule if xTaskResumeAll has not already done so, we may have put ourselves to sleep. */
if( xAlreadyYielded == pdFALSE ) /*(5)*/
{
portYIELD_WITHIN_API(); /*(6)*/
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
#endif /* INCLUDE_vTaskDelay */(1) The delay time is determined by the parameter xTicksToDelay To make sure , The number of beats for the time to be delayed , The delay time must be greater than 0. Otherwise, it is equivalent to calling portTIELD() Switch tasks .
(2) Call function vTaskSuspendAll() Suspend task scheduler .
(3) Call function prvAddCurrentTaskToDelayList() Add the task to be delayed to the delay list pxDelaydTaskList perhaps pxOverFlowDelaydTaskList in .
(4) Call function xTaskResumeAll() Restore task scheduler .
(5) If the function xTaskResumeAll() If there is no task scheduling, the task scheduling must be performed here .
(6) Call function portYIELD_WITHIN_API() Make a task schedule .
function vTaskDelayUntil()
function vTaskDelayUntil() It's blocking the mission , The blocking time is an absolute time , Functions can be used for tasks that need to be performed at a certain frequency vTaskDelayUntil(). This function is defined in tasks.c in .
| Parameters | Are |
|---|---|
| pxPreviousWakeTime | The time point when the last task is awakened after the delay ends , The first call to a function in a task vTaskDelayUntil() It is necessary pxPreviousWakeTime Initialize the whiel() Time point value of loop body , In the future, the function vTaskDelayUntil() It will update automatically pxPreviousWakeTime |
| xTimeIncrement | The number of time beats the task needs to delay ( be relative to pxPreviousWakeTime Beats of this delay ) |
#if ( INCLUDE_vTaskDelayUntil == 1 )
void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement )
{
TickType_t xTimeToWake;
BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE;
configASSERT( pxPreviousWakeTime );
configASSERT( ( xTimeIncrement > 0U ) );
configASSERT( uxSchedulerSuspended == 0 );
vTaskSuspendAll(); /*(1)*/
{
/* Minor optimisation. The tick count cannot change in this block. */
const TickType_t xConstTickCount = xTickCount; /*(2)*/
/* Generate the tick time at which the task wants to wake. */
xTimeToWake = *pxPreviousWakeTime + xTimeIncrement; /*(3)*/
if( xConstTickCount < *pxPreviousWakeTime ) /*(4)*/
{
/* The tick count has overflowed since this function was lasted called. In this case the only time we should ever actually delay is if the wake time has also overflowed, and the wake time is greater than the tick time. When this is the case it is as if neither time had overflowed. */
if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )/*(5)*/
{
xShouldDelay = pdTRUE; /*(6)*/
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
/* The tick time has not overflowed. In this case we will delay if either the wake time has overflowed, and/or the tick time is less than the wake time. */
if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )/*(7)*/
{
xShouldDelay = pdTRUE; /*(8)*/
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
/* Update the wake time ready for the next call. */
*pxPreviousWakeTime = xTimeToWake; /*(9)*/
if( xShouldDelay != pdFALSE ) /*(10)*/
{
traceTASK_DELAY_UNTIL( xTimeToWake );
/* prvAddCurrentTaskToDelayedList() needs the block time, not the time to wake, so subtract the current tick count. */
prvAddCurrentTaskToDelayedList( xTimeToWake - xConstTickCount, pdFALSE ); /*(11)*/
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
xAlreadyYielded = xTaskResumeAll(); /*(12)*/
/* Force a reschedule if xTaskResumeAll has not already done so, we may have put ourselves to sleep. */
if( xAlreadyYielded == pdFALSE )
{
portYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
#endif /* INCLUDE_vTaskDelayUntil */(1) Suspend task scheduler
(2) Record entry function vTaskDelayUntil() Time point value of , And keep it in xConstTickCount in .
(3) According to the delay time xTimeIncrement To calculate the next wake-up time of the task , And keep it in xTimeToWake in . This delay time is relative to the time point when the last task was awakened pxPreviousWakeTime Of .
(4) xConstTickCount overflow .
(5) since xConstTickCount overflow , Then the calculated task wake-up time point must also be overflow , also xTimeToWake Certainly more than xConstTickCount.
(6) If meet (5) Condition will pdTRUE Assign a value to xShouldDelay, Marking allows time delay .
(7) The other two cases ,1 It's just xTimeToWake overflow .2 No spillage .
(8) take pdTRUE Assign a value to xShouldDelay, Marking allows time delay .
(9) to update pxPreviousWakeTime The value of is xTimeToWake, Prepare for the next execution of this function .
(10) After the previous judgment , Allow task delay .
(11) Call function prvAddCurrentTaskToDelaydList() Carry out delay .
(12) Call function xTaskResumeAll() Restore task scheduler .
边栏推荐
- CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
- mysql修改自动递增初始值
- How to set Google Chrome as the default browser
- Lc236. nearest common ancestor of binary tree
- MySQL modify auto increment initial value
- 力扣94二叉树的中序遍历
- Is it safe to open an account for stock speculation? Is it reliable?
- 装饰器模式的应用,包装ServletRequest,增加addParameter方法
- 微信小程序实现数据侦听器watch,包含销毁watch和子属性的watch
- es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
猜你喜欢

User level threads and kernel level threads

A 2.5D Cancer Segmentation for MRI Images Based on U-Net

Segmentation of Head and Neck Tumours Using Modified U-net

How to set Google Chrome as the default browser

Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images

容器

Introduction to Chang'an chain data storage and construction of MySQL storage environment

Making of simple addition calculator based on pyqt5 and QT Designer

JVM之TLAB

A method of creating easy to manage and maintain thread by C language
随机推荐
Es error nonodeavailableexception[none of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
JS获取手机型号和系统版本
通用分页框架
你必须知道的23个最有用的Elasticseaerch检索技巧
Force deduction 85 question maximum rectangle
C语言实现一种创建易管理易维护线程的方法
Closed training (25) basic web security
sublime text3设置运行自己的Makefile
Is it safe to open an account for stock speculation? Is it reliable?
遍历vector容器中的对象的方式
UE4 compile a single file (VS and editor start respectively)
2020-09-23左右值 右值引用 std::move()
【华为认证】HCIA-DATACOM史上最全精选题库(附答案解析)
JVM之 MinorGC、 MajorGC、 FullGC、
Kicad learning notes - shortcut keys
语言特性
IPC(进程间通信)之管道详解
微信小程序重写Page函数,实现全局日志记录
Introduction to Chang'an chain data storage and construction of MySQL storage environment
Construction and use of Changan chain go language smart contract environment