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

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

相关推荐
qq_448011163 小时前
C语言中的柔性数组
c语言·开发语言·柔性数组
luj_17685 小时前
塔防牌:策略与卡牌的智慧碰撞
服务器·c语言·开发语言·经验分享·算法
wuyk5556 小时前
3.链表:用指针串联的动态数据结构
c语言·开发语言·数据结构·链表
Lzh编程小栈7 小时前
【嵌入式底层】SPI超透彻详解:通信原理、四线结构、四种模式、寄存器底层 + 面试全集
c语言·stm32·单片机·面试·职场和发展
凉茶钱7 小时前
【数据结构】堆的应用
c语言·数据结构
Herbert_hwt12 小时前
【C语言基础】常量、选择结构与运算符全解析
c语言·开发语言·算法
WWJA王文举1 天前
I²C通信完整流程详解:START、地址、ACK、数据、Repeated START和STOP一次讲透
c语言·开发语言
qq_448011161 天前
C语言中的动态内存分配
c语言·开发语言·php
动词ing1 天前
【学习笔记】C语言(数组指针与指针数组+字符数组+函数+参数传递+字符串作为形参+递归函数+指针函数+回调函数+结构体嵌套+内存动态分配函数)
c语言·笔记·学习