Skip to content

Commit

Permalink
I2C HAL: Add FFE CSR check after TXRX command.
Browse files Browse the repository at this point in the history
Signed-off-by: Szymon Duchniewicz <szduchniewicz@gmail.com>
  • Loading branch information
Willmish committed Jul 17, 2023
1 parent 7212769 commit 015be1b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions HAL/src/eoss3_hal_i2c.c
Expand Up @@ -42,6 +42,11 @@
volatile unsigned int _delayCycleCount = _x_; \
while (_delayCycleCount--); \
} while(0)
#define MAX_CYCLES_FFE 50 // how many cycles to wait after each write to TXRX data register for i2c, for FFE to stop being busy - pick up the data and transmit to the i2c device (otherwise will fail on next transmission function)
#define waitFFEReady(_x_) for (int i = 0; i != _x_; i++) \
if (!((EXT_REGS_FFE->CSR & WB_CSR_BUSY) \
|| (EXT_REGS_FFE->CSR & WB_CSR_MASTER_START)))\
break;

/* This variable holds I2C status */
I2C_State eI2CState = I2C_RESET;
Expand Down Expand Up @@ -179,6 +184,7 @@ HAL_StatusTypeDef HAL_I2C_Write(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -205,6 +211,7 @@ HAL_StatusTypeDef HAL_I2C_Write(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -234,6 +241,7 @@ HAL_StatusTypeDef HAL_I2C_Write(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -255,6 +263,7 @@ HAL_StatusTypeDef HAL_I2C_Write(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_STOP_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -297,6 +306,7 @@ HAL_StatusTypeDef HAL_I2C_Read(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -324,6 +334,7 @@ HAL_StatusTypeDef HAL_I2C_Read(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_STOP_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -344,6 +355,7 @@ HAL_StatusTypeDef HAL_I2C_Read(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -437,6 +449,7 @@ HAL_StatusTypeDef HAL_I2C_Read16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT8
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -464,6 +477,7 @@ HAL_StatusTypeDef HAL_I2C_Read16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT8
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -483,6 +497,7 @@ HAL_StatusTypeDef HAL_I2C_Read16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT8
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_STOP_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -503,6 +518,7 @@ HAL_StatusTypeDef HAL_I2C_Read16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT8
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -597,6 +613,7 @@ HAL_StatusTypeDef HAL_I2C_Write16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with start condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_START_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -624,6 +641,7 @@ HAL_StatusTypeDef HAL_I2C_Write16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -644,6 +662,7 @@ HAL_StatusTypeDef HAL_I2C_Write16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down Expand Up @@ -673,6 +692,7 @@ HAL_StatusTypeDef HAL_I2C_Write16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand All @@ -694,6 +714,7 @@ HAL_StatusTypeDef HAL_I2C_Write16(UINT8_t ucDevAddress, UINT16_t ucAddress, UINT
eI2CState = I2C_READY;
return HAL_ERROR;
}
waitFFEReady(MAX_CYCLES_FFE);

/* Generate command with stop condition and write cycle */
if(HAL_WB_Transmit(I2C_CMD_SR, CMD_STOP_BIT | CMD_WRITE_SLAVE_BIT, ucI2CSlaveID) != HAL_OK)
Expand Down

0 comments on commit 015be1b

Please sign in to comment.