当前位置:网站首页>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 .
边栏推荐
- 2020-09-23左右值 右值引用 std::move()
- Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
- 阿里云服务器安装配置redis,无法远程访问
- 2020-09-17 gateway业务流程 两个任务:referer认证和非商品模板化
- [Huawei certification] the most complete and selected question bank in hcia-datacom history (with answer analysis)
- Introduction to intranet penetration tool FRP
- JVM四种调用方法的指令
- 我想要股票开户优惠,怎么得到?还有,在线开户安全么?
- Summary of PHP memory horse technology research and killing methods
- 阿里云防火墙配置,多种设置方式(iptables和fireward)
猜你喜欢

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

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

Force deduction 85 question maximum rectangle

力扣94二叉树的中序遍历

Closed door cultivation (24) shallow understanding of cross domain problems

KDevelop new project

Segmentation of Head and Neck Tumours Using Modified U-net

JVM之对象的内存布局

IPC(进程间通信)之管道详解

A comparison of methods for fully automatic segmentation of tumors and involved nodes in PET/CT of h
随机推荐
zabbix4.4配置监控服务器指标,以及图形页乱码解决
ImageView图片填充问题
Recyclerview refreshes blinks and crashes when deleting items
Construction and use of Changan chain go language smart contract environment
内网穿透工具frp使用入门
Application of decorator mode, packaging ServletRequest and adding addparameter method
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
安装Anaconda后启动JupyterLab需要输入密码
leetcode MYSQL数据库题目178
微信小程序实现store功能
阿里云防火墙配置,多种设置方式(iptables和fireward)
Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear
Data visualization: the significance of data visualization
Caused by: org. apache. xerces. impl. io. MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
367. 有效的完全平方数-二分法
How to traverse objects in the vector container
367. effective complete square dichotomy
Wechat applet rewrites the page function to realize global logging
Generic paging framework
请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律: