Skip to content
Snippets Groups Projects
Verified Commit 18ec7649 authored by rahix's avatar rahix
Browse files

feat(epicardium): Add a separate task for PMIC


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent f8dbe9a2
No related branches found
No related tags found
No related merge requests found
......@@ -30,21 +30,6 @@ void vApiDispatcher(void *pvParameters)
}
}
static void pmic_button(bool falling)
{
if (falling) {
printf("Resetting ...\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;
}
}
int main(void)
{
card10_init();
......@@ -53,8 +38,6 @@ int main(void)
/* TODO: Move this to its own function */
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
pmic_set_button_callback(pmic_button);
cdcacm_init();
printf("=> Initializing tasks ...\n");
......@@ -71,6 +54,19 @@ int main(void)
abort();
}
/* PMIC */
if (xTaskCreate(
vPmicTask,
(const char *)"PMIC",
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 1,
NULL) != pdPASS) {
printf("Failed to create pmic task!\n");
abort();
}
/* API */
if (xTaskCreate(
vApiDispatcher,
(const char *)"API Dispatcher",
......
module_sources = files(
'leds.c',
'pmic.c',
'serial.c',
'vibra.c'
'vibra.c',
)
......@@ -5,5 +5,8 @@
#define SERIAL_READ_BUFFER_SIZE 128
void vSerialTask(void *pvParameters);
/* ---------- PMIC --------------------------------------------------------- */
void vPmicTask(void *pvParameters);
#endif /* MODULES_H */
#include <stdio.h>
#include "max32665.h"
#include "gcr_regs.h"
#include "pmic.h"
#include "MAX77650-Arduino-Library.h"
#include "FreeRTOS.h"
#include "task.h"
#include "epicardium.h"
#include "modules.h"
/* Task ID for the pmic handler */
static TaskHandle_t pmic_task_id = NULL;
void pmic_interrupt_callback(void *_)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (pmic_task_id != NULL) {
vTaskNotifyGiveFromISR(pmic_task_id, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void vPmicTask(void *pvParameters)
{
pmic_task_id = xTaskGetCurrentTaskHandle();
while (1) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
uint8_t int_flag = MAX77650_getINT_GLBL();
if (int_flag & MAX77650_INT_nEN_F) {
/* Button was pressed */
printf("pmic: Button pressed!\n");
}
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");
}
MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM;
}
/* TODO: Remove when all interrupts are handled */
if (int_flag & ~(MAX77650_INT_nEN_F | MAX77650_INT_nEN_R)) {
printf("=====> WARNING <=====\n"
"* Unhandled PMIC Interrupt: %x\n",
int_flag);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment