Skip to content

Commit

Permalink
ARMmbed#114 Add busy error code to I2C transactions when the response…
Browse files Browse the repository at this point in the history
… hasn't been attended

Uprev I2C protocl version
  • Loading branch information
gerargz committed Aug 16, 2021
1 parent 9d09263 commit 40c0e30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion source/board/microbitv2/i2c_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size);
static void i2c_read_flash_callback(uint8_t* pData, uint8_t size);

static void i2c_slave_callback(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData) {
i2cCommand_t i2cResponse = {0};

switch (xfer->event)
{
/* Address match event */
Expand Down Expand Up @@ -101,6 +103,13 @@ static void i2c_slave_callback(I2C_Type *base, i2c_slave_transfer_t *xfer, void
xfer->data = g_slave_RX_buff;
xfer->dataSize = I2C_DATA_LENGTH;
g_SlaveRxFlag = true;

// Clear transmit Buffer in IRQ. It will be filled when the task attends the I2C event
i2c_clearBuffer();
// Add busy error code
i2cResponse.cmdId = gErrorResponse_c;
i2cResponse.cmdData.errorRspCmd.errorCode = gErrorBusy_c;
i2c_fillBuffer((uint8_t*) &i2cResponse, 0, sizeof(i2cResponse));
break;

/* Transfer done */
Expand Down Expand Up @@ -276,7 +285,7 @@ static void i2c_write_comms_callback(uint8_t* pData, uint8_t size) {
memcpy(&i2cResponse.cmdData.readRspCmd.data, &board_id_hex, sizeof(board_id_hex));
break;
case gI2CProtocolVersion_c: {
uint16_t i2c_version = 1;
uint16_t i2c_version = 2;
i2cResponse.cmdData.readRspCmd.dataSize = sizeof(i2c_version);
memcpy(&i2cResponse.cmdData.readRspCmd.data, &i2c_version, sizeof(i2c_version));
}
Expand Down
3 changes: 2 additions & 1 deletion source/board/microbitv2/i2c_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ typedef enum errorCode_tag {
gErrorWrongPropertySize_c = 0x35,
gErrorReadDisallowed_c = 0x36,
gErrorWriteDisallowed_c = 0x37,
gErrorWriteFail_c = 0x38
gErrorWriteFail_c = 0x38,
gErrorBusy_c = 0x39
} errorCode_t;

typedef __PACKED_STRUCT readReqCmd_tag {
Expand Down

0 comments on commit 40c0e30

Please sign in to comment.