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 
31 #include <pios.h>
32 #include <openpilot.h>
33 #include <board_hw_defs.c>
34 #include <manualcontrolsettings.h>
35 #include <modulesettings.h>
36 #include <hwtaulink.h>
37 #include <pios_hal.h>
38 
40 #if defined(PIOS_INCLUDE_PPM)
41 uintptr_t pios_ppm_rcvr_id;
42 #endif
43 
45 
46 #define PIOS_COM_TELEM_RX_BUF_LEN 450
47 #define PIOS_COM_TELEM_TX_BUF_LEN 450
48 #define PIOS_COM_FRSKYSPORT_TX_BUF_LEN 24
49 
55 void PIOS_Board_Init(void)
56 {
57  const struct pios_board_info * bdinfo = &pios_board_info_blob;
58 
59 #if defined(PIOS_INCLUDE_ANNUNC)
61 #endif /* PIOS_INCLUDE_ANNUNC */
62 
63 #if defined(PIOS_INCLUDE_FLASH) && defined(PIOS_INCLUDE_LOGFS_SETTINGS)
64  /* Inititialize all flash drivers */
65  PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg);
66 
67  /* Register the partition table */
68  const struct pios_flash_partition * flash_partition_table;
69  uint32_t num_partitions;
70  flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->board_rev, &num_partitions);
71  PIOS_FLASH_register_partition_table(flash_partition_table, num_partitions);
72 
73  /* Mount all filesystems */
75 
76 #ifdef ERASE_FLASH
78 #if defined(PIOS_LED_HEARTBEAT)
80 #endif /* PIOS_LED_HEARTBEAT */
81  while (1);
82 #endif
83 
84 #endif /* PIOS_INCLUDE_FLASH && PIOS_INCLUDE_LOGFS_SETTINGS */
85 
86  /* Set up the SPI interface to the rfm22b */
87  if (PIOS_SPI_Init(&pios_spi_rfm22b_id, &pios_spi_rfm22b_cfg)) {
89  }
90 
91 #ifdef PIOS_INCLUDE_WDG
92  /* Initialize watchdog as early as possible to catch faults during init */
93  PIOS_WDG_Init();
94 #endif /* PIOS_INCLUDE_WDG */
95 
96 #if defined(PIOS_INCLUDE_RTC)
97  /* Initialize the real-time clock and its associated tick */
98  PIOS_RTC_Init(&pios_rtc_main_cfg);
99 #endif /* PIOS_INCLUDE_RTC */
100 
101  HwTauLinkInitialize();
102 
103 #if defined(PIOS_INCLUDE_TIM)
104  /* Set up pulse timers */
109 #endif /* PIOS_INCLUDE_TIM */
110 
111  /* Initialize board specific USB data */
113 
114  // Configure the main port
115  HwTauLinkData hwTauLink;
116  HwTauLinkGet(&hwTauLink);
117 
118  /* Flags to determine if various USB interfaces are advertised */
119  bool usb_cdc_present = false;
120 
121 #if defined(PIOS_INCLUDE_USB_CDC)
123  PIOS_Assert(0);
124  }
125  usb_cdc_present = true;
126 #else
128  PIOS_Assert(0);
129  }
130 #endif
131 
132  /*Initialize the USB device */
133  uintptr_t pios_usb_id;
134  PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
135 
136  PIOS_HAL_ConfigureHID(HWSHARED_USB_HIDPORT_USBTELEMETRY, pios_usb_id, &pios_usb_hid_cfg);
137 
138  /* Configure the USB virtual com port (VCP) */
139 #if defined(PIOS_INCLUDE_USB_CDC)
140  if (usb_cdc_present) {
141  PIOS_HAL_ConfigureCDC(hwTauLink.VCPPort, pios_usb_id, &pios_usb_cdc_cfg);
142  }
143 #endif
144 
145  PIOS_HAL_ConfigurePort(hwTauLink.MainPort, // port type protocol
146  &pios_usart_serial_cfg, // usart_port_cfg
147  &pios_usart_com_driver, // com_driver
148  NULL, // i2c_id
149  NULL, // i2c_cfg
150  NULL, // ppm_cfg
151  NULL, // pwm_cfg
152  PIOS_LED_ALARM, // led_id
153  NULL, // dsm_cfg
154  0, // dsm_mode
155  NULL); // sbus_cfg
156 
157  ModuleSettingsInitialize();
158  ModuleSettingsData moduleSettings;
159  ModuleSettingsGet(&moduleSettings);
160 
161  moduleSettings.ComUsbBridgeSpeed = hwTauLink.ComSpeed;
162  moduleSettings.TelemetrySpeed = hwTauLink.ComSpeed;
163 
164  ModuleSettingsSet(&moduleSettings);
165 
166 #ifdef PIOS_INCLUDE_OPENLRS
167  const struct pios_openlrs_cfg *openlrs_cfg = PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(bdinfo->board_rev);
168 
169  PIOS_HAL_ConfigureRFM22B(pios_spi_rfm22b_id,
170  bdinfo->board_type, bdinfo->board_rev,
171  hwTauLink.RfBand, hwTauLink.MaxRfPower,
172  openlrs_cfg, &openlrs_handle);
173 #endif
174 
175  if (bdinfo->board_rev == TAULINK_VERSION_MODULE) {
176  // Configure the main serial port function
177 
178  static struct pios_usart_params pios_usart_bluetooth_params = {
179  .init = {
180  .USART_BaudRate = 9600,
181  .USART_WordLength = USART_WordLength_8b,
182  .USART_Parity = USART_Parity_No,
183  .USART_StopBits = USART_StopBits_1,
184  .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
185  .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
186  },
187  };
188 
189  switch (hwTauLink.BTPort) {
190  case HWTAULINK_BTPORT_TELEMETRY:
191  {
192  // Note: if the main port is also on telemetry the bluetooth
193  // port will take precedence
194 
195  uintptr_t pios_usart2_id;
196  if (PIOS_USART_Init(&pios_usart2_id, &pios_usart_bluetooth_cfg, &pios_usart_bluetooth_params)) {
197  PIOS_Assert(0);
198  }
202  PIOS_Assert(0);
203  }
204  }
205  break;
206  case HWTAULINK_BTPORT_COMBRIDGE:
207  {
208  // Note: if the main port is also on telemetry the bluetooth
209  // port will take precedence
210  uintptr_t pios_usart2_id;
211  if (PIOS_USART_Init(&pios_usart2_id, &pios_usart_bluetooth_cfg, &pios_usart_bluetooth_params)) {
212  PIOS_Assert(0);
213  }
217  PIOS_Assert(0);
218  }
219 
221  }
222  break;
223  case HWTAULINK_BTPORT_DISABLED:
224  break;
225  }
226  }
227 
228  // Configure the flexi port
229 
230  static struct pios_usart_params pios_usart_sport_params = {
231  .init = {
232  .USART_BaudRate = 57600,
233  .USART_WordLength = USART_WordLength_8b,
234  .USART_Parity = USART_Parity_No,
235  .USART_StopBits = USART_StopBits_1,
236  .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
237  .USART_Mode = USART_Mode_Tx,
238  },
239  };
240 
241  switch (hwTauLink.PPMPort) {
242  case HWTAULINK_PPMPORT_PPM:
243  {
244 #if defined(PIOS_INCLUDE_PPM)
245  /* PPM input is configured on the coordinator modem and sent in the RFM22BReceiver UAVO. */
246  uintptr_t pios_ppm_id;
247  PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_cfg);
248 
250  PIOS_Assert(0);
251  }
252 
253  pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM] = pios_ppm_rcvr_id;
254 #endif /* PIOS_INCLUDE_PPM */
255  break;
256  }
257  case HWTAULINK_PPMPORT_SPORT:
258 #if defined(PIOS_INCLUDE_TARANIS_SPORT)
259  PIOS_HAL_ConfigureCom(&pios_usart_sport_cfg, &pios_usart_sport_params, 0, PIOS_COM_FRSKYSPORT_TX_BUF_LEN, &pios_usart_com_driver,
261 #endif /* PIOS_INCLUDE_TARANIS_SPORT */
262  break;
263  case HWTAULINK_PPMPORT_PPMSPORT:
264  {
265 #if defined(PIOS_INCLUDE_TARANIS_SPORT)
266  PIOS_HAL_ConfigureCom(&pios_usart_sport_cfg, &pios_usart_sport_params, 0, PIOS_COM_FRSKYSPORT_TX_BUF_LEN, &pios_usart_com_driver,
268 #endif /* PIOS_INCLUDE_TARANIS_SPORT */
269 #if defined(PIOS_INCLUDE_PPM)
270  /* PPM input is configured on the coordinator modem and sent in the RFM22BReceiver UAVO. */
271  uintptr_t pios_ppm_id;
272  PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_cfg);
273 
275  PIOS_Assert(0);
276  }
277 
278 #endif /* PIOS_INCLUDE_PPM */
279  break;
280  }
281  case HWTAULINK_PPMPORT_DISABLED:
282  default:
283  break;
284  }
285 
286  /* Remap AFIO pin */
287  GPIO_PinRemapConfig( GPIO_Remap_SWJ_NoJTRST, ENABLE);
288 
289 #ifdef PIOS_INCLUDE_ADC
290  PIOS_ADC_Init();
291 #endif
292 }
293 
uintptr_t pios_com_telem_uart_bluetooth_id
Definition: pios_board.c:39
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
uintptr_t pios_com_frsky_sport_id
int32_t PIOS_USB_DESC_HID_CDC_Init(void)
void PIOS_HAL_ConfigureCDC(HwSharedUSB_VCPPortOptions port_type, uintptr_t usb_id, const struct pios_usb_cdc_cfg *cdc_cfg)
#define PIOS_COM_TELEM_RX_BUF_LEN
Definition: pios_board.c:46
Main PiOS header to include all the compiled in PiOS options.
uintptr_t pios_rcvr_group_map[]
Definition: pios_hal.c:73
#define PIOS_DEBUG_Assert(test)
Definition: pios_debug.h:51
uintptr_t pios_uavo_settings_fs_id
Definition: pios_board.c:50
void PIOS_ANNUNC_Off(uint32_t annunc_id)
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t *fs_id, const struct flashfs_logfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
#define PIOS_COM_FRSKYSPORT_TX_BUF_LEN
Definition: pios_board.c:48
const struct pios_board_info pios_board_info_blob
USART_InitTypeDef init
#define PIOS_LED_ALARM
Definition: pios_board.h:86
#define PIOS_COM_TELEM_TX_BUF_LEN
Definition: pios_board.c:47
static const struct pios_tim_clock_cfg tim_4_cfg
const struct pios_com_driver pios_usart_com_driver
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
Definition: pios_tim.c:62
int32_t PIOS_RCVR_Init(uintptr_t *rcvr_id, const struct pios_rcvr_driver *driver, const uintptr_t lower_id)
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
uintptr_t pios_ppm_rcvr_id
void PIOS_Board_Init()
Definition: pios_board.c:44
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
static const struct pios_tim_clock_cfg tim_1_cfg
void PIOS_RTC_Init(const struct pios_rtc_cfg *cfg)
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
void PIOS_HAL_ConfigureHID(HwSharedUSB_HIDPortOptions port_type, uintptr_t usb_id, const struct pios_usb_hid_cfg *hid_cfg)
int32_t PIOS_USART_Init(uintptr_t *usart_id, const struct pios_usart_cfg *cfg, struct pios_usart_params *params)
int32_t PIOS_COM_Init(uintptr_t *com_id, const struct pios_com_driver *driver, uintptr_t lower_id, uint16_t rx_buffer_len, uint16_t tx_buffer_len)
void PIOS_FLASH_register_partition_table(const struct pios_flash_partition partition_table[], uint8_t num_partitions)
int32_t PIOS_PPM_Init(uintptr_t *ppm_id, const struct pios_ppm_cfg *cfg)
Includes PiOS and core architecture components.
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
uint16_t PIOS_WDG_Init()
Initialize the watchdog timer for a specified timeout.
Definition: pios_wdg.c:63
int32_t PIOS_ADC_Init(uintptr_t *adc_id, const struct pios_adc_driver *driver, uintptr_t lower_id)
static const struct pios_tim_clock_cfg tim_3_cfg
int32_t PIOS_FLASHFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
const struct pios_rcvr_driver pios_ppm_rcvr_driver
uintptr_t pios_com_bridge_id
Definition: pios_hal.c:81
static const struct pios_tim_clock_cfg tim_2_cfg
#define PIOS_Assert(test)
Definition: pios_debug.h:52
#define TAULINK_VERSION_MODULE
Definition: pios_board.h:34
int32_t PIOS_USB_BOARD_DATA_Init(void)
#define PIOS_LED_HEARTBEAT
Definition: pios_board.h:85