PMIC
The PMIC driver provides API to control I2C based PMIC present in the board. It supports configuration of various features/modules in the PMIC. I2C controller is used to read/write to the PMIC registers. Refer to the corresponding PMIC datasheet for more details.
Features Supported
Support enable/disable watchdog
Watchdog in trigger and Q&A mode with interrupt/reset support upon failure
GPIO configuration
Thermal monitoring
Voltage monitoring
SysConfig Features
Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
Option to specify I2C address for the register pages
Toggle watchdog functionality
Watchdog mode selection
Single/dual I2C communication mode selection
Watchdog parameters configuration
Warm reset option upon watchdog failure
Features NOT Supported
ADC
CRC check for read and write
Important Usage Guidelines
Power cycle the board to restore the PMIC register configurations.
Example Usage
Include the below file to access the APIs
//! [include]
#include <board/pmic.h>
#include <board/pmic/pmic_i2c.h>
#define CONFIG_PMIC0 (0U)
#define MAIN_I2C (0U)
#define CONFIG_PMIC_NUM_INSTANCES (1U)
/* PMIC Driver handles - opened during Board_pmicOpen() */
PMIC_Handle gPmicHandle[CONFIG_PMIC_NUM_INSTANCES];
/* PMIC LLD Driver handles - opened during Pmic_init() */
Pmic_CoreHandle_t gPmicCoreHandle[CONFIG_PMIC_NUM_INSTANCES];
Pmic_CoreCfg_t gPmicCoreCfg[CONFIG_PMIC_NUM_INSTANCES] =
{
{
.pmicDeviceType = PMIC_DEV_BURTON_TPS6522X,
.slaveAddr = 0x48,
.nvmSlaveAddr = 0x49,
.qaSlaveAddr = 0x12,
.i2c1Speed = PMIC_I2C_STANDARD_MODE,
.pFnPmicCommIoRead = &PMIC_i2cRead,
.pFnPmicCommIoWrite = &PMIC_i2cWrite,
.validParams = (PMIC_CFG_DEVICE_TYPE_VALID_SHIFT | PMIC_CFG_COMM_MODE_VALID_SHIFT | \
PMIC_CFG_SLAVEADDR_VALID_SHIFT | PMIC_CFG_QASLAVEADDR_VALID_SHIFT | \
PMIC_CFG_NVMSLAVEADDR_VALID_SHIFT | PMIC_CFG_COMM_IO_RD_VALID_SHIFT | \
PMIC_CFG_COMM_IO_WR_VALID_SHIFT | PMIC_CFG_I2C1_SPEED_VALID_SHIFT | \
PMIC_CFG_CRITSEC_START_VALID_SHIFT | PMIC_CFG_CRITSEC_STOP_VALID_SHIFT),
.instType = PMIC_MAIN_INST,
.commMode = PMIC_INTF_SINGLE_I2C,
.pFnPmicCritSecStart = &PMIC_critSecStartFn,
.pFnPmicCritSecStop = &PMIC_critSecStopFn,
},
};
/* PMIC Config */
PMIC_Config gPmicConfig[CONFIG_PMIC_NUM_INSTANCES] =
{
{
.pmicConfigData = (Pmic_CoreCfg_t *)&gPmicCoreCfg[CONFIG_PMIC0],
.pmicCoreHandle = (Pmic_CoreHandle_t *)&gPmicCoreHandle[CONFIG_PMIC0],
},
};
/* PMIC params */
PMIC_Params gPmicParams[CONFIG_PMIC_NUM_INSTANCES] =
{
{
.mainDrvinstance = MAIN_I2C,
},
};
uint32_t gPmicConfigNum = CONFIG_PMIC_NUM_INSTANCES;
//! [include]
Instance Open Example
//! [open]
PMIC_init();
gPmicHandle[CONFIG_PMIC0] = NULL;
gPmicHandle[CONFIG_PMIC0] = PMIC_open(CONFIG_PMIC0, &gPmicParams[CONFIG_PMIC0]);
if (!gPmicHandle[CONFIG_PMIC0])
{
DebugP_assert(FALSE);
}
//! [open]
Instance Close Example
//! [close]
PMIC_close(gPmicHandle[CONFIG_PMIC0]);
//! [close]
GPIO pin configuration example
//! [pmic_gpio_config]
/* Configure a GPIO pin in the PMIC */
int32_t status = PMIC_ST_SUCCESS;
Pmic_GpioCfg_t gpioCfg =
{
.pinDir = PMIC_GPIO_INPUT,
.pinFunc = PMIC_TPS6522X_GPIO_PINFUNC_GPIO6_NERR_MCU,
.pullCtrl = PMIC_GPIO_PULL_DOWN,
.deglitchEnable = PMIC_GPIO_DEGLITCH_ENABLE,
};
status = Pmic_gpioSetConfiguration(gPmicConfig[CONFIG_PMIC0].pmicCoreHandle, \
PMIC_TPS6522X_GPIO6_PIN, gpioCfg);
if (PMIC_ST_SUCCESS != status)
{
DebugP_assert(FALSE);
}
//! [pmic_gpio_config]
API Reference
Typedefs
-
typedef void *PMIC_Handle
Handle to the PMIC driver returned by PMIC_open()
Functions
-
void PMIC_init(void)
This function initializes the PMIC module.
-
void PMIC_deinit(void)
This function de-initializes the PMIC module.
-
PMIC_Handle PMIC_open(uint32_t instanceId, const PMIC_Params *params)
Open PMIC driver.
Make sure the SOC peripheral driver is open’ed before calling this API. Drivers_open function generated by SysCfg opens the underlying SOC peripheral driver, e.g I2C
Global variables
PMIC_Config gPmicConfig[]anduint32_t gPmicConfigNumis instantiated by SysCfg to describe the PMIC configuration based on user selection in SysCfg.- Parameters:
instanceId – [IN] Index within
PMIC_Config gPmicConfig[]denoting the PMIC driver to openparams – [IN] Open parameters
- Returns:
Handle to PMIC driver which should be used in subsequent API call Else returns NULL in case of failure
-
PMIC_Handle PMIC_getHandle(uint32_t instanceId)
Get handle to PMIC driver.
- Parameters:
instanceId – [in] Index within
PMIC_Config gPmicConfig[]- Returns:
Handle to pmic driver
- Returns:
NULL in case of failure
-
void PMIC_close(PMIC_Handle handle)
Close PMIC driver.
- Parameters:
handle – [IN] PMIC driver handle from PMIC_open
-
void PMIC_critSecStartFn(void)
Initiates the start of a critical section for PMIC operations. This function attempts to acquire a semaphore, which is typically used to ensure exclusive access to resources during PMIC operations.
-
void PMIC_critSecStopFn(void)
Concludes a critical section for PMIC operations. This function releases the semaphore, signifying the end of a critical section initiated by a corresponding “start” function.
-
struct PMIC_Config
- #include <pmic.h>
PMIC driver configuration, these are filled by SysCfg based on the device that is selected.
Public Members
-
Pmic_CoreCfg_t *pmicConfigData
Configuration data used to initialize PMIC
-
Pmic_CoreHandle_t *pmicCoreHandle
PMIC LLD driver handle, used to maintain driver implementation state
-
uint8_t wdogMode
Watchdog mode - Trigger/Q&A
-
uint8_t trigWdogPin
Trigger watchdog input signal GPIO pin number
-
uint8_t trigWdogPinFunc
Trigger watchdog input signal GPIO pin function
-
uint8_t qaWdogpin1
Q&A watchdog GPIO pin-1 number
-
uint8_t qaWdogpin2
Q&A watchdog GPIO pin-2 number
-
uint8_t qaWdogpin1Func
Q&A watchdog GPIO pin-1 fucntion
-
uint8_t qaWdogpin2Func
Q&A watchdog GPIO pin-2 fucntion
-
Pmic_CoreCfg_t *pmicConfigData
-
struct PMIC_Params
- #include <pmic.h>
Parameters passed during PMIC_open()