当前位置:网站首页>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 .
边栏推荐
- 基於PyQt5和Qt Designer的簡易加法計算器的制作
- 2020-09-17 gateway业务流程 两个任务:referer认证和非商品模板化
- Data visualization: the significance of data visualization
- leetcode MYSQL数据库题目180
- Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear
- 装饰器模式的应用,包装ServletRequest,增加addParameter方法
- Middle order traversal of Li Kou 94 binary tree
- linux下centos7中mysql5.7安装教程
- Cloud management platform: 9 open source cloud management platforms (CMP)
- kdevelop新建工程
猜你喜欢

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

1424. diagonal traversal II

遍历vector容器中的对象的方式

A 3D Dual Path U-Net of Cancer Segmentation Based on MRI

Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks

MySQL configuring master-slave databases

JVM之TLAB

Application of decorator mode, packaging ServletRequest and adding addparameter method

Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
随机推荐
券商经理给的开户二维码办理股票开户安全吗?我想开个户
2020-09-17 gateway业务流程 两个任务:referer认证和非商品模板化
A 2.5D Cancer Segmentation for MRI Images Based on U-Net
2020-9-14 广告系统入门
2020-09-18 referer认证 url转义
Hystrix熔断器:服务熔断与服务降级
Wechat applet implements the data listener watch, including the watch that destroys the watch and sub attributes
Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages
动态规划总结
JS获取手机型号和系统版本
【华为认证】HCIA-DATACOM史上最全精选题库(附答案解析)
Recyclerview refreshes blinks and crashes when deleting items
mysql修改自动递增初始值
zabbix4.4配置监控服务器指标,以及图形页乱码解决
UE4 compile a single file (VS and editor start respectively)
Data governance: Metadata Management (Part 2)
请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
Summary of PHP memory horse technology research and killing methods
Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
Do you know what BFD is? This article explains the principle and usage scenarios of BFD protocol in detail