Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy handler to receive the I2CSlaveAddr when don't match the IPMBAddr #215

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions port/ucontroller/nxp/lpc17xx/lpc17_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void vI2CConfig( I2C_ID_T id, uint32_t speed )

static TaskHandle_t slave_task_id;
I2C_XFER_T slave_cfg;
I2C_XFER_T slave_dummy;
uint8_t recv_msg[i2cMAX_MSG_LENGTH];
uint8_t recv_msg_dummy[i2cMAX_MSG_LENGTH];
uint8_t recv_bytes;

uint8_t xI2CSlaveReceive( I2C_ID_T id, uint8_t * rx_buff, uint8_t buff_len, uint32_t timeout )
Expand Down Expand Up @@ -138,6 +140,13 @@ static void I2C_Slave_Event(I2C_ID_T id, I2C_EVENT_T event)
}
}

/*
* This stub functions is called when the received I2C Slave Address doesn't match the
* expected IPMB address. This seems to be necessary because the lpcopen library tries
* to handle the I2C Slave configuration for I2C_SLAVE_GENERAL even if it's not configured,
* thus dereferencing an invalid unitialized pointer generating a HardFault.
*/
static void I2C_Dummy_Event(I2C_ID_T id, I2C_EVENT_T event){}

void vI2CSlaveSetup ( I2C_ID_T id, uint8_t slave_addr )
{
Expand All @@ -149,6 +158,13 @@ void vI2CSlaveSetup ( I2C_ID_T id, uint8_t slave_addr )
slave_cfg.rxBuff = &recv_msg[0];
slave_cfg.rxSz = (sizeof(recv_msg)/sizeof(recv_msg[0]));
Chip_I2C_SlaveSetup( id, I2C_SLAVE_0, &slave_cfg, I2C_Slave_Event, SLAVE_MASK);

slave_dummy.slaveAddr = 0;
slave_dummy.txBuff = NULL;
slave_dummy.txSz = 0;
slave_dummy.rxBuff = recv_msg_dummy;
slave_dummy.rxSz =(sizeof(recv_msg_dummy)/sizeof(recv_msg_dummy[0]));
Chip_I2C_SlaveSetup( id, I2C_SLAVE_GENERAL, &slave_dummy, I2C_Dummy_Event, SLAVE_MASK);
}

int xI2CMasterWriteRead(I2C_ID_T id, uint8_t addr, const uint8_t *tx_buff, int tx_len, uint8_t *rx_buff, int rx_len)
Expand Down
Loading