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

Merge branch 'rahix/hw-init'


Implement proper initialization of the different peripherals in
hardware_early_init() & hardware_init().  This includes stripping down
the display init so it does not perform a full reset anymore; we can do
this as the bootloader will have always performed the full reset
already.

Additionally this changeset enables the hardware_reset() function which
resets peripherals on load of a new app.  This should increase stability
as apps can always assume everything to be in its default state on load.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parents f012c7f7 a357a3f6
No related branches found
Tags bootloader-v1
No related merge requests found
This diff is collapsed.
......@@ -199,11 +199,14 @@ void core1_boot(void)
core1_start(&core1_initial_ivt);
}
void core1_reset(void)
void core1_trigger_reset(void)
{
/* Signal core 1 that we intend to load a new payload. */
api_interrupt_trigger(EPIC_INT_RESET);
}
void core1_wait_ready(void)
{
/* Wait for the core to accept */
while (1) {
while (SEMA_GetSema(_CONTROL_SEMAPHORE) == E_BUSY) {
......
......@@ -37,7 +37,10 @@ void api_prepare_args(char *args);
void core1_boot(void);
/* Reset core 1 into a state where it can accept a new payload */
void core1_reset(void);
void core1_trigger_reset(void);
/* Wait for core 1 to respond that it is ready for a new payload */
void core1_wait_ready(void);
/* Load a payload into core 1 */
void core1_load(void *ivt, char *args);
......
#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 "Heart.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);
......@@ -35,46 +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 */
gfx_copy_region_raw(
&display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen);
/* 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 */
......@@ -129,10 +73,6 @@ int main(void)
abort();
}
/* light sensor */
LOG_INFO("startup", "starting light sensor ...");
epic_light_sensor_run();
/* Lifecycle */
if (xTaskCreate(
vLifecycleTask,
......
#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"
#include "display.h"
#include "leds.h"
#include "pb.h"
#include "pmic.h"
#include "portexpander.h"
#include "gpio.h"
#include "i2c.h"
#include "spi.h"
/*
* Early init is called at the very beginning and is meant for modules which
......@@ -9,7 +26,124 @@
*/
int hardware_early_init(void)
{
card10_init();
/*
* I2C bus for onboard peripherals (ie. PMIC, BMA400, BHI160, BME680,
* ...)
*/
I2C_Shutdown(MXC_I2C1_BUS0);
I2C_Init(MXC_I2C1_BUS0, I2C_FAST_MODE, NULL);
#ifndef CARD10_DEBUG_CORE1
/*
* SAO I2C bus
*/
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
#endif
/*
* GPIO peripheral.
*/
GPIO_Init();
/*
* PMIC (MAX77650)
*/
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
/*
* Harmonic Board Portexpander
*/
portexpander_init();
/*
* Buttons
*/
PB_Init();
/*
* SPI for ECG
*/
const sys_cfg_spi_t spi17y_master_cfg = {
.map = MAP_A,
.ss0 = Enable,
.ss1 = Disable,
.ss2 = Disable,
};
if (SPI_Init(SPI0, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
LOG_ERR("init", "Error configuring SPI");
while (1)
;
}
/*
* The bootloader has already initialized the display, so we only need
* to do the bare minimum here (mostly the gfx datastructures).
*/
display_init_slim();
/*
* RGB LEDs
*/
leds_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 +157,10 @@ int hardware_early_init(void)
*/
int hardware_init(void)
{
/* Light Sensor */
LOG_INFO("init", "Starting light sensor ...");
epic_light_sensor_run();
return 0;
}
......@@ -35,6 +173,24 @@ int hardware_init(void)
*/
int hardware_reset(void)
{
card10_init();
/*
* API Dispatcher & API Interrupts
*/
api_interrupt_init();
api_dispatcher_init();
/*
* LEDs
*/
leds_init();
epic_leds_set_rocket(0, 0);
epic_leds_set_rocket(1, 0);
epic_leds_set_rocket(2, 0);
/*
* Display
*/
display_init_slim();
return 0;
}
......@@ -2,6 +2,7 @@
#include "modules/log.h"
#include "modules/modules.h"
#include "api/dispatcher.h"
#include "api/interrupt-sender.h"
#include "l0der/l0der.h"
#include "card10.h"
......@@ -87,6 +88,9 @@ static int load_stat(char *name)
*/
static int do_load(struct load_info *info)
{
struct l0dable_info l0dable;
int res;
if (*info->name == '\0') {
LOG_INFO("lifecycle", "Loading Python interpreter ...");
} else {
......@@ -100,9 +104,21 @@ static int do_load(struct load_info *info)
if (info->do_reset) {
LOG_DEBUG("lifecycle", "Triggering core 1 reset.");
core1_reset();
api_dispatcher_init();
core1_trigger_reset();
}
/*
* Wait for the core to become ready to accept a new payload.
*/
core1_wait_ready();
/*
* Reinitialize Hardware & Drivers
*/
res = hardware_reset();
if (res < 0) {
return res;
}
switch (info->type) {
......@@ -112,14 +128,7 @@ static int do_load(struct load_info *info)
core1_load(PYCARDIUM_IVT, info->name);
break;
case PL_L0DABLE:
/*
* Always reset when loading a l0dable to make sure the memory
* space is absolutely free.
*/
core1_reset();
struct l0dable_info l0dable;
int res = l0der_load_path(info->name, &l0dable);
res = l0der_load_path(info->name, &l0dable);
if (res != 0) {
LOG_ERR("lifecycle", "l0der failed: %d\n", res);
xSemaphoreGive(api_mutex);
......
#include "card10.h"
#include "pmic.h"
#include "bosch.h"
#include "display.h"
......@@ -24,8 +25,6 @@
#include <stdint.h>
#include <string.h>
#define SPI_SPEED (15 * 1000 * 1000) // Bit Rate
const gpio_cfg_t bhi_interrupt_pin = {
PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
};
......
......@@ -4,6 +4,8 @@
#include <stdint.h>
#define SPI_SPEED (15 * 1000 * 1000) // Bit Rate
extern const gpio_cfg_t bhi_interrupt_pin;
void card10_init(void);
......
......@@ -103,3 +103,18 @@ void display_init(void)
txt_init(&display_textb, &display_screen, &Font12);
gfx_clear(&display_screen);
}
void display_init_slim(void)
{
if (!portexpander_detected()) {
// Open-drain
MAX77650_setDRV(false);
// Output
MAX77650_setDIR(false);
}
GPIO_Config(&DEV_DC_PIN);
display_screen = gfx_screen(LCD_framebuffer());
txt_init(&display_textb, &display_screen, &Font12);
}
......@@ -6,5 +6,6 @@ extern struct gfx_region display_screen;
extern struct txt_buffer display_textb;
void display_init(void);
void display_init_slim(void);
#endif
......@@ -12,8 +12,6 @@ void txt_init(struct txt_buffer *txtb, struct gfx_region *reg, sFONT *f)
txtb->bg_color = gfx_color_rgb_f(reg, .0f, .0f, .0f);
txtb->draw_cursor = 1;
txtb->auto_update = 1;
txt_clear(txtb);
}
static inline size_t width_(struct txt_buffer *tm)
......
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