timer.c 介绍

static portTASK_FUNCTION( prvTimerTask, pvParameters )

{

TickType_t xNextExpireTime;

BaseType_t xListWasEmpty;

/* Just to avoid compiler warnings. */

( void ) pvParameters;

#if ( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )

{

/* Allow the application writer to execute some code in the context of

* this task at the point the task starts executing. This is useful if the

* application includes initialisation code that would benefit from

* executing after the scheduler has been started. */

vApplicationDaemonTaskStartupHook();

}

#endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */

for( ; configCONTROL_INFINITE_LOOP(); )

{

/* Query the timers list to see if it contains any timers, and if so,

* obtain the time at which the next timer will expire. */

xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );

/* If a timer has expired, process it. Otherwise, block this task

* until either a timer does expire, or a command is received. */

prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );

/* Empty the command queue. */

prvProcessReceivedCommands();

}

}

xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );

获取下一个列表节点

prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );

( void ) xTaskResumeAll();

prvProcessExpiredTimer( xNextExpireTime, xTimeNow );

static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,

const TickType_t xTimeNow )

{

/* MISRA Ref 11.5.3 Void pointer assignment */

/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */

/* coveritymisra_c_2012_rule_11_5_violation */

Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );

/* Remove the timer from the list of active timers. A check has already

* been performed to ensure the list is not empty. */

( void ) uxListRemove( &( pxTimer->xTimerListItem ) );

if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U )

{

prvReloadTimer( pxTimer, xNextExpireTime, xTimeNow );

}

else

{

pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );

}

/* Call the timer callback. */

traceTIMER_EXPIRED( pxTimer );

pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );

}

如果节点超时时间到达,那么删除节点,触发回调

/* Empty the command queue. */

prvProcessReceivedCommands();

如果节点时间没有达到,那么不触发回调

重新将任务挂起,设置超时剩余的超时时间。

vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );

定时器接收消息处理,启动,停止,删除

相关推荐
爱读书的小胖44 分钟前
Codewars: A Brave New Wordle(C)解题分析
c语言·数据结构·算法
Escalating_xu1 小时前
【数据结构】顺序表的应用:动态通讯录项目与双指针经典算法
c语言·数据结构·算法
从小白到软工2 小时前
C语言(中)预告
c语言·数据结构·经验分享·ai编程
Logic1012 小时前
C语言/数据结构字符串题解:解压缩“字符+次数“格式——多位数字处理与字符串还原
c语言·数据结构·字符串·模拟·时间复杂度·空间复杂度·算法题
SuperByteMaster3 小时前
while(1){;} 加分号
c语言
Logic1013 小时前
C语言/数据结构位运算题解:异或XOR找出糖葫芦派对中的“独一无二山楂果数量“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
星恒随风4 小时前
Linux进程信号(一):从Ctrl+C到kill、raise、alarm,深入理解信号的概念与产生原理
linux·c语言·笔记·学习·状态模式
学逆向的4 小时前
C 浮点数e(科学计数法)
c语言·开发语言·网络安全
知识分享小能手4 小时前
C学习教程,从入门到精通,C语言数组 —— 知识点详解(8)
c语言·学习·算法
lhbweilai4 小时前
分析FreeRTOS内核对象API的源码实现(三)
c语言·stm32·单片机