Complete the code to give a semaphore from an ISR.
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR( [1], &xHigherPriorityTaskWoken );The function xSemaphoreGiveFromISR() requires the semaphore handle as the first argument.
Complete the code to check if a higher priority task was woken after giving the semaphore.
if( [1] == pdTRUE ) { portYIELD_FROM_ISR(); }
The variable xHigherPriorityTaskWoken is set by xSemaphoreGiveFromISR() to indicate if a context switch is needed.
Fix the error in the ISR code to correctly give the semaphore and yield if needed.
void vISR_Handler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR( [1], &xHigherPriorityTaskWoken );
if( xHigherPriorityTaskWoken == pdTRUE ) {
portYIELD_FROM_ISR();
}
}The ISR must use xSemaphoreGiveFromISR() instead of xSemaphoreGive(). The blank should be the semaphore handle passed to xSemaphoreGiveFromISR().
Fill both blanks to correctly give a semaphore from ISR and check if a context switch is needed.
BaseType_t [1] = pdFALSE; xSemaphoreGiveFromISR( [2], &[1] ); if( [1] == pdTRUE ) { portYIELD_FROM_ISR(); }
The variable xHigherPriorityTaskWoken tracks if a higher priority task was woken. The semaphore handle xSemaphore is given from ISR.
Fill all three blanks to create a task that waits for a semaphore given from an ISR.
void vTaskFunction(void *pvParameters) {
for( ;; ) {
if( xSemaphoreTake( [1], portMAX_DELAY ) == [2] ) {
// Process event
[3]();
}
}
}The task waits indefinitely for xSemaphore. When xSemaphoreTake() returns pdTRUE, it calls handleEvent() to process the event.
