|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @addtogroup TauLabsBootloader Tau Labs Bootloaders |
| 4 | + * @{ |
| 5 | + * @addtogroup QuantonBL Quanton bootloader |
| 6 | + * @{ |
| 7 | + * |
| 8 | + * @file pios_board.c |
| 9 | + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. |
| 10 | + * @author Tau Labs, http://taulabs.org, Copyright (C) 2012-2013 |
| 11 | + * @brief Board specific initialization for the bootloader |
| 12 | + * @see The GNU Public License (GPL) Version 3 |
| 13 | + * |
| 14 | + *****************************************************************************/ |
| 15 | +/* |
| 16 | + * This program is free software; you can redistribute it and/or modify |
| 17 | + * it under the terms of the GNU General Public License as published by |
| 18 | + * the Free Software Foundation; either version 3 of the License, or |
| 19 | + * (at your option) any later version. |
| 20 | + * |
| 21 | + * This program is distributed in the hope that it will be useful, but |
| 22 | + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 23 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 24 | + * for more details. |
| 25 | + * |
| 26 | + * You should have received a copy of the GNU General Public License along |
| 27 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 28 | + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | + */ |
| 30 | + |
| 31 | +/* Pull in the board-specific static HW definitions. |
| 32 | + * Including .c files is a bit ugly but this allows all of |
| 33 | + * the HW definitions to be const and static to limit their |
| 34 | + * scope. |
| 35 | + * |
| 36 | + * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE |
| 37 | + */ |
| 38 | +#include "board_hw_defs.c" |
| 39 | + |
| 40 | +#include <pios_board_info.h> |
| 41 | +#include <pios.h> |
| 42 | + |
| 43 | +uintptr_t pios_com_telem_usb_id; |
| 44 | + |
| 45 | +void PIOS_Board_Init() { |
| 46 | + |
| 47 | + /* Delay system */ |
| 48 | + PIOS_DELAY_Init(); |
| 49 | + |
| 50 | + const struct pios_board_info * bdinfo = &pios_board_info_blob; |
| 51 | + |
| 52 | +#if defined(PIOS_INCLUDE_LED) |
| 53 | + const struct pios_led_cfg * led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); |
| 54 | + PIOS_Assert(led_cfg); |
| 55 | + PIOS_LED_Init(led_cfg); |
| 56 | +#endif /* PIOS_INCLUDE_LED */ |
| 57 | + |
| 58 | + PWR_BackupAccessCmd(ENABLE); |
| 59 | + RCC_LSEConfig(RCC_LSE_OFF); |
| 60 | + |
| 61 | + PIOS_LED_On(PIOS_LED_HEARTBEAT); |
| 62 | + PIOS_LED_On(PIOS_LED_ALARM); |
| 63 | + |
| 64 | +#if defined(PIOS_INCLUDE_SPI) |
| 65 | + /* Set up the SPI interface to the flash */ |
| 66 | + if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) { |
| 67 | + PIOS_DEBUG_Assert(0); |
| 68 | + } |
| 69 | +#endif /* PIOS_INCLUDE_SPI */ |
| 70 | + |
| 71 | +#if defined(PIOS_INCLUDE_FLASH) |
| 72 | + /* Inititialize all flash drivers */ |
| 73 | + PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg); |
| 74 | + |
| 75 | +#if defined(PIOS_INCLUDE_SPI) |
| 76 | + PIOS_Flash_Jedec_Init(&pios_external_flash_id, pios_spi_flash_id, 0, &flash_mx25_cfg); |
| 77 | +#endif /* PIOS_INCLUDE_SPI */ |
| 78 | + |
| 79 | + /* Register the partition table */ |
| 80 | + PIOS_FLASH_register_partition_table(pios_flash_partition_table, NELEMENTS(pios_flash_partition_table)); |
| 81 | +#endif /* PIOS_INCLUDE_FLASH */ |
| 82 | + |
| 83 | +#if defined(PIOS_INCLUDE_USB) |
| 84 | + /* Initialize board specific USB data */ |
| 85 | + PIOS_USB_BOARD_DATA_Init(); |
| 86 | + |
| 87 | + /* Activate the HID-only USB configuration */ |
| 88 | + PIOS_USB_DESC_HID_ONLY_Init(); |
| 89 | + |
| 90 | + uintptr_t pios_usb_id; |
| 91 | + PIOS_USB_Init(&pios_usb_id, PIOS_BOARD_HW_DEFS_GetUsbCfg(bdinfo->board_rev)); |
| 92 | + |
| 93 | +#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM_MSG) |
| 94 | + uintptr_t pios_usb_hid_id; |
| 95 | + if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) { |
| 96 | + PIOS_Assert(0); |
| 97 | + } |
| 98 | + if (PIOS_COM_MSG_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id)) { |
| 99 | + PIOS_Assert(0); |
| 100 | + } |
| 101 | +#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM_MSG */ |
| 102 | + |
| 103 | + PIOS_USBHOOK_Activate(); |
| 104 | + |
| 105 | +#endif /* PIOS_INCLUDE_USB */ |
| 106 | +} |
0 commit comments