Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

已更新 2025年4月

vTimerSetTimerID

[定时器 API]

timers.h

1 void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );

创建定时器时,会为软件定时器分配一个标识符 (ID), 您随时可以使用

vTimerSetTimerID()
API 函数更改此 ID。

如果将同一个回调函数分配给多个定时器, 则可以在回调函数内检查定时器标识符, 以确定哪个定时器实际已到期。

在定时器回调函数的调用之间,定时器标识符也可用于将数据存储在定时器中 。

参数:

  • xTimer

    更新的计时器。

  • pvNewID

    句柄,定时器标识符将被设置为此句柄。

用法示例:

1/* A callback function assigned to a timer. */
2void TimerCallbackFunction( TimerHandle_t pxExpiredTimer )
3{
4uint32_t ulCallCount;
5
6 /* A count of the number of times this timer has expired
7 and executed its callback function is stored in the
8 timer's ID. Retrieve the count, increment it, then save
9 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}