1
0
forked from me/IronOS

Refactor I2C result to use notifications, allowing faster task yield

So that one I2C done, task can directly swap and pickup later if I2C is blocking
This commit is contained in:
Ben V. Brown
2025-02-22 17:33:33 +11:00
parent 622d8aac07
commit 0ed2d84fca

View File

@@ -122,7 +122,8 @@ void FRToSI2C::CpltCallback() {
// Unlock the semaphore && allow task switch if desired by RTOS // Unlock the semaphore && allow task switch if desired by RTOS
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(IRQTaskWaitingHandle, &xHigherPriorityTaskWoken); xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken);
xTaskNotifyFromISR(IRQTaskWaitingHandle, IRQFailureMarker ? 2 : 1, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
} }
@@ -168,11 +169,9 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b
I2C_Enable(I2C0_ID); I2C_Enable(I2C0_ID);
// Wait for transfer in background // Wait for transfer in background
ulTaskNotifyTake(pdTRUE, TICKS_100MS); uint32_t result = 0;
xTaskNotifyWait(0xFFFFFFFF, 0xFFFFFFFF, &result, TICKS_100MS);
bool ok = !IRQFailureMarker; // Capture before unlock so it doesnt get overwritten return result == 1;
unlock();
return ok;
} }
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) { bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) {
@@ -211,11 +210,9 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu
I2C_Enable(I2C0_ID); I2C_Enable(I2C0_ID);
// Wait for transfer in background // Wait for transfer in background
ulTaskNotifyTake(pdTRUE, TICKS_100MS); uint32_t result = 0;
xTaskNotifyWait(0xFFFFFFFF, 0xFFFFFFFF, &result, TICKS_100MS);
bool ok = !IRQFailureMarker; // Capture before unlock so it doesnt get overwritten return result == 1;
unlock();
return ok;
} }
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); } bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); }