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.”

Updated Jun 2025

xTimerStopFromISR

[Timer API]

timers.h

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

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

    xTimerStopFromISR()
    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 calling
    xTimerStopFromISR()
    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), then
    pxHigherPriorityTaskWoken
    will get set to
    pdTRUE
    internally within the
    xTimerStopFromISR()
    function. If
    xTimerStopFromISR()
    sets this value to
    pdTRUE
    , then a context switch should be performed before the interrupt exits.

Returns:

  • pdFAIL

    pdFAIL
    will be returned if the stop command could not be sent to the timer command queue.

  • pdPASS

    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 the
    configTIMER_TASK_PRIORITY
    configuration constant.

Example usage:

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}