Consider a FreeRTOS system where an interrupt service routine (ISR) defers processing to a task using a queue. What will be the output of the following code snippet when the interrupt triggers?
#include "FreeRTOS.h" #include "task.h" #include "queue.h" QueueHandle_t xQueue; void vDeferredTask(void *pvParameters) { int receivedValue; while(1) { if(xQueueReceive(xQueue, &receivedValue, portMAX_DELAY) == pdPASS) { printf("Processed value: %d\n", receivedValue); } } } void vISR_Handler(void) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; int valueToSend = 42; xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } int main() { xQueue = xQueueCreate(5, sizeof(int)); xTaskCreate(vDeferredTask, "DeferredTask", 1000, NULL, 1, NULL); vISR_Handler(); vTaskStartScheduler(); return 0; }
Think about how the ISR sends data to the queue and how the task waits for data.
The ISR sends the value 42 to the queue using xQueueSendFromISR. The deferred task waits on the queue and prints the received value. Thus, the output is Processed value: 42.
Which of the following is the main advantage of using deferred interrupt processing in an embedded system?
Consider how deferring work affects interrupt latency and system responsiveness.
Deferred interrupt processing keeps ISRs short by moving heavy work to tasks. This reduces interrupt latency and improves responsiveness. It does not eliminate priorities or guarantee strict order.
In a FreeRTOS system, a deferred interrupt processing task reads from a queue filled by an ISR. The system sometimes crashes with a stack overflow error. Which code snippet below most likely causes this issue?
void vISR_Handler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int valueToSend = 100;
for(int i = 0; i < 10; i++) {
xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken);
}
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}Think about what happens if the ISR sends more items than the queue can hold.
Sending multiple items rapidly without checking queue space can overflow the queue, causing memory corruption or stack overflow in the task. The other options are either incorrect or unrelated to the crash.
Which option contains a syntax error that prevents the deferred interrupt processing code from compiling?
void vISR_Handler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE
int valueToSend = 10;
xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}Look carefully at each line for missing punctuation.
The line initializing xHigherPriorityTaskWoken is missing a semicolon, causing a syntax error. Other options describe logical or API misuse, not syntax errors.
You need to design a deferred interrupt processing system in FreeRTOS where two ISRs with different priorities defer work to tasks. The high priority ISR defers critical data, and the low priority ISR defers less critical data. Which design approach below best ensures that critical data is processed first without blocking the system?
Consider how task priorities and separate queues affect processing order and responsiveness.
Using two queues and two tasks with priorities matching ISR criticality ensures critical data is processed first. A high priority task will preempt the low priority task, maintaining responsiveness. Other options risk delays or complex priority handling inside tasks.