0
0
FreeRTOSprogramming~20 mins

ISR-safe API functions (FromISR suffix) in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ISR-safe API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AResult: 1, Woken: 1
BResult: 0, Woken: 1
CResult: 1, Woken: 0
DResult: 0, Woken: 0
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.
🧠 Conceptual
intermediate
1:30remaining
Purpose of the FromISR suffix in FreeRTOS API
What is the main reason FreeRTOS provides API functions with the FromISR suffix?
AThey allow blocking calls inside ISRs.
BThey are optimized for use in interrupt service routines and do not block.
CThey disable all interrupts globally.
DThey automatically create tasks from ISRs.
Attempts:
2 left
💡 Hint
Think about what restrictions exist inside ISRs.
🔧 Debug
advanced
2: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);
ACompile error: Missing FromISR suffix function.
BNo error; code runs correctly.
CQueue overflow error.
DRuntime error: Blocking call inside ISR.
Attempts:
2 left
💡 Hint
Consider what happens if you call a normal API function inside an ISR.
📝 Syntax
advanced
1:30remaining
Correct usage of xSemaphoreGiveFromISR
Which option correctly uses xSemaphoreGiveFromISR to give a semaphore inside an ISR?
AxSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
BxSemaphoreGiveFromISR(&xSemaphore, &xHigherPriorityTaskWoken);
CxSemaphoreGiveFromISR(xSemaphore);
DxSemaphoreGiveFromISR(xSemaphore, NULL);
Attempts:
2 left
💡 Hint
Check the function signature and parameters carefully.
🚀 Application
expert
2: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?
ACall portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
BCall vTaskDelay(1);
CDo nothing; the scheduler will switch tasks automatically.
DCall xTaskResumeAll();
Attempts:
2 left
💡 Hint
Think about how to request a context switch from an ISR.