diff --git a/epicardium/modules/modules.h b/epicardium/modules/modules.h index 5a074273748019293f30c6ae299c830a019c497c..a66d8285cae6ecefc991696fa94f424a792577ed 100644 --- a/epicardium/modules/modules.h +++ b/epicardium/modules/modules.h @@ -6,6 +6,9 @@ void vSerialTask(void *pvParameters); /* ---------- PMIC --------------------------------------------------------- */ +/* In 1/10s */ +#define PMIC_PRESS_SLEEP 20 +#define PMIC_PRESS_POWEROFF 40 void vPmicTask(void *pvParameters); #endif /* MODULES_H */ diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index 41618cdae0dd23c4c0657d75377a738cb5b94a98..4e786f645ec98b286b187a6f1304716c4e252659 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -25,30 +25,46 @@ void pmic_interrupt_callback(void *_) void vPmicTask(void *pvParameters) { + int count = 0; + portTickType delay = portMAX_DELAY; pmic_task_id = xTaskGetCurrentTaskHandle(); while (1) { - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + ulTaskNotifyTake(pdTRUE, delay); + + if (count == PMIC_PRESS_SLEEP) { + printf("pmic: Sleep\n" + "[[ Unimplemented ]]\n"); + } + + if (count == PMIC_PRESS_POWEROFF) { + printf("pmic: Poweroff\n" + "[[ Unimplemented ]]\n"); + } uint8_t int_flag = MAX77650_getINT_GLBL(); if (int_flag & MAX77650_INT_nEN_F) { /* Button was pressed */ - printf("pmic: Button pressed!\n"); + count = 0; + delay = portTICK_PERIOD_MS * 100; } if (int_flag & MAX77650_INT_nEN_R) { /* Button was pressed */ - printf("pmic: Button released!\n"); - - printf("Resetting ...\n"); - /* - * Give the UART fifo time to clear. - * TODO: Do this properly - */ - for (int i = 0; i < 0x1000000; i++) { - __asm volatile("nop"); + if (count < PMIC_PRESS_SLEEP) { + printf("pmic: Reset\n"); + /* + * Give the UART fifo time to clear. + * TODO: Do this properly + */ + for (int i = 0; i < 0x1000000; i++) { + __asm volatile("nop"); + } + MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM; } - MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM; + + count = 0; + delay = portMAX_DELAY; } /* TODO: Remove when all interrupts are handled */ @@ -57,5 +73,9 @@ void vPmicTask(void *pvParameters) "* Unhandled PMIC Interrupt: %x\n", int_flag); } + + if (delay != portMAX_DELAY) { + count += 1; + } } }