Use a queue's FromISR API: in the interrupt handler, after reading the data from the peripheral, call xQueueSendFromISR(queue, &item, &higherPriorityTaskWoken) to enqueue it, then on ISR exit call portYIELD_FROM_ISR(higherPriorityTaskWoken) so that if the send unblocked a higher-priority task, the scheduler switches to it immediately. A consumer task sits blocked on xQueueReceive(queue, &item, portMAX_DELAY) and wakes to process each item. This is the deferred-interrupt pattern carrying a payload: the ISR stays minimal (read the byte/sample, enqueue, return), and the actual processing happens in a task that's blocked (using no CPU) until data arrives. The mandatory rules are that you must use the FromISR variant (the normal xQueueSend cannot be called from interrupt context), you must not call any blocking or non-FromISR API in the ISR, and you keep the ISR short. If items can arrive faster than the task drains them, the queue depth must be sized to absorb the worst-case burst, or you decide a drop/overwrite policy. This is the same structure as signaling with a semaphore-from-ISR, except the queue conveys the actual data, not just the fact that an event occurred.
RTOS & Real-Time Concepts · Interview question
How do you pass data from an ISR to a task?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Queues & Inter-Task Communication
Passing data between tasks safely: a kernel queue is a thread-safe blocking FIFO (copy-by-value), the RTOS producer/consumer pattern that replaces shared-global-plus-mutex with message passing.
More Queues & Inter-Task Communication questions
Why use a queue instead of a shared global protected by a mutex?What are the copy semantics of a FreeRTOS queue, and when do you send a pointer instead?What goes wrong if you queue a pointer to a local variable?Besides queues, what inter-task communication primitives does an RTOS offer, and when would you use them?
Browse all 472 interview questions