dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_board.c
Go to the documentation of this file.
1 
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, see <http://www.gnu.org/licenses/>
28  */
29 
30 /* Pull in the board-specific static HW definitions.
31  * Including .c files is a bit ugly but this allows all of
32  * the HW definitions to be const and static to limit their
33  * scope.
34  *
35  * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE
36  */
37 #include "board_hw_defs.c"
38 
39 #include <pios_board_info.h>
40 #include <pios.h>
41 
43 
45 {
46  /* Delay system */
48 
49  const struct pios_board_info * bdinfo = &pios_board_info_blob;
50 
51 #if defined(PIOS_INCLUDE_ANNUNC)
52  const struct pios_annunc_cfg * led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev);
53  PIOS_Assert(led_cfg);
54  PIOS_ANNUNC_Init(led_cfg);
55 #endif /* PIOS_INCLUDE_ANNUNC */
56 
57 
58 #if defined(PIOS_INCLUDE_SPI)
59  /* Set up the SPI interface to the flash and rfm22b */
60  if (PIOS_SPI_Init(&pios_spi_telem_flash_id, &pios_spi_telem_flash_cfg)) {
62  }
63 #endif /* PIOS_INCLUDE_SPI */
64 
65 #if defined(PIOS_INCLUDE_FLASH)
66  /* Inititialize all flash drivers */
67  bool flash_chip_ok = false;
68  for (int i = 0; i < NELEMENTS(flash_chip_cfgs); i++) {
69  if (PIOS_Flash_Jedec_Init(&pios_external_flash_id, pios_spi_telem_flash_id,
70  1, &flash_chip_cfgs[i]) == 0) {
71  flash_chip_ok = true;
72  break;
73  }
74  }
75 
76  PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg);
77 
78  if (!flash_chip_ok) {
79  pios_external_flash_id = 0;
80 
81  /* Override configuration for Omnibus things */
82  PIOS_ANNUNC_Init(&pios_annunc_omnibus_cfg);
83  }
84 
85  const struct pios_flash_partition * flash_partition_table;
86  uint32_t num_partitions;
87 
88  flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->board_rev, &num_partitions);
89 
90  /* Register the partition table */
91  PIOS_FLASH_register_partition_table(flash_partition_table, num_partitions);
92 #endif /* PIOS_INCLUDE_FLASH */
93 
94 #if defined(PIOS_INCLUDE_USB)
95  /* Initialize board specific USB data */
97 
98  /* Activate the HID-only USB configuration */
100 
101  uintptr_t pios_usb_id;
102  PIOS_USB_Init(&pios_usb_id, PIOS_BOARD_HW_DEFS_GetUsbCfg(bdinfo->board_rev));
103 
104 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM_MSG)
105  uintptr_t pios_usb_hid_id;
106  if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
107  PIOS_Assert(0);
108  }
110  PIOS_Assert(0);
111  }
112 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM_MSG */
113 
115 
116 #endif /* PIOS_INCLUDE_USB */
117 }
118 
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
Main PiOS header to include all the compiled in PiOS options.
#define NELEMENTS(x)
Definition: pios.h:192
int32_t PIOS_Flash_Jedec_Init(uintptr_t *flash_id, pios_spi_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg *cfg)
#define PIOS_DEBUG_Assert(test)
Definition: pios_debug.h:51
int32_t PIOS_USB_HID_Init(uintptr_t *usbhid_id, const struct pios_usb_hid_cfg *cfg, uintptr_t lower_id)
int32_t PIOS_DELAY_Init(void)
Definition: pios_delay.c:98
const struct pios_board_info pios_board_info_blob
const struct pios_com_driver pios_usb_hid_com_driver
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
void PIOS_Board_Init()
Definition: pios_board.c:44
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
uint8_t i
Definition: msp_messages.h:97
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
uintptr_t pios_com_telem_usb_id
Definition: pios_board.c:42
int32_t PIOS_COM_MSG_Init(uintptr_t *com_id, const struct pios_com_driver *driver, uintptr_t lower_id)
void PIOS_USBHOOK_Activate(void)
Definition: pios_usbhook.c:80
void PIOS_FLASH_register_partition_table(const struct pios_flash_partition partition_table[], uint8_t num_partitions)
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
#define PIOS_Assert(test)
Definition: pios_debug.h:52
int32_t PIOS_USB_BOARD_DATA_Init(void)