diff --git a/epicardium/main.c b/epicardium/main.c index cd989f4cf101b5754bbdaddd757947a0de51120a..1ae2dde0ea54abef8bbab248502d5537b47e243c 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -36,7 +36,8 @@ int main(void) LOG_INFO("startup", "Epicardium startup ..."); LOG_INFO("startup", "Version " CARD10_VERSION); - card10_init(); + hardware_early_init(); + #ifdef CARD10_DEBUG_CORE1 LOG_WARN("startup", "Core 1 Debugger Mode"); static const gpio_cfg_t swclk = { @@ -157,6 +158,8 @@ int main(void) core1_load((void *)0x10080000, "main.py"); } + hardware_init(); + LOG_INFO("startup", "Starting FreeRTOS ..."); vTaskStartScheduler(); diff --git a/epicardium/modules/hardware.c b/epicardium/modules/hardware.c new file mode 100644 index 0000000000000000000000000000000000000000..ee369248a17788907875d346fb5f3b4e9de9dc52 --- /dev/null +++ b/epicardium/modules/hardware.c @@ -0,0 +1,40 @@ +#include "modules/modules.h" + +#include "card10.h" + +/* + * Early init is called at the very beginning and is meant for modules which + * absolutely need to start as soon as possible. hardware_early_init() blocks + * which means code in here should be fast. + */ +int hardware_early_init(void) +{ + card10_init(); + return 0; +} + +/* + * hardware_init() is called after the core has been bootstrapped and is meant + * for less critical initialization steps. Modules which initialize here should + * be robust against a l0dable using their API before initialization is done. + * + * Ideally, acquire a lock in hardware_early_init() and release it in + * hardware_init() once initialization is done. + */ +int hardware_init(void) +{ + return 0; +} + +/* + * hardware_reset() is called whenever a new l0dable is started. hardware_reset() + * should bring all peripherals back into a known initial state. This does not + * necessarily mean resetting the peripheral entirely but hardware_reset() + * should at least bring the API facing part of a peripheral back into the state + * a fresh booted l0dable expects. + */ +int hardware_reset(void) +{ + card10_init(); + return 0; +} diff --git a/epicardium/modules/meson.build b/epicardium/modules/meson.build index 9a70957d0c4b70083c92c5386ca5edd3f513102c..ba1a4fd47d3827fc1f2d3d85215c089564208e9f 100644 --- a/epicardium/modules/meson.build +++ b/epicardium/modules/meson.build @@ -2,6 +2,7 @@ module_sources = files( 'dispatcher.c', 'display.c', 'fileops.c', + 'hardware.c', 'leds.c', 'light_sensor.c', 'log.c', diff --git a/epicardium/modules/modules.h b/epicardium/modules/modules.h index ea2a313f4970e1d607be99adc9ac843aefcfdea5..df1a9d9b477f043433225c59eec93500e386d0af 100644 --- a/epicardium/modules/modules.h +++ b/epicardium/modules/modules.h @@ -11,6 +11,11 @@ void vApiDispatcher(void *pvParameters); extern SemaphoreHandle_t api_mutex; extern TaskHandle_t dispatcher_task_id; +/* ---------- Hardware Init & Reset ---------------------------------------- */ +int hardware_early_init(void); +int hardware_init(void); +int hardware_reset(void); + /* ---------- Serial ------------------------------------------------------- */ #define SERIAL_READ_BUFFER_SIZE 128 void vSerialTask(void *pvParameters); @@ -27,4 +32,5 @@ void ble_uart_write(uint8_t *pValue, uint8_t len); // Forces an unlock of the display. Only to be used in epicardium void disp_forcelock(); + #endif /* MODULES_H */