Skip to content

Commit 73d87d5

Browse files
Aymane-STfpistm
authored andcommitted
fix(i3c): mark dynamically assigned addresses as used during DAA
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent cc1bdb8 commit 73d87d5

1 file changed

Lines changed: 11 additions & 38 deletions

File tree

‎libraries/I3C/src/I3C.cpp‎

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -617,24 +617,18 @@ int I3CBus::readReg(uint8_t dynAddr,
617617
bool I3CBus::isI2CDeviceReady(uint8_t addr, uint32_t trials, uint32_t timeout)
618618
{
619619
bool result = false;
620-
621620
if (_initialized) {
622-
HAL_StatusTypeDef st = HAL_I3C_Ctrl_IsDeviceI2C_Ready(&_hi3c, addr, trials, timeout);
623-
result = (st == HAL_OK);
621+
result = (HAL_I3C_Ctrl_IsDeviceI2C_Ready(&_hi3c, addr, trials, timeout) == HAL_OK);
624622
}
625-
626623
return result;
627624
}
628625

629626
bool I3CBus::isI3CDeviceReady(uint8_t dynAddr, uint32_t trials, uint32_t timeout)
630627
{
631628
bool result = false;
632-
633629
if (_initialized) {
634-
HAL_StatusTypeDef st = HAL_I3C_Ctrl_IsDeviceI3C_Ready(&_hi3c, dynAddr, trials, timeout);
635-
result = (st == HAL_OK);
630+
result = (HAL_I3C_Ctrl_IsDeviceI3C_Ready(&_hi3c, dynAddr, trials, timeout) == HAL_OK);
636631
}
637-
638632
return result;
639633
}
640634

@@ -676,11 +670,9 @@ bool I3CBus::cccBroadcastWrite(uint8_t cccId,
676670
COUNTOF(ccc),
677671
option) == HAL_OK);
678672

679-
if (st == HAL_OK) {
680-
st = HAL_I3C_Ctrl_TransmitCCC(&_hi3c, &context, timeout);
681-
if (st == HAL_OK) {
682-
result = true;
683-
} else {
673+
if (result) {
674+
result = (HAL_I3C_Ctrl_TransmitCCC(&_hi3c, &context, timeout) == HAL_OK);
675+
if (!result) {
684676
uint32_t err = HAL_I3C_GetError(&_hi3c);
685677
if ((err & HAL_I3C_ERROR_CE2) != 0U) {
686678
result = true;
@@ -734,11 +726,8 @@ bool I3CBus::cccDirectWrite(uint8_t targetAddr,
734726
COUNTOF(ccc),
735727
option) == HAL_OK);
736728

737-
if (st == HAL_OK) {
738-
st = HAL_I3C_Ctrl_TransmitCCC(&_hi3c, &context, timeout);
739-
if (st == HAL_OK) {
740-
result = true;
741-
}
729+
if (result) {
730+
result = (HAL_I3C_Ctrl_TransmitCCC(&_hi3c, &context, timeout) == HAL_OK);
742731
}
743732
}
744733
}
@@ -780,11 +769,8 @@ bool I3CBus::cccDirectRead(uint8_t targetAddr,
780769
COUNTOF(ccc),
781770
I3C_DIRECT_WITHOUT_DEFBYTE_RESTART) == HAL_OK);
782771

783-
if (st == HAL_OK) {
784-
st = HAL_I3C_Ctrl_ReceiveCCC(&_hi3c, &context, timeout);
785-
if (st == HAL_OK) {
786-
result = true;
787-
}
772+
if (result) {
773+
result = (HAL_I3C_Ctrl_ReceiveCCC(&_hi3c, &context, timeout) == HAL_OK);
788774
}
789775
}
790776

@@ -947,21 +933,9 @@ void I3CBus::initAddressMap()
947933

948934
bool I3CBus::isValidUsableDynamicAddr(uint8_t addr) const
949935
{
950-
bool result = true;
951-
952-
if ((addr == 0U) || (addr >= 0x7EU)) {
953-
result = false;
954-
}
955-
956-
if (result && ((addr & 0x01U) != 0U)) {
957-
result = false;
958-
}
959-
960-
return result;
936+
return (((addr != 0U) && (addr < 0x7EU)) && (addr & 0x01U) == 0U);
961937
}
962938

963-
964-
965939
bool I3CBus::isAddrFree(uint8_t addr) const
966940
{
967941
return (addr < 128U) && (_addrMap[addr] == I3CAddrState::Free);
@@ -974,8 +948,6 @@ void I3CBus::markAddrUsed(uint8_t addr)
974948
}
975949
}
976950

977-
978-
979951
void I3CBus::markAddrFree(uint8_t addr)
980952
{
981953
if ((addr < 128U) && (addr != 0x00U) && (addr != 0x7EU) && (addr != 0x7FU)) {
@@ -1042,6 +1014,7 @@ int I3CBus::assignDynamicAddresses(I3CDiscoveredDevice *devices,
10421014
result = -3;
10431015
stop = true;
10441016
} else {
1017+
markAddrUsed(da);
10451018
devices[count].dynAddr = da;
10461019
count++;
10471020
}

0 commit comments

Comments
 (0)