diff --git a/epicardium/main.c b/epicardium/main.c index 2b2c2769ecafe1c1ea8f56573a48d2925a1ee044..d0e15ff97c68b3d3a3725130338d69dc3ada51a1 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -1,30 +1,12 @@ -#include <stdio.h> -#include <stdlib.h> - -#include <ff.h> - -#include "max32665.h" -#include "uart.h" -#include "cdcacm.h" -#include "gpio.h" - -#include "card10.h" -#include "pmic.h" -#include "leds.h" -#include "api/dispatcher.h" #include "modules/modules.h" #include "modules/log.h" -#include "modules/stream.h" -#include "modules/filesystem.h" -#include "api/interrupt-sender.h" - -#include "gfx.h" -#include "display.h" #include "card10-version.h" #include "FreeRTOS.h" #include "task.h" +#include <stdlib.h> + TaskHandle_t dispatcher_task_id; void vBleTask(void *pvParameters); @@ -34,41 +16,9 @@ int main(void) LOG_INFO("startup", "Epicardium startup ..."); LOG_INFO("startup", "Version " CARD10_VERSION); + LOG_INFO("startup", "Initializing hardware ..."); hardware_early_init(); -#ifdef CARD10_DEBUG_CORE1 - LOG_WARN("startup", "Core 1 Debugger Mode"); - static const gpio_cfg_t swclk = { - PORT_0, - PIN_7, - GPIO_FUNC_ALT3, - GPIO_PAD_NONE, - }; - static const gpio_cfg_t swdio = { - PORT_0, - PIN_6, - GPIO_FUNC_ALT3, - GPIO_PAD_NONE, - }; - - GPIO_Config(&swclk); - GPIO_Config(&swdio); -#endif /* CARD10_DEBUG_CORE1 */ - - /* TODO: Move this to its own function */ - SCB->SCR |= SCB_SCR_SEVONPEND_Msk; - - if (cdcacm_init() < 0) { - LOG_ERR("startup", "USB-Serial unavailable"); - } - - fatfs_init(); - api_interrupt_init(); - stream_init(); - - LOG_INFO("startup", "Initializing dispatcher ..."); - api_dispatcher_init(); - LOG_INFO("startup", "Initializing tasks ..."); /* Serial */ @@ -123,10 +73,6 @@ int main(void) abort(); } - /* light sensor */ - LOG_INFO("startup", "starting light sensor ..."); - epic_light_sensor_run(); - /* Lifecycle */ if (xTaskCreate( vLifecycleTask, diff --git a/epicardium/modules/hardware.c b/epicardium/modules/hardware.c index ee369248a17788907875d346fb5f3b4e9de9dc52..7ec18cd2c86fe22c9e7f4499b18a7f75c3ea6fb7 100644 --- a/epicardium/modules/hardware.c +++ b/epicardium/modules/hardware.c @@ -1,4 +1,12 @@ +#include "epicardium.h" + +#include "api/dispatcher.h" +#include "api/interrupt-sender.h" +#include "cdcacm.h" +#include "modules/filesystem.h" +#include "modules/log.h" #include "modules/modules.h" +#include "modules/stream.h" #include "card10.h" @@ -10,6 +18,60 @@ int hardware_early_init(void) { card10_init(); + +#ifdef CARD10_DEBUG_CORE1 + /* + * The SAO pins can be reconfigured for SWCLK2 and SWDIO2 which allows + * debugging core 1. This feature can optionally be enabled at + * compile-time. + */ + LOG_WARN("init", "Core 1 Debugger Mode"); + static const gpio_cfg_t swclk = { + PORT_0, + PIN_7, + GPIO_FUNC_ALT3, + GPIO_PAD_NONE, + }; + static const gpio_cfg_t swdio = { + PORT_0, + PIN_6, + GPIO_FUNC_ALT3, + GPIO_PAD_NONE, + }; + + GPIO_Config(&swclk); + GPIO_Config(&swdio); +#endif /* CARD10_DEBUG_CORE1 */ + + /* + * Enable SEV-ON-PEND which is needed for proper working of the FreeRTOS + * tickless idle sleep in Epicardium. + */ + SCB->SCR |= SCB_SCR_SEVONPEND_Msk; + + /* + * USB-Serial + */ + if (cdcacm_init() < 0) { + LOG_ERR("init", "USB-Serial unavailable"); + } + + /* + * Flash & FatFS + */ + fatfs_init(); + + /* + * API Dispatcher & API Interrupts + */ + api_interrupt_init(); + api_dispatcher_init(); + + /* + * Sensor streams + */ + stream_init(); + return 0; } @@ -23,6 +85,10 @@ int hardware_early_init(void) */ int hardware_init(void) { + /* Light Sensor */ + LOG_INFO("init", "Starting light sensor ..."); + epic_light_sensor_run(); + return 0; }