diff --git a/flight/Bootloaders/AHRS/bl_fsm.c b/flight/Bootloaders/AHRS/bl_fsm.c index f473eea8b..48126037e 100644 --- a/flight/Bootloaders/AHRS/bl_fsm.c +++ b/flight/Bootloaders/AHRS/bl_fsm.c @@ -32,6 +32,12 @@ static struct lfsm_context context = { 0 }; static void lfsm_update_link_tx (struct lfsm_context * context); static void lfsm_init_rx (struct lfsm_context * context); +static uint32_t PIOS_SPI_OP; +void lfsm_attach(uint32_t spi_id) +{ + PIOS_SPI_OP = spi_id; +} + /* * * Link Finite State Machine diff --git a/flight/Bootloaders/AHRS/inc/bl_fsm.h b/flight/Bootloaders/AHRS/inc/bl_fsm.h index 614ca4dac..7ab3369e7 100644 --- a/flight/Bootloaders/AHRS/inc/bl_fsm.h +++ b/flight/Bootloaders/AHRS/inc/bl_fsm.h @@ -72,6 +72,7 @@ struct lfsm_link_stats { uint32_t rx_badver; }; +extern void lfsm_attach(uint32_t spi_id); extern void lfsm_init(void); extern void lfsm_inject_event(enum lfsm_event event); diff --git a/flight/Bootloaders/AHRS/inc/pios_config.h b/flight/Bootloaders/AHRS/inc/pios_config.h index f3eaca763..601701c1e 100644 --- a/flight/Bootloaders/AHRS/inc/pios_config.h +++ b/flight/Bootloaders/AHRS/inc/pios_config.h @@ -29,18 +29,12 @@ #define PIOS_CONFIG_H /* Enable/Disable PiOS Modules */ -//#define PIOS_INCLUDE_ADC #define PIOS_INCLUDE_DELAY -//#define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_IRQ #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_SPI #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_BL_HELPER -//#define PIOS_INCLUDE_USART -//#define PIOS_INCLUDE_COM -//#define PIOS_INCLUDE_HMC5843 #define PIOS_INCLUDE_GPIO - #endif /* PIOS_CONFIG_H */ diff --git a/flight/Bootloaders/AHRS/main.c b/flight/Bootloaders/AHRS/main.c index 723f8388b..41d04175a 100644 --- a/flight/Bootloaders/AHRS/main.c +++ b/flight/Bootloaders/AHRS/main.c @@ -37,6 +37,8 @@ #include "bl_fsm.h" /* lfsm_state */ #include "stm32f10x_flash.h" +extern void PIOS_Board_Init(void); + #define NSS_HOLD_STATE ((GPIOB->IDR & GPIO_Pin_12) ? 0 : 1) enum bootloader_status boot_status; /* Private typedef -----------------------------------------------------------*/ @@ -92,9 +94,7 @@ int main() { PIOS_DELAY_WaitmS(1000); PIOS_IAP_ClearRequest(); } - /* SPI link to master */ - PIOS_SPI_Init(); - lfsm_init(); + PIOS_Board_Init(); boot_status = idle; Fw_crc = crc_memory_calc(); PIOS_LED_On(LED1); diff --git a/flight/Bootloaders/AHRS/pios_board.c b/flight/Bootloaders/AHRS/pios_board.c index 7784b8739..0b1cd6fd0 100644 --- a/flight/Bootloaders/AHRS/pios_board.c +++ b/flight/Bootloaders/AHRS/pios_board.c @@ -128,200 +128,23 @@ static const struct pios_spi_cfg pios_spi_op_cfg = { }, }; -/* - * Board specific number of devices. - */ -struct pios_spi_dev pios_spi_devs[] = { - { - .cfg = &pios_spi_op_cfg, - }, -}; - -uint8_t pios_spi_num_devices = NELEMENTS(pios_spi_devs); - +uint32_t pios_spi_op_id; void PIOS_SPI_op_irq_handler(void) { - /* Call into the generic code to handle the IRQ for this specific device */ - PIOS_SPI_IRQ_Handler(PIOS_SPI_OP); + /* Call into the generic code to handle the IRQ for this specific device */ + PIOS_SPI_IRQ_Handler(pios_spi_op_id); } #endif /* PIOS_INCLUDE_SPI */ -#if defined(PIOS_INCLUDE_USART) -#include +#include "bl_fsm.h" /* lfsm_* */ -/* - * AUX USART - */ -void PIOS_USART_aux_irq_handler(void); -void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_aux_irq_handler"))); -const struct pios_usart_cfg pios_usart_aux_cfg = { - .regs = USART3, - .init = { - #if defined(PIOS_COM_AUX_BAUDRATE) - .USART_BaudRate = PIOS_COM_AUX_BAUDRATE - #else - .USART_BaudRate = 115200, - #endif - .USART_WordLength = USART_WordLength_8b, - .USART_Parity = USART_Parity_No, - .USART_StopBits = USART_StopBits_1, - .USART_HardwareFlowControl = USART_HardwareFlowControl_None, - .USART_Mode = USART_Mode_Rx | USART_Mode_Tx, - }, - .irq = { - .handler = PIOS_USART_aux_irq_handler, - .init = { - .NVIC_IRQChannel = USART3_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, - .rx = { - .gpio = GPIOB, - .init = { - .GPIO_Pin = GPIO_Pin_11, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_IPU, - }, - }, - .tx = { - .gpio = GPIOB, - .init = { - .GPIO_Pin = GPIO_Pin_10, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_AF_PP, - }, - }, -}; - -/* - * Board specific number of devices. - */ -struct pios_usart_dev pios_usart_devs[] = { -#define PIOS_USART_AUX 0 - { - .cfg = &pios_usart_aux_cfg, - }, -}; - -uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs); - -void PIOS_USART_aux_irq_handler(void) +void PIOS_Board_Init() { - PIOS_USART_IRQ_Handler(PIOS_USART_AUX); + /* Set up the SPI interface to the OP board */ + if (PIOS_SPI_Init(&pios_spi_op_id, &pios_spi_op_cfg)) { + PIOS_DEBUG_Assert(0); + } + lfsm_attach(pios_spi_op_id); + lfsm_init(); } - -#endif /* PIOS_INCLUDE_USART */ - -#if defined(PIOS_INCLUDE_COM) -#include - -/* - * COM devices - */ - -/* - * Board specific number of devices. - */ -extern const struct pios_com_driver pios_usart_com_driver; - -struct pios_com_dev pios_com_devs[] = { - { - .id = PIOS_USART_AUX, - .driver = &pios_usart_com_driver, - }, -}; - -const uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs); - -#endif /* PIOS_INCLUDE_COM */ - -#if defined(PIOS_INCLUDE_I2C) -#include - -/* - * I2C Adapters - */ - -void PIOS_I2C_main_adapter_ev_irq_handler(void); -void PIOS_I2C_main_adapter_er_irq_handler(void); -void I2C1_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_ev_irq_handler"))); -void I2C1_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_er_irq_handler"))); - -const struct pios_i2c_adapter_cfg pios_i2c_main_adapter_cfg = { - .regs = I2C1, - .init = { - .I2C_Mode = I2C_Mode_I2C, - .I2C_OwnAddress1 = 0, - .I2C_Ack = I2C_Ack_Enable, - .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit, - .I2C_DutyCycle = I2C_DutyCycle_2, - .I2C_ClockSpeed = 200000, /* bits/s */ - }, - .transfer_timeout_ms = 50, - .scl = { - .gpio = GPIOB, - .init = { - .GPIO_Pin = GPIO_Pin_6, - .GPIO_Speed = GPIO_Speed_10MHz, - .GPIO_Mode = GPIO_Mode_AF_OD, - }, - }, - .sda = { - .gpio = GPIOB, - .init = { - .GPIO_Pin = GPIO_Pin_7, - .GPIO_Speed = GPIO_Speed_10MHz, - .GPIO_Mode = GPIO_Mode_AF_OD, - }, - }, - .event = { - .handler = PIOS_I2C_main_adapter_ev_irq_handler, - .flags = 0, /* FIXME: check this */ - .init = { - .NVIC_IRQChannel = I2C1_EV_IRQn, - //.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST, - .NVIC_IRQChannelPreemptionPriority = 2, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, - .error = { - .handler = PIOS_I2C_main_adapter_er_irq_handler, - .flags = 0, /* FIXME: check this */ - .init = { - .NVIC_IRQChannel = I2C1_ER_IRQn, - //.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST, - .NVIC_IRQChannelPreemptionPriority = 2, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, -}; - -/* - * Board specific number of devices. - */ -struct pios_i2c_adapter pios_i2c_adapters[] = { - { - .cfg = &pios_i2c_main_adapter_cfg, - }, -}; - -uint8_t pios_i2c_num_adapters = NELEMENTS(pios_i2c_adapters); - -void PIOS_I2C_main_adapter_ev_irq_handler(void) -{ - /* Call into the generic code to handle the IRQ for this specific device */ - PIOS_I2C_EV_IRQ_Handler(PIOS_I2C_MAIN_ADAPTER); -} - -void PIOS_I2C_main_adapter_er_irq_handler(void) -{ - /* Call into the generic code to handle the IRQ for this specific device */ - PIOS_I2C_ER_IRQ_Handler(PIOS_I2C_MAIN_ADAPTER); -} - -#endif /* PIOS_INCLUDE_I2C */