已更新 2025年4月
vTimerSetTimerID
[定时器 API]
timers.h
1 void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
创建定时器时,会为软件定时器分配一个标识符 (ID), 您随时可以使用
vTimerSetTimerID()
如果将同一个回调函数分配给多个定时器, 则可以在回调函数内检查定时器标识符, 以确定哪个定时器实际已到期。
在定时器回调函数的调用之间,定时器标识符也可用于将数据存储在定时器中 。
参数:
-
xTimer
更新的计时器。
-
pvNewID
句柄,定时器标识符将被设置为此句柄。
用法示例:
1/* A callback function assigned to a timer. */2void TimerCallbackFunction( TimerHandle_t pxExpiredTimer )3{4uint32_t ulCallCount;56 /* A count of the number of times this timer has expired7 and executed its callback function is stored in the8 timer's ID. Retrieve the count, increment it, then save9 it back into the timer's ID. */10 ulCallCount =11 ( uint32_t ) [pvTimerGetTimerID](/Documentation/02-Kernel/04-API-references/11-Software-timers/13-pvTimerGetTimerID)( pxExpiredTimer );12 ulCallCount++;13 vTimerSetTimerID( pxExpiredTimer, ( void * ) ulCallCount );14}