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 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 /* Pull in the board-specific static HW definitions.
36  * Including .c files is a bit ugly but this allows all of
37  * the HW definitions to be const and static to limit their
38  * scope.
39  *
40  * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE
41  */
42 #include "board_hw_defs.c"
43 
44 #include <pios_board_info.h>
45 #include <pios.h>
46 
47 #ifdef PIOS_INCLUDE_WS2811
48 #include <pios_ws2811.h>
49 #endif
50 
52 
54  /* Absolute first thing-- drive the video mask pin low */
55  GPIO_Init(video_mask_pin.gpio, (GPIO_InitTypeDef *)&video_mask_pin.init);
56  GPIO_WriteBit(video_mask_pin.gpio,
57  video_mask_pin.init.GPIO_Pin, Bit_RESET);
58 
59  /* Delay system */
61 
62  const struct pios_board_info * bdinfo = &pios_board_info_blob;
63 
64 #if defined(PIOS_INCLUDE_ANNUNC)
65  const struct pios_annunc_cfg * led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev);
66  PIOS_Assert(led_cfg);
67  PIOS_ANNUNC_Init(led_cfg);
68 #endif /* PIOS_INCLUDE_ANNUNC */
69 
70 #ifdef PIOS_INCLUDE_WS2811
73 #endif
74 
75  if ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL) {
76  /* Oh no. We're not clocked from PLL, that is DEFINITELY
77  * not what we expect. */
78 
79  while (true) {
80 #ifdef PIOS_INCLUDE_ANNUNC
81 #if defined(PIOS_LED_HEARTBEAT)
83  for (int i=0; i < 500000; i++) {
84  asm volatile ("nop"::);
85  }
87  for (int i=0; i < 500000; i++) {
88  asm volatile ("nop"::);
89  }
90 #endif /* PIOS_LED_HEARTBEAT */
91 #endif /* PIOS_INCLUDE_ANNUNC */
92  }
93  }
94 
95 #if defined(PIOS_INCLUDE_FLASH)
96  /* Inititialize all flash drivers */
97  PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg);
98 
99  /* Register the partition table */
101 #endif /* PIOS_INCLUDE_FLASH */
102 
103 #if defined(PIOS_INCLUDE_USB)
104  /* Initialize board specific USB data */
106 
107  /* Activate the HID-only USB configuration */
109 
110  uintptr_t pios_usb_id;
111  PIOS_USB_Init(&pios_usb_id, PIOS_BOARD_HW_DEFS_GetUsbCfg(bdinfo->board_rev));
112 
113 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM_MSG)
114  uintptr_t pios_usb_hid_id;
115  if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
116  PIOS_Assert(0);
117  }
119  PIOS_Assert(0);
120  }
121 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM_MSG */
122 
124 
125 #endif /* PIOS_INCLUDE_USB */
126 }
127 
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
const struct stm32_gpio video_mask_pin
Main PiOS header to include all the compiled in PiOS options.
GPIO_InitTypeDef init
Definition: pios_stm32.h:61
#define NELEMENTS(x)
Definition: pios.h:192
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
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
void PIOS_ANNUNC_Off(uint32_t annunc_id)
const struct pios_board_info pios_board_info_blob
int PIOS_WS2811_init(ws2811_dev_t *dev_out, const struct pios_ws2811_cfg *cfg, int max_leds)
Allocate and initialise WS2811 device.
Definition: pios_ws2811.c:64
const struct pios_com_driver pios_usb_hid_com_driver
ws2811_dev_t pios_ws2811
Definition: pios_board.c:66
void PIOS_Board_Init()
Definition: pios_board.c:44
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
void PIOS_ANNUNC_On(uint32_t annunc_id)
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)
void PIOS_WS2811_trigger_update(ws2811_dev_t dev)
Trigger an update of the LED strand.
Definition: pios_ws2811.c:197
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
#define PIOS_Assert(test)
Definition: pios_debug.h:52
int32_t PIOS_USB_BOARD_DATA_Init(void)
#define PIOS_LED_HEARTBEAT
Definition: pios_board.h:85