Skip to content

Commit

Permalink
PMICDRV-173: Support IRQ / Error Status
Browse files Browse the repository at this point in the history
Adds support for the IRQ module which allows for
configuration (masking/unmasking), reading, and clearing of interrupt
sources on LP8772X PMIC.

Signed-off-by: Michael Leonard <[email protected]>
  • Loading branch information
LeonardMH committed Jul 1, 2024
1 parent 44f6df8 commit eb75582
Show file tree
Hide file tree
Showing 8 changed files with 1,333 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ SOURCES = \
src/pmic.c \
src/pmic_common.c \
src/pmic_core.c \
src/pmic_wdg.c \
src/pmic_io.c
src/pmic_io.c \
src/pmic_irq.c \
src/pmic_wdg.c

OBJECTS = $(SOURCES:.c=.o)

Expand Down
50 changes: 47 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ Pmic_CoreCfg_t coreCfg = {
.pmicDeviceType = PMIC_DEV_COACH_LP8772X,
.commMode = PMIC_INTF_I2C_SINGLE,
.crcEnable = PMIC_ENABLE,
.configCrcEnable = PMIC_ENABLE,
.configCrcEnable = PMIC_DISABLE,
.slaveAddr = <Device I2C Address>,
.pCommHandle = &commHandle,
.pFnPmicCommIoRead = PmicCommIoRead,
.pFnPmicCommIoWrite = PmicCommIoWrite,
.pFnPmicCommIoRd = PmicCommIoRead,
.pFnPmicCommIoWr = PmicCommIoWrite,
.pFnPmicCritSecStart = CritSecStart,
.pFnPmicCritSecStop = CritSecStop,
};
Expand Down Expand Up @@ -192,3 +192,47 @@ reporting for PMIC watchdog features, and supports calculation and response for
Q&A watchdog mode.

See `include/pmic_wdg.h` for more information on these APIs.

### IRQ Mask Control, Status Read, and Clear

The IRQ module for the PMIC driver supports masking (disable) and un-masking
(enable) of individual interrupt sources on the PMIC, supports reading the
status of all interrupts using an optimal algorithm based on the heirarchical
structure of the IRQs, and supports clearing individual IRQs as handled or all
at once.

See `include/pmic_irq.h` for more information on these APIs.

#### IRQ Status Read and Clear Example

A common pattern for end-user is to recieve an nINT interrupt on the MCU, check
IRQ status on the PMIC, handle relevant interrupts, and then clear these IRQ
sources. An example of how this can be done using the pmic-lld APIs is shown
below:

``` c
// Create IRQ status structure
Pmic_IrqStat_t irqStat;

// Reads all IRQ status registers (optimally, only if relevant), and populates
// `irqStat` with information necessary for further processing
pmicStatus = Pmic_irqGetStat(&pmicHandle, &irqStat);

void HandleIrqNum(uint8 irqNum) {
// User implemented function to handle IRQs as desired
}

if (pmicStatus == PMIC_ST_SUCCESS) {
uint8_t irqFlagStat;
uint8_t irqNum;

do {
irqFlagStat = Pmic_irqGetNextFlag(&irqStat, &irqNum);

if (irqFlagStat == PMIC_ST_SUCCESS) {
HandleIrqNum(irqNum);
Pmic_irqClrFlag(&pmicHandle, irqNum);
}
} while (irqFlagStat == PMIC_ST_SUCCESS);
}
```
13 changes: 13 additions & 0 deletions include/pmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#include "pmic_core.h"
#include "pmic_io.h"
#include "pmic_irq.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -136,7 +137,9 @@ extern "C" {
#define PMIC_ST_ERR_DATA_IO_CRC (-((int32_t)10))
#define PMIC_ST_ERR_INTF_SETUP_FAILED (-((int32_t)11))
#define PMIC_ST_ERR_COMM_INTF_INIT_FAIL (-((int32_t)12))
#define PMIC_ST_ERR_NOT_SUPPORTED (-((int32_t)13))
#define PMIC_ST_WARN_INV_DEVICE_ID (-((int32_t)40))
#define PMIC_ST_WARN_NO_IRQ_REMAINING (-((int32_t)41))
/** @} */

/**
Expand All @@ -149,6 +152,16 @@ extern "C" {
#define PMIC_DISABLE ((bool)false)
/** @} */

/**
* @anchor Pmic_IrqMaskControl
* @name PMIC IRQ Mask Control
*
* @{
*/
#define PMIC_IRQ_MASK ((bool)true)
#define PMIC_IRQ_UNMASK ((bool)false)
/** @} */

/**
* @anchor Pmic_DeviceType
* @name PMIC Device type
Expand Down
5 changes: 5 additions & 0 deletions include/pmic_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
extern "C" {
#endif

/*==========================================================================*/
/* Macros & Typedefs */
/*==========================================================================*/
#define COUNT(x) (sizeof(x) / sizeof(x[0]))

/*==========================================================================*/
/* Structures and Enums */
/*==========================================================================*/
Expand Down
Loading

0 comments on commit eb75582

Please sign in to comment.