当前位置:网站首页>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 .
边栏推荐
- 完美二叉树、完全二叉树、完满二叉树
- Student增删gaih
- 语言特性
- leetcode MYSQL数据库题目178
- GSOAP example - calc
- 你必须知道的23个最有用的Elasticseaerch检索技巧
- 2020-09-25 boost库的noncopyable,用于单例模式
- Please use the learned knowledge to write a program to find out the password hidden in the long string below. The burial point of the password conforms to the following rules:
- FreeRTOS(九)——队列
- GCC and makefile
猜你喜欢

容器

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

阿里云防火墙配置,多种设置方式(iptables和fireward)

阿里云服务器安装配置redis,无法远程访问

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

Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.

JVM之对象的内存布局

UE4 compile a single file (VS and editor start respectively)

linux环境下安装配置redis,并设置开机自启动

Segmentation of Head and Neck Tumours Using Modified U-net
随机推荐
Constructing SQL statements by sprintf() function in C language
C语言实现一种创建易管理易维护线程的方法
Segmentation of Head and Neck Tumours Using Modified U-net
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
JVM四种调用方法的指令
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
Lc236. nearest common ancestor of binary tree
KDevelop new project
kdevelop新建工程
User level threads and kernel level threads
Data governance: the solution of data governance in the data Arena
es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
leetcode MYSQL数据库题目180
Basic operations of MAC MySQL database
Introduction to Chang'an chain data storage and construction of MySQL storage environment
How to set Google Chrome as the default browser
滑块验证代码
Is it safe to open an account for stock speculation? Is it reliable?
Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.
Please use the learned knowledge to write a program to find out the password hidden in the long string below. The burial point of the password conforms to the following rules: