Skip to content

Commit

Permalink
PMICDRV-185: Add versions of Pmic_io{Tx,Rx}Byte which handle critical…
Browse files Browse the repository at this point in the history
… section

Add two new functions to the IO module which are duplicates of
Pmic_ioTxByte and Pmic_ioRxByte, but obtain and release critical
sections before/after performing the write/read, respectively.

These functions should be preferred for one-off reads and writes which
are not part of a larger sequence of sequential transactions.

Signed-off-by: Michael Leonard <[email protected]>
  • Loading branch information
LeonardMH committed Jul 1, 2024
1 parent 8a89fdc commit 44f6df8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/pmic_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions src/pmic_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdint.h>

#include "pmic.h"
#include "pmic_common.h"
#include "pmic_io.h"
#include "regmap/io.h"

Expand Down Expand Up @@ -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};
Expand All @@ -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;
Expand Down

0 comments on commit 44f6df8

Please sign in to comment.