Updated Jun 2025
xTimerStopFromISR
timers.h
1 BaseType_t xTimerStopFromISR2 (3 TimerHandle_t xTimer,4 BaseType_t *pxHigherPriorityTaskWoken5 );
A version of xTimerStop() that can be called from an interrupt service routine.
Parameters:
-
xTimer
The handle of the timer being stopped.
-
pxHigherPriorityTaskWoken
The timer service/daemon task spends most of its time in the Blocked state, waiting for messages to arrive on the timer command queue. Calling
writes a message to the timer command queue, so has the potential to transition the timer service/daemon task out of the Blocked state. If callingxTimerStopFromISR()causes the timer service/daemon task to leave the Blocked state, and the timer service/daemon task has a priority equal to or greater than the currently executing task (the task that was interrupted), thenxTimerStopFromISR()will get set topxHigherPriorityTaskWokeninternally within thepdTRUEfunction. IfxTimerStopFromISR()sets this value toxTimerStopFromISR(), then a context switch should be performed before the interrupt exits.pdTRUE
Returns:
-
pdFAIL
will be returned if the stop command could not be sent to the timer command queue.pdFAIL -
pdPASS
will be returned if the command was successfully sent to the timer command queue. When the command is actually processed will depend on the priority of the timer service/daemon task relative to other tasks in the system. The timer service/daemon task priority is set by thepdPASSconfiguration constant.configTIMER_TASK_PRIORITY
Example usage:
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}