Skip to content

Commit

Permalink
Implement bug fixes found through running core_test.c
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnBuiTI authored and LeonardMH committed Aug 14, 2024
1 parent dd2ebf0 commit 58d283b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/pmic_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ int32_t Pmic_setRegLock(const Pmic_CoreHandle_t *pmicHandle, bool lock)

int32_t Pmic_unlockRegs(const Pmic_CoreHandle_t *pmicHandle)
{
return Pmic_setRegLock(pmicHandle, PMIC_LOCK);
return Pmic_setRegLock(pmicHandle, PMIC_UNLOCK);
}

int32_t Pmic_lockRegs(const Pmic_CoreHandle_t *pmicHandle)
{
return Pmic_setRegLock(pmicHandle, PMIC_UNLOCK);
return Pmic_setRegLock(pmicHandle, PMIC_LOCK);
}
6 changes: 3 additions & 3 deletions src/pmic_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static uint8_t findInverse(uint8_t num)
{
uint8_t inverse = 0U;

for (uint8_t i = 0U; i < 4U; i++)
for (uint8_t i = 0U; i < 8U; i++)
{
if ((num & (1U << i)) != 0U)
{
Expand Down Expand Up @@ -193,14 +193,14 @@ int32_t Pmic_ioRx(const Pmic_CoreHandle_t *pmicHandle, uint8_t regAddr, uint8_t
// Index 0 is most significant byte, last index is the least significant byte
i2cFrame[0U] = (uint8_t)((pmicHandle->i2cAddr & 0x7FU) << 1U);
i2cFrame[1U] = regAddr;
i2cFrame[2U] = (uint8_t)((pmicHandle->i2cAddr & 0x7FU) | 1U);
i2cFrame[2U] = (uint8_t)(((pmicHandle->i2cAddr & 0x7FU) << 1U) | 1U);
i2cFrameLen = (pmicHandle->crcEnable == PMIC_ENABLE) ? 5U : 4U;

// Begin read exchange. Data will be stored beginning at i2cFrame[3U]
status = pmicHandle->ioRead(pmicHandle, regAddr, i2cFrameLen - 3U, &i2cFrame[3U]);
}

// If read exchange was good and PMIC CRC is enabled, compare SCRC to expected CRC
// If read exchange was successful and PMIC CRC is enabled, compare SCRC to expected CRC
if ((status == PMIC_ST_SUCCESS) && (pmicHandle->crcEnable == PMIC_ENABLE))
{
// i2cFrame[0U] - Target device I2C address with write bit
Expand Down
19 changes: 15 additions & 4 deletions test/core_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ void coreTest(void *args)

if (status == PMIC_ST_SUCCESS)
{
DebugP_log("Running PMIC Core tests...\r\n");
UNITY_BEGIN();
RUN_CORE_TESTS();
UNITY_END();
status = Pmic_unlockRegs(&pmicHandle);

if (status == PMIC_ST_SUCCESS)
{
DebugP_log("Running PMIC Core tests...\r\n");

UNITY_BEGIN();
RUN_CORE_TESTS();
UNITY_END();
}
else
{
DebugP_log("Failed to unlock PMIC registers\r\n");
DebugP_log("\tStatus code: %d\r\n", status);
}
}
else
{
Expand Down

0 comments on commit 58d283b

Please sign in to comment.