Skip to content
Snippets Groups Projects
Commit e6685d5a authored by schneider's avatar schneider Committed by rahix
Browse files

chore(style): Code style for bootloader

parent 1afb0212
No related branches found
No related tags found
No related merge requests found
......@@ -89,13 +89,8 @@ static const msc_idstrings_t ids = {
/* Functions to control "disk" memory. See msc.h for definitions. */
static const msc_mem_t mem = {
mscmem_init,
mscmem_start,
mscmem_stop,
mscmem_ready,
mscmem_size,
mscmem_read,
mscmem_write,
mscmem_init, mscmem_start, mscmem_stop, mscmem_ready,
mscmem_size, mscmem_read, mscmem_write,
};
/* This callback is used to allow the driver to call part specific initialization functions. */
......@@ -117,7 +112,6 @@ void delay_us(unsigned int usec)
mxc_delay(usec);
}
/******************************************************************************/
void run_usbmsc(void)
{
......@@ -133,25 +127,32 @@ void run_usbmsc(void)
/* Start out in full speed */
usb_opts.enable_hs = 0;
usb_opts.delay_us = delay_us; /* Function which will be used for delays */
usb_opts.delay_us =
delay_us; /* Function which will be used for delays */
usb_opts.init_callback = usb_startup_cb;
usb_opts.shutdown_callback = usb_shutdown_cb;
/* Initialize the usb module */
if (usb_init(&usb_opts) != 0) {
printf("usb_init() failed\n");
while (1);
while (1)
;
}
/* Initialize the enumeration module */
if (enum_init() != 0) {
printf("enum_init() failed\n");
while (1);
while (1)
;
}
/* Register enumeration data */
enum_register_descriptor(ENUM_DESC_DEVICE, (uint8_t*)&device_descriptor, 0);
enum_register_descriptor(ENUM_DESC_CONFIG, (uint8_t*)&config_descriptor, 0);
enum_register_descriptor(
ENUM_DESC_DEVICE, (uint8_t *)&device_descriptor, 0
);
enum_register_descriptor(
ENUM_DESC_CONFIG, (uint8_t *)&config_descriptor, 0
);
enum_register_descriptor(ENUM_DESC_STRING, lang_id_desc, 0);
enum_register_descriptor(ENUM_DESC_STRING, mfg_id_desc, 1);
enum_register_descriptor(ENUM_DESC_STRING, prod_id_desc, 2);
......@@ -165,9 +166,11 @@ void run_usbmsc(void)
enum_register_callback(ENUM_CLRFEATURE, clrfeature_callback, NULL);
/* Initialize the class driver */
if (msc_init(&config_descriptor.msc_interface_descriptor, &ids, &mem) != 0) {
if (msc_init(&config_descriptor.msc_interface_descriptor, &ids, &mem) !=
0) {
printf("msc_init() failed\n");
while (1);
while (1)
;
}
/* Register callbacks */
......@@ -180,7 +183,6 @@ void run_usbmsc(void)
/* Wait for events */
while (1) {
if (suspended || !configured) {
//LED_Off(0);
} else {
......@@ -201,7 +203,8 @@ void run_usbmsc(void)
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_SUSP)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_SUSP);
printf("Suspended\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_DPACT)) {
} else if (MXC_GETBIT(
&event_flags, MAXUSB_EVENT_DPACT)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_DPACT);
printf("Resume\n");
} else if (MXC_GETBIT(&event_flags, EVENT_ENUM_COMP)) {
......@@ -221,7 +224,8 @@ void run_usbmsc(void)
static int setconfig_callback(usb_setup_pkt *sud, void *cbdata)
{
/* Confirm the configuration value */
if (sud->wValue == config_descriptor.config_descriptor.bConfigurationValue) {
if (sud->wValue ==
config_descriptor.config_descriptor.bConfigurationValue) {
configured = 1;
MXC_SETBIT(&event_flags, EVENT_ENUM_COMP);
return msc_configure(&msc_cfg); /* Configure the device class */
......
......@@ -60,7 +60,14 @@ bool check_integrity(void)
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
Paint_DrawString_EN(0, 16*2, "card10.bin not found", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0,
16 * 2,
"card10.bin not found",
&Font16,
0x0000,
0xffff
);
LCD_Update();
printf("f_open error %d\n", res);
......@@ -83,7 +90,14 @@ bool check_integrity(void)
if (crcval == 0) {
return true;
} else {
Paint_DrawString_EN(0, 16*2, "Integrity check failed", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0,
16 * 2,
"Integrity check failed",
&Font16,
0x0000,
0xffff
);
LCD_Update();
printf("CRC check failed. Final CRC: %d\n", crcval);
return false;
......@@ -129,7 +143,8 @@ void erase_partition(void)
int ret = FLC_MultiPageErase(PARTITION_START, PARTITION_END);
if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
while(1);
while (1)
;
}
}
......@@ -144,7 +159,8 @@ void flash_partition(void)
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
printf("f_open error %d\n", res);
while(1);
while (1)
;
}
uint32_t partition = PARTITION_START;
......@@ -156,10 +172,16 @@ void flash_partition(void)
printf("f_read error %d\n", res);
break; /* Going to return false, don't want to use this file */
}
int ret = FLC_Write(partition, readbytes, (uint32_t *)data); /* wild cast. not sure if this works */
int ret = FLC_Write(
partition,
readbytes,
(uint32_t *
)
data); /* wild cast. not sure if this works */
if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
while(1);
while (1)
;
}
partition += readbytes;
} while (readbytes == sizeof(data));
......@@ -168,7 +190,8 @@ void flash_partition(void)
f_close(&file);
}
static inline void boot(const void * vtable){
static inline void boot(const void *vtable)
{
SCB->VTOR = (uintptr_t)vtable;
// Reset stack pointer & branch to the new reset vector.
......@@ -214,14 +237,22 @@ int main(void)
// If the button is pressed, we go into MSC mode.
if (PB_Get(3)) {
Paint_DrawString_EN(0, 16*2, "USB activated. Waiting.", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0,
16 * 2,
"USB activated. Waiting.",
&Font16,
0x0000,
0xffff
);
LCD_Update();
run_usbmsc();
// If we return, don't try to boot. Maybe rather trigger a software reset.
// Reason: Not sure in which state the USB peripheral is and what kind
// of interrupts are active.
while(1);
while (1)
;
}
if (mount()) {
......@@ -229,7 +260,14 @@ int main(void)
printf("Found valid application image\n");
if (is_update_needed()) {
printf("Trying to update application from external flash\n");
Paint_DrawString_EN(0, 16*4, "Updating...", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0,
16 * 4,
"Updating...",
&Font16,
0x0000,
0xffff
);
LCD_Update();
erase_partition();
flash_partition();
......@@ -240,14 +278,22 @@ int main(void)
printf("Integrity check failed\n");
}
} else {
Paint_DrawString_EN(0, 16*2, "Failed to mount file system", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0,
16 * 2,
"Failed to mount file system",
&Font16,
0x0000,
0xffff
);
LCD_Update();
printf("Failed to mount the external flash\n");
}
printf("Trying to boot\n");
Paint_DrawString_EN(0, 16*4, "Trying to boot", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 4, "Trying to boot", &Font16, 0x0000, 0xffff
);
LCD_Update();
//while(1);
// boot partition
......
......@@ -30,7 +30,9 @@
* At 12 MHz things seem stable*/
#define SPI_SPEED (12 * 1000 * 1000) // Bit Rate. Display has 15 MHz limit
const gpio_cfg_t bhi_interrupt_pin = {PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP};
const gpio_cfg_t bhi_interrupt_pin = {
PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
};
void card10_init(void)
{
......@@ -56,7 +58,9 @@ void card10_init(void)
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
// Enable 32 kHz output
RTC_SquareWave(MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL);
RTC_SquareWave(
MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL
);
// Enable SPI
sys_cfg_spi_t spi17y_master_cfg;
......@@ -68,12 +72,14 @@ void card10_init(void)
if (SPI_Init(SPI0, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
while (1)
;
}
if (SPI_Init(SPI2, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
while (1)
;
}
display_init();
......@@ -81,7 +87,6 @@ void card10_init(void)
leds_init();
GPIO_Config(&bhi_interrupt_pin);
}
static uint32_t ecg_read_reg(uint8_t reg)
......@@ -111,7 +116,8 @@ void card10_diag(void)
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
int res =
I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if (res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
......@@ -126,26 +132,35 @@ void card10_diag(void)
printf("Failed to init bhy\n");
} else {
/* wait for the bhy trigger the interrupt pin go down and up again */
while (GPIO_InGet(&bhi_interrupt_pin));
while (!GPIO_InGet(&bhi_interrupt_pin));
while (GPIO_InGet(&bhi_interrupt_pin))
;
while (!GPIO_InGet(&bhi_interrupt_pin))
;
/* the remapping matrix for BHI and Magmetometer should be configured here to make sure rotation vector is */
/* calculated in a correct coordinates system. */
int8_t bhy_mapping_matrix_config[3*3] = {0,-1,0,1,0,0,0,0,1};
int8_t mag_mapping_matrix_config[3*3] = {-1,0,0,0,1,0,0,0,-1};
bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_ACC, bhy_mapping_matrix_config);
bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_MAG, mag_mapping_matrix_config);
bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_GYRO, bhy_mapping_matrix_config);
int8_t bhy_mapping_matrix_config[3 * 3] = { 0, -1, 0, 1, 0,
0, 0, 0, 1 };
int8_t mag_mapping_matrix_config[3 * 3] = { -1, 0, 0, 0, 1,
0, 0, 0, -1 };
bhy_mapping_matrix_set(
PHYSICAL_SENSOR_INDEX_ACC, bhy_mapping_matrix_config
);
bhy_mapping_matrix_set(
PHYSICAL_SENSOR_INDEX_MAG, mag_mapping_matrix_config
);
bhy_mapping_matrix_set(
PHYSICAL_SENSOR_INDEX_GYRO, bhy_mapping_matrix_config
);
/* the sic matrix should be calculated for customer platform by logging uncalibrated magnetometer data. */
/* the sic matrix here is only an example array (identity matrix). Customer should generate their own matrix. */
/* This affects magnetometer fusion performance. */
float sic_array[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
float sic_array[9] = { 1.0, 0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0 };
bhy_set_sic_matrix(sic_array);
}
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
......@@ -182,16 +197,17 @@ void card10_diag(void)
uint32_t val = ecg_read_reg(0xf);
printf("ECG: %02x: 0x%06lx (should be 0x5139a0)\n", 0xf, val);
#endif
}
void core1_start(void) {
void core1_start(void)
{
//MXC_GCR->gp0 = (uint32_t)(&__isr_vector_core1);
MXC_GCR->gp0 = 0x10080000;
MXC_GCR->perckcn1 &= ~MXC_F_GCR_PERCKCN1_CPU1;
}
void core1_stop(void) {
void core1_stop(void)
{
MXC_GCR->perckcn1 |= MXC_F_GCR_PERCKCN1_CPU1;
}
......@@ -219,4 +235,3 @@ void GPIO3_IRQHandler(void)
{
GPIO_Handler(PORT_3);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment