There is documentation about taskYIELD
. This function can be used to request context switch so no need to wait for the tick. Context switching is privileged operation so it is often done by software interrupt. In your case by PendSV and SVCall.
If all tasks are blocked (e.g by vTaskDelay
) then FreeRTOS is running Idle Task. vTaskDelay
uses portYIELD
internally to request context switch, because there is no way how to continue current task.
You also need some knowledge about Preemptive multitasking to understand FreeRTOS in that mode.
Edit 2016-01-29:
- Calling delay function causes calling
taskYIELD
/portYIELD
internally. So your current task is blocked and FreeRTOS reschedule to highest priority task, that can run (is not also blocked) or to Idle task if there is no task able to run.
- Calling e.g.
xQueueReceive
can have two possibilities. There is some element in the queue, so it is POPed. There is no element in the queue, so the task is switched to blocked state and YIELD is called for you, so FreeRTOS reshedule to another task.
- Calling e.g.
xQueueSend
can have two possibilities. There is no room in the queue, so the task is blocked until there is some space. There is at least one free element, so you can push to the queue.
Receiving element from the queue or sending element to the queue can wake other higher priority task, that is doing oposite but is currently blocked. FreeRTOS will reschedule it immediately.
This can be also done from interrupt handler. You can have handler task, that is waiting on some queue. From the interrupt, you put some element to the queue. After the interrupt ends, FreeRTOS reschedules to the task waiting on that queue. There is just prerequisite to have enough high priority on that task. This has benefit, that you are not doing much in the interrupt - just some cleanup and sending item to the queue - which is short operation.
Handling interrupt can be also done by xTimerPendFunctionCallFromISR
, which is another interresting way how to handle interrupts.
Please also read about FreeRTOS fundamentals. There are several chapters about it and it is interresting reading.