Challenge - 5 Problems
ISR-safe API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of xQueueSendFromISR usage
What is the output of this code snippet when called inside an ISR?
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
QueueHandle_t xQueue = xQueueCreate(1, sizeof(int));
int value = 10;
BaseType_t result = xQueueSendFromISR(xQueue, &value, &xHigherPriorityTaskWoken);
printf("Result: %d, Woken: %d\n", result, xHigherPriorityTaskWoken);FreeRTOS
BaseType_t xHigherPriorityTaskWoken = pdFALSE; QueueHandle_t xQueue = xQueueCreate(1, sizeof(int)); int value = 10; BaseType_t result = xQueueSendFromISR(xQueue, &value, &xHigherPriorityTaskWoken); printf("Result: %d, Woken: %d\n", result, xHigherPriorityTaskWoken);
Attempts:
2 left
💡 Hint
Remember that xQueueSendFromISR returns pdTRUE (1) on success and pdFALSE (0) on failure. The Woken flag is set only if a higher priority task was unblocked.
✗ Incorrect
The queue is empty and has space, so xQueueSendFromISR returns pdTRUE (1). Since no higher priority task was waiting, xHigherPriorityTaskWoken remains pdFALSE (0).
🧠 Conceptual
intermediate1:30remaining
Purpose of the FromISR suffix in FreeRTOS API
What is the main reason FreeRTOS provides API functions with the FromISR suffix?
Attempts:
2 left
💡 Hint
Think about what restrictions exist inside ISRs.
✗ Incorrect
Functions with the FromISR suffix are designed to be safe to call from ISRs. They do not block and handle critical sections differently to avoid issues in interrupt context.
🔧 Debug
advanced2:00remaining
Identify the error in this ISR-safe queue send code
What error will occur when running this code inside an ISR?
BaseType_t xHigherPriorityTaskWoken = pdFALSE; int value = 5; xQueueSend(xQueue, &value, 0);
Attempts:
2 left
💡 Hint
Consider what happens if you call a normal API function inside an ISR.
✗ Incorrect
xQueueSend is not safe to call inside an ISR because it may block. Calling it inside an ISR can cause runtime errors or unpredictable behavior.
📝 Syntax
advanced1:30remaining
Correct usage of xSemaphoreGiveFromISR
Which option correctly uses xSemaphoreGiveFromISR to give a semaphore inside an ISR?
Attempts:
2 left
💡 Hint
Check the function signature and parameters carefully.
✗ Incorrect
xSemaphoreGiveFromISR requires a pointer to the semaphore handle and a pointer to a BaseType_t variable to indicate if a higher priority task was woken.
🚀 Application
expert2:30remaining
Determining task switch necessity after ISR
Inside an ISR, you call xQueueSendFromISR and the xHigherPriorityTaskWoken flag is set to pdTRUE. What should you do next to ensure the higher priority task runs immediately after the ISR?
Attempts:
2 left
💡 Hint
Think about how to request a context switch from an ISR.
✗ Incorrect
When xHigherPriorityTaskWoken is pdTRUE, you must call portYIELD_FROM_ISR to request a context switch immediately after the ISR ends.