fix: Corrected I3C checksum
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
|
|
||||||
|
#define OWN_ADDRESS (0x01)
|
||||||
|
|
||||||
uint8_t i3c_crc(uint8_t dst, uint8_t *msg, size_t len) {
|
uint8_t i3c_crc(uint8_t dst, uint8_t *msg, size_t len) {
|
||||||
uint8_t crc;
|
uint8_t crc;
|
||||||
crc8_init(&crc);
|
crc8_init(&crc);
|
||||||
@@ -25,6 +27,7 @@ bool i3c_validate(uint8_t *msg, size_t len)
|
|||||||
uint8_t rcvd_crc8 = msg[2];
|
uint8_t rcvd_crc8 = msg[2];
|
||||||
msg[2] = 0;
|
msg[2] = 0;
|
||||||
crc8_init(&computed_crc8);
|
crc8_init(&computed_crc8);
|
||||||
|
crc8_add(&computed_crc8, OWN_ADDRESS);
|
||||||
crc8_addSlice(&computed_crc8, msg, len);
|
crc8_addSlice(&computed_crc8, msg, len);
|
||||||
crc8_finish(&computed_crc8);
|
crc8_finish(&computed_crc8);
|
||||||
msg[2] = rcvd_crc8;
|
msg[2] = rcvd_crc8;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ void handle_incp(msg_buf_t *msgs)
|
|||||||
// Check I3C
|
// Check I3C
|
||||||
if (!i3c_validate(msg, len))
|
if (!i3c_validate(msg, len))
|
||||||
{
|
{
|
||||||
|
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
|
||||||
//return; // Ignore failed messages
|
//return; // Ignore failed messages
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ static void handle_msg(uint8_t sender, uint8_t *bytes, uint32_t len)
|
|||||||
|
|
||||||
bytes[-3] = I2C_OWN_ADDR;
|
bytes[-3] = I2C_OWN_ADDR;
|
||||||
bytes[-2] = len;
|
bytes[-2] = len;
|
||||||
bytes[-1] = i3c_crc(I2C_OWN_ADDR, bytes, len);
|
bytes[-1] = i3c_crc(sender, bytes-I3C_HEADER_SIZE, len+I3C_HEADER_SIZE);
|
||||||
I2C1_transmit_master(sender, bytes-I3C_HEADER_SIZE, len+I3C_HEADER_SIZE);
|
I2C1_transmit_master(sender, bytes-I3C_HEADER_SIZE, len+I3C_HEADER_SIZE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user