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年6月

xTimerStopFromISR

[定时器 API]

timers.h

1 BaseType_t xTimerStopFromISR
2 (
3 TimerHandle_t xTimer,
4 BaseType_t *pxHigherPriorityTaskWoken
5 );

可从中断服务例程调用的 xTimerStop() 的版本。

参数:

  • xTimer

    正在停止的定时器的句柄。

  • pxHigherPriorityTaskWoken

    定时器服务/守护进程任务大部分时间都处于“阻塞”状态,等待消息 到达定时器命令队列。调用

    xTimerStopFromISR()
    会将消息写入定时器命令 队列,从而让定时器服务/守护进程任务转换为非阻塞状态。如果 调用
    xTimerStopFromISR()
    导致定时器服务/守护进程任务退出阻塞状态,并且 定时器服务/守护进程任务的优先级等于或高于当前执行的任务 (被中断的任务),则
    pxHigherPriorityTaskWoken
    将被设置为
    pdTRUE
    (从
    xTimerStopFromISR()
    函数内部设置)。如果
    xTimerStopFromISR()
    将此值设置为
    pdTRUE
    , 那么应在退出中断之前执行上下文切换。

返回:

  • pdFAIL

    如果无法向定时器命令队列发送停止命令,则返回

    pdFAIL

  • pdPASS

    如果命令成功发送至定时器命令队列,则返回

    pdPASS
    。实际处理命令的时间 取决于定时器服务/守护进程任务相对于系统中其他任务的 优先级。定时器服务/守护进程 任务的优先级由
    configTIMER_TASK_PRIORITY
    配置常量设置。

用法示例:

1/* This scenario assumes xTimer has already been created and started. When
2 an interrupt occurs, the timer should be simply stopped. */
3
4/* The interrupt service routine that stops the timer. */
5void vAnExampleInterruptServiceRoutine( void )
6{
7BaseType_t xHigherPriorityTaskWoken = pdFALSE;
8
9 /* The interrupt has occurred - simply stop the timer.
10 xHigherPriorityTaskWoken was set to pdFALSE where it was defined
11 (within this function). As this is an interrupt service routine, only
12 FreeRTOS API functions that end in "FromISR" can be used. */
13 if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
14 {
15 /* The stop command was not executed successfully. Take appropriate
16 action here. */
17 }
18
19 /* If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
20 should be performed. The syntax required to perform a context switch
21 from inside an ISR varies from port to port, and from compiler to
22 compiler. Inspect the demos for the port you are using to find the
23 actual syntax required. */
24 if( xHigherPriorityTaskWoken != pdFALSE )
25 {
26 /* Call the interrupt safe yield function here (actual function
27 depends on the FreeRTOS port being used). */
28 }
29}