Skip to content

Commit 5e21717

Browse files
DatanoiseTVVorrad
authored andcommitted
fix(i2c_master): yield from ISR when no matching device is found
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via `xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and `xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup returns no matching device, the function returned directly, skipping the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher- priority task waiting on the bus mux or the event queue would then have to wait for the next scheduler tick instead of being preempted into immediately, inflating worst-case event latency. Replace the early return with a goto to the existing yield check at the end of the ISR. Merges #18569
1 parent cb4a55a commit 5e21717

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

components/esp_driver_i2c/i2c_master.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,10 @@ static void i2c_master_isr_handler_default(void *arg)
828828
}
829829
xSemaphoreGiveFromISR(i2c_master->bus_lock_mux, &HPTaskAwoken);
830830
if (i2c_dev == NULL) {
831-
return;
831+
// HPTaskAwoken may have been set by xQueueSendFromISR / xSemaphoreTakeFromISR /
832+
// xSemaphoreGiveFromISR above; fall through to the yield check at the end of
833+
// the ISR rather than returning directly.
834+
goto out;
832835
}
833836
i2c_master_event_data_t evt = {
834837
.event = i2c_master->event,
@@ -866,6 +869,7 @@ static void i2c_master_isr_handler_default(void *arg)
866869
xSemaphoreGiveFromISR(i2c_master->cmd_semphr, &HPTaskAwoken);
867870
}
868871

872+
out:
869873
if (HPTaskAwoken == pdTRUE) {
870874
portYIELD_FROM_ISR();
871875
}

0 commit comments

Comments
 (0)