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 );

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

相关推荐
wdfk_prog15 小时前
canopennode-rtt推荐,不只可以做从站,也可以承担主站角色
c语言·开发语言·数据库·学习·算法·深度优先
无小道15 小时前
C/C++——可变参数
c语言·开发语言·c++·可变参数
是隼人16 小时前
buuctf-pwn PWN1题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
zbyyd16 小时前
Linux 网络编程:IO 多路复用
linux·运维·c语言·网络
晊晌_h17 小时前
嵌入式从0到精通——Linux 网络通信|TCP、HTTP 网络编程
linux·c语言·网络
路上有只喵18 小时前
STM32 UI Designer:一个开源的嵌入式 LCD 界面可视化设计工具(自动生成 C 代码)
c语言·驱动开发·stm32
灵晔君18 小时前
【Linux】基础IO(一)——文件、上层C库文件操作、底层linux原生IO
linux·运维·c语言
736c1 天前
C语言-结构体 08
c语言
736c1 天前
C语言-数组 07
c语言·开发语言
kakakahahahaha1 天前
【Windows】C盘低空间反复复发的排查与扩容边界
c语言·windows·电脑·笔记本电脑·内容运营·软件需求