Commit 87fba8d6 authored by schneider's avatar schneider
Browse files

fix(pmic): Check pmic interrupt state from application context

Closes #13
parent d19fa787
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
#include "msc.h" #include "msc.h"
#include "descriptors.h" #include "descriptors.h"
#include "mscmem.h" #include "mscmem.h"
#include "card10.h"
/***** Definitions *****/ /***** Definitions *****/
#define EVENT_ENUM_COMP MAXUSB_NUM_EVENTS #define EVENT_ENUM_COMP MAXUSB_NUM_EVENTS
...@@ -212,6 +212,8 @@ void run_usbmsc(void) ...@@ -212,6 +212,8 @@ void run_usbmsc(void)
printf("Remote Wakeup\n"); printf("Remote Wakeup\n");
} }
} }
card10_poll();
} }
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "api/dispatcher.h" #include "api/dispatcher.h"
#include "card10.h"
extern TaskHandle_t dispatcher_task_id; extern TaskHandle_t dispatcher_task_id;
/* /*
...@@ -39,6 +41,10 @@ void post_idle_sleep(TickType_t xExpectedIdleTime) ...@@ -39,6 +41,10 @@ void post_idle_sleep(TickType_t xExpectedIdleTime)
if (api_dispatcher_poll_once()) { if (api_dispatcher_poll_once()) {
xTaskNotifyGive(dispatcher_task_id); xTaskNotifyGive(dispatcher_task_id);
} }
// Do card10 house keeping. E.g. polling the i2c devices if they triggered an interrupt
// TODO: Do this in a more task fokused way (high/low ISR)
card10_poll();
} }
void vApplicationGetIdleTaskMemory( void vApplicationGetIdleTaskMemory(
......
...@@ -185,3 +185,7 @@ void core1_stop(void) { ...@@ -185,3 +185,7 @@ void core1_stop(void) {
MXC_GCR->perckcn1 |= MXC_F_GCR_PERCKCN1_CPU1; MXC_GCR->perckcn1 |= MXC_F_GCR_PERCKCN1_CPU1;
} }
void card10_poll(void)
{
pmic_poll();
}
...@@ -12,4 +12,5 @@ void card10_diag(void); ...@@ -12,4 +12,5 @@ void card10_diag(void);
void core1_start(void); void core1_start(void);
void core1_stop(void); void core1_stop(void);
void card10_poll(void);
#endif #endif
...@@ -9,11 +9,14 @@ static const gpio_cfg_t pmic_interrupt_pin = { ...@@ -9,11 +9,14 @@ static const gpio_cfg_t pmic_interrupt_pin = {
PORT_0, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP PORT_0, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
}; };
static pmic_button_callback_fn pmic_button_callback = NULL; static pmic_button_callback_fn pmic_button_callback = NULL;
static volatile bool interrupt_pending;
void pmic_init(void) void pmic_init(void)
{ {
uint8_t didm = MAX77650_getDIDM(); uint8_t didm = MAX77650_getDIDM();
uint8_t cid = MAX77650_getChipID(); uint8_t cid = MAX77650_getChipID();
interrupt_pending = false;
printf("MAX7765x DIDM: 0x%02x CID: 0x%02x\n", didm, cid); printf("MAX7765x DIDM: 0x%02x CID: 0x%02x\n", didm, cid);
MAX77650_setIP_SBB0(0b11); //Limit switch current of SBB0 to 500mA for noise reduction MAX77650_setIP_SBB0(0b11); //Limit switch current of SBB0 to 500mA for noise reduction
...@@ -99,14 +102,23 @@ void pmic_init(void) ...@@ -99,14 +102,23 @@ void pmic_init(void)
static void pmic_interrupt_callback(void*_) static void pmic_interrupt_callback(void*_)
{ {
uint8_t int_flag = MAX77650_getINT_GLBL(); interrupt_pending = true;
}
if (int_flag & (MAX77650_INT_nEN_R | MAX77650_INT_nEN_F)) { void pmic_poll(void)
if (pmic_button_callback != NULL) { {
(*pmic_button_callback)(int_flag & MAX77650_INT_nEN_F); if(interrupt_pending) {
/* There might be a race condition here. Don't care ATM. */
interrupt_pending = false;
uint8_t int_flag = MAX77650_getINT_GLBL();
if (int_flag & (MAX77650_INT_nEN_R | MAX77650_INT_nEN_F)) {
if (pmic_button_callback != NULL) {
(*pmic_button_callback)(int_flag & MAX77650_INT_nEN_F);
}
} }
/* TODO: Other pmic interrupts */
} }
/* TODO: Other pmic interrupts */
} }
void pmic_set_button_callback(pmic_button_callback_fn cb) void pmic_set_button_callback(pmic_button_callback_fn cb)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
void pmic_init(void); void pmic_init(void);
void pmic_set_led(uint8_t led, uint8_t val); void pmic_set_led(uint8_t led, uint8_t val);
void pmic_poll(void);
typedef void (*pmic_button_callback_fn)(bool falling); typedef void (*pmic_button_callback_fn)(bool falling);
void pmic_set_button_callback(pmic_button_callback_fn cb); void pmic_set_button_callback(pmic_button_callback_fn cb);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment