Higher priority task to be woken

looking at this API sample code:

void vANInterruptHandler( void )
    BaseType_t xHigherPriorityTaskWoken;
    uint32_t ulStatusRegister;

    ulStatusRegister = ulReadPeripheralInterruptStatus();

    vClearPeripheralInterruptStatus( ulStatusRegister );

    xHigherPriorityTaskWoken = pdFALSE;

    xTaskNotifyIndexedFromISR( xHandlingTask,
                               &xHigherPriorityTaskWoken );

    /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
    The macro used to do this is dependent on the port and may be called
    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );

If xHandlingTask is at priority 2 and there are other tasks at priority 1 and 3, which one will be immediately executed? xHandlingTask at priority 2 because the ISR just sent the notification to it or 3 if it was its turn?

What if the ISR was called in the middle of a task at priority 3, after the ISR, will the control go back to that priority 3 task until it is completed or to xHandlingTask (priority 2) because the ISR sent a notify and yielded from an ISR?

Thank you

The FreeRTOS schedule will ALWAYS chose the higher priority ready task, always.

If you interrupted a priority 3 task, and woke a priority 2 task, HigherPriorityTaskWoken would not be set, as there is no need to run the schedule, and if you did, it would still chose a Priority 3 ready task.

portYIELD_FROM_ISR just runs the scheduler, so the scheduler will still see that the priority 3 task was ready.

This is JUST like if the priority 3 task did a taskYIELD, that will check if another priority 3 task wants time and switch to it, but it will NOT switch to a priority 2 task.

Highly recommend reading the free to download book - think it will answer most of your questions.

Thank you both,

@rtel I have, but being relatively new to freeRTOS things get confusing. Apologies if I sometimes ask silly questions or questions that I should already know the answer to or to which you have already explained but I most likely did not pick up as I should have

Thank you as always! :slight_smile: