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

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

相关推荐
David猪大卫1 小时前
【Linux修炼】环境变量、进程地址空间
linux·c语言·经验分享·笔记·学习·ubuntu·centos
Zwawa9 小时前
两根线怎么挂住一堆设备:I2C 协议原理
c语言·单片机·嵌入式
武子康11 小时前
h3.c 的两个权重槽,怎样把内存压力换成 SSD 等待
c语言·人工智能·agent
§ꦿCFོ༉1 天前
嵌入式八股—C语言入门学习(一)
c语言·编程语言·嵌入式八股文
沐晓时光1 天前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
智者知已应修善业2 天前
【51单片机实现从下到上,从上到下,从中间到两边,两边到中间】2024-10-23
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
布莱克6052 天前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
揽星河..2 天前
【C语言】底层程序设计
c语言·开发语言
揽星河..2 天前
【C语言】结构体
c语言·开发语言
唐青枫2 天前
C 语言 malloc() 详解与实战 Demo
c语言