diff --git a/include/pmic_io.h b/include/pmic_io.h index e959037..ec1ae76 100644 --- a/include/pmic_io.h +++ b/include/pmic_io.h @@ -71,6 +71,21 @@ extern "C" { */ int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData); +/** + * @ingroup DRV_PMIC_IO_MODULE + * @brief Write a byte to the given PMIC `regAddr`, performing CRC on + * communications if necessary and enabled. Additionally, obtain and release a + * critical section before/after the write. + * + * @param handle [IN] PMIC Interface Handle + * @param regAddr [IN] Register address to write to + * @param txData [IN] Data to send to `regAddr` + * + * @return PMIC_ST_SUCCESS in case of success or appropriate error code. For + * possible values, see @ref Pmic_ErrorCodes. + */ +int32_t Pmic_ioTxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData); + /** * @ingroup DRV_PMIC_IO_MODULE * @brief Read a byte from the given PMIC `regAddr`, extracting the desired @@ -85,6 +100,21 @@ int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txDat */ int32_t Pmic_ioRxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *rxBuffer); +/** + * @ingroup DRV_PMIC_IO_MODULE + * @brief Read a byte from the given PMIC `regAddr`, extracting the desired + * register data from the CRC framed data returned by the PMIC. Additionally, + * obtain and release a critical section before/after the read. + * + * @param handle [IN] PMIC Interface Handle + * @param regAddr [IN] Register address to read from + * @param rxBuffer [IN] Buffer to store result data in + * + * @return PMIC_ST_SUCCESS in case of success or appropriate error code. For + * possible values, see @ref Pmic_ErrorCodes. + */ +int32_t Pmic_ioRxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *rxBuffer); + /** * @ingroup DRV_PMIC_IO_MODULE * @brief Determine whether I2C CRC is enabled or disabled. diff --git a/src/pmic_io.c b/src/pmic_io.c index 8206588..52f2bd8 100644 --- a/src/pmic_io.c +++ b/src/pmic_io.c @@ -37,6 +37,7 @@ #include #include "pmic.h" +#include "pmic_common.h" #include "pmic_io.h" #include "regmap/io.h" @@ -84,6 +85,16 @@ int32_t Pmic_ioRxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *pRxB return status; } +int32_t Pmic_ioRxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t *rxBuffer) { + int32_t status; + + Pmic_criticalSectionStart(handle); + status = Pmic_ioRxByte(handle, regAddr, rxBuffer); + Pmic_criticalSectionStop(handle); + + return status; +} + int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData) { /* Set write data to txBuf[2], with WDATA[7:0] */ uint8_t txBuf[PMIC_IO_BUF_SIZE] = {0U, 0U, txData, 0U}; @@ -104,6 +115,16 @@ int32_t Pmic_ioTxByte(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txDat return handle->pFnPmicCommIoWr(handle, (uint8_t)PMIC_MAIN_INST, regAddr, &txBuf[0], frameSize); } +int32_t Pmic_ioTxByte_CS(Pmic_CoreHandle_t *handle, uint16_t regAddr, uint8_t txData) { + int32_t status; + + Pmic_criticalSectionStart(handle); + status = Pmic_ioTxByte(handle, regAddr, txData); + Pmic_criticalSectionStop(handle); + + return status; +} + int32_t Pmic_ioGetCrcEnableState(Pmic_CoreHandle_t *handle, bool *isEnabled) { int32_t status = Pmic_checkPmicCoreHandle(handle); uint8_t regData = 0U;