已更新 2025年6月
xTimerStopFromISR
[定时器 API]
timers.h
1 BaseType_t xTimerStopFromISR2 (3 TimerHandle_t xTimer,4 BaseType_t *pxHigherPriorityTaskWoken5 );
可从中断服务例程调用的 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. When2 an interrupt occurs, the timer should be simply stopped. */34/* The interrupt service routine that stops the timer. */5void vAnExampleInterruptServiceRoutine( void )6{7BaseType_t xHigherPriorityTaskWoken = pdFALSE;89 /* The interrupt has occurred - simply stop the timer.10 xHigherPriorityTaskWoken was set to pdFALSE where it was defined11 (within this function). As this is an interrupt service routine, only12 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 appropriate16 action here. */17 }1819 /* If xHigherPriorityTaskWoken equals pdTRUE, then a context switch20 should be performed. The syntax required to perform a context switch21 from inside an ISR varies from port to port, and from compiler to22 compiler. Inspect the demos for the port you are using to find the23 actual syntax required. */24 if( xHigherPriorityTaskWoken != pdFALSE )25 {26 /* Call the interrupt safe yield function here (actual function27 depends on the FreeRTOS port being used). */28 }29}