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 
38 #include "board_hw_defs.c"
39 
40 #include <pios.h>
41 #include <pios_hal.h>
42 #include <openpilot.h>
43 #include <uavobjectsinit.h>
44 #include "hwquanton.h"
45 #include "manualcontrolsettings.h"
46 #include "modulesettings.h"
47 #include "rgbledsettings.h"
48 
52 
54 
61 #include <pios_board_info.h>
62 
63 void PIOS_Board_Init(void) {
64  const struct pios_board_info * bdinfo = &pios_board_info_blob;
65 
66 #if defined(PIOS_INCLUDE_ANNUNC)
67  const struct pios_annunc_cfg * led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev);
68  PIOS_Assert(led_cfg);
69  PIOS_ANNUNC_Init(led_cfg);
70 #endif /* PIOS_INCLUDE_ANNUNC */
71 
72 #if defined(PIOS_INCLUDE_SPI)
73  if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
75  }
76  if (PIOS_SPI_Init(&pios_spi_gyro_accel_id, &pios_spi_gyro_accel_cfg)) {
77  PIOS_Assert(0);
78  }
79 #endif
80 
81 
82 #if defined(PIOS_INCLUDE_FLASH)
83  /* Inititialize all flash drivers */
84  if (PIOS_Flash_Jedec_Init(&pios_external_flash_id, pios_spi_flash_id, 0, &flash_mx25_cfg) != 0)
86  if (PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg) != 0)
88 
89  /* Register the partition table */
90  const struct pios_flash_partition * flash_partition_table;
91  uint32_t num_partitions;
92  flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->board_rev, &num_partitions);
93  PIOS_FLASH_register_partition_table(flash_partition_table, num_partitions);
94 
95  /* Mount all filesystems */
98 #endif /* PIOS_INCLUDE_FLASH */
99 
100  PIOS_RESET_Clear(); // Clear the RCC reset flags after use.
101 
102  /* Initialize the hardware UAVOs */
103  HwQuantonInitialize();
104  ModuleSettingsInitialize();
105 
106 #if defined(PIOS_INCLUDE_RTC)
107  /* Initialize the real-time clock and its associated tick */
108  PIOS_RTC_Init(&pios_rtc_main_cfg);
109 #endif
110 
111  /* Initialize watchdog as early as possible to catch faults during init
112  * but do it only if there is no debugger connected
113  */
114  if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
115  PIOS_WDG_Init();
116  }
117 
118  /* Set up pulse timers */
119  //Timers used for inputs (1, 2, 5, 8)
124  // Timers used for outputs (3, 10, 11, 12)
129 
130  /* IAP System Setup */
131  PIOS_IAP_Init();
132  uint16_t boot_count = PIOS_IAP_ReadBootCount();
133  if (boot_count < 3) {
134  PIOS_IAP_WriteBootCount(++boot_count);
135  AlarmsClear(SYSTEMALARMS_ALARM_BOOTFAULT);
136  } else {
137  /* Too many failed boot attempts, force hw config to defaults */
138  HwQuantonSetDefaults(HwQuantonHandle(), 0);
139  ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
140  AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
141  }
142 
143 #if defined(PIOS_INCLUDE_USB)
144  /* Initialize board specific USB data */
146 
147  /* Flags to determine if various USB interfaces are advertised */
148  bool usb_hid_present = false;
149  bool usb_cdc_present = false;
150 
151 #if defined(PIOS_INCLUDE_USB_CDC)
153  PIOS_Assert(0);
154  }
155  usb_hid_present = true;
156  usb_cdc_present = true;
157 #else
159  PIOS_Assert(0);
160  }
161  usb_hid_present = true;
162 #endif
163 
164  uintptr_t pios_usb_id;
165  PIOS_USB_Init(&pios_usb_id, PIOS_BOARD_HW_DEFS_GetUsbCfg(bdinfo->board_rev));
166 
167 #if defined(PIOS_INCLUDE_USB_CDC)
168 
169  uint8_t hw_usb_vcpport;
170  /* Configure the USB VCP port */
171  HwQuantonUSB_VCPPortGet(&hw_usb_vcpport);
172 
173  if (!usb_cdc_present) {
174  /* Force VCP port function to disabled if we haven't advertised VCP in our USB descriptor */
175  hw_usb_vcpport = HWQUANTON_USB_VCPPORT_DISABLED;
176  }
177 
178  PIOS_HAL_ConfigureCDC(hw_usb_vcpport, pios_usb_id, &pios_usb_cdc_cfg);
179 
180 #endif /* PIOS_INCLUDE_USB_CDC */
181 
182 #if defined(PIOS_INCLUDE_USB_HID)
183  /* Configure the usb HID port */
184  uint8_t hw_usb_hidport;
185  HwQuantonUSB_HIDPortGet(&hw_usb_hidport);
186 
187  if (!usb_hid_present) {
188  /* Force HID port function to disabled if we haven't advertised HID in our USB descriptor */
189  hw_usb_hidport = HWQUANTON_USB_HIDPORT_DISABLED;
190  }
191 
192  PIOS_HAL_ConfigureHID(hw_usb_hidport, pios_usb_id, &pios_usb_hid_cfg);
193 
194 #endif /* PIOS_INCLUDE_USB_HID */
195 
196  if (usb_hid_present || usb_cdc_present) {
198  }
199 #endif /* PIOS_INCLUDE_USB */
200 
201  /* Configure the IO ports */
202 
203 #if defined(PIOS_INCLUDE_I2C)
204  if (PIOS_I2C_Init(&pios_i2c_internal_adapter_id, &pios_i2c_internal_adapter_cfg)) {
206  }
207  if (PIOS_I2C_CheckClear(pios_i2c_internal_adapter_id) != 0)
209  else
210  if (AlarmsGet(SYSTEMALARMS_ALARM_I2C) == SYSTEMALARMS_ALARM_UNINITIALISED)
211  AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_OK);
212 #endif
213 
214  HwQuantonDSMxModeOptions hw_DSMxMode;
215  HwQuantonDSMxModeGet(&hw_DSMxMode);
216 
217  /* UART1 Port */
218  uint8_t hw_uart1;
219  HwQuantonUart1Get(&hw_uart1);
220 
221  PIOS_HAL_ConfigurePort(hw_uart1, // port type protocol
222  &pios_usart1_cfg, // usart_port_cfg
223  &pios_usart_com_driver, // com_driver
224  &pios_i2c_usart1_adapter_id, // i2c_id
225  &pios_i2c_usart1_adapter_cfg, // i2c_cfg
226  NULL, // ppm_cfg
227  NULL, // pwm_cfg
228  PIOS_LED_ALARM, // led_id
229  &pios_usart1_dsm_aux_cfg, // dsm_cfg
230  hw_DSMxMode, // dsm_mode
231  NULL); // sbus_cfg
232 
233  /* UART2 Port */
234  uint8_t hw_uart2;
235  HwQuantonUart2Get(&hw_uart2);
236 
237  PIOS_HAL_ConfigurePort(hw_uart2, // port type protocol
238  &pios_usart2_cfg, // usart_port_cfg
239  &pios_usart_com_driver, // com_driver
240  NULL, // i2c_id
241  NULL, // i2c_cfg
242  NULL, // ppm_cfg
243  NULL, // pwm_cfg
244  PIOS_LED_ALARM, // led_id
245  &pios_usart2_dsm_aux_cfg, // dsm_cfg
246  0, // dsm_mode
247  &pios_usart2_sbus_aux_cfg); // sbus_cfg
248 
249  /* UART3 Port */
250  uint8_t hw_uart3;
251  HwQuantonUart3Get(&hw_uart3);
252 
253  PIOS_HAL_ConfigurePort(hw_uart3, // port type protocol
254  &pios_usart3_cfg, // usart_port_cfg
255  &pios_usart_com_driver, // com_driver
256  &pios_i2c_usart3_adapter_id, // i2c_id
257  &pios_i2c_usart3_adapter_cfg, // i2c_cfg
258  NULL, // ppm_cfg
259  NULL, // pwm_cfg
260  PIOS_LED_ALARM, // led_id
261  &pios_usart3_dsm_aux_cfg, // dsm_cfg
262  hw_DSMxMode, // dsm_mode
263  NULL); // sbus_cfg
264 
265  /* UART4 Port */
266  uint8_t hw_uart4;
267  HwQuantonUart4Get(&hw_uart4);
268 
269  PIOS_HAL_ConfigurePort(hw_uart4, // port type protocol
270  &pios_usart4_cfg, // usart_port_cfg
271  &pios_usart_com_driver, // com_driver
272  NULL, // i2c_id
273  NULL, // i2c_cfg
274  NULL, // ppm_cfg
275  NULL, // pwm_cfg
276  PIOS_LED_ALARM, // led_id
277  &pios_usart4_dsm_aux_cfg, // dsm_cfg
278  hw_DSMxMode, // dsm_mode
279  NULL); // sbus_cfg
280 
281  /* UART5 Port */
282  uint8_t hw_uart5;
283  HwQuantonUart5Get(&hw_uart5);
284 
285  PIOS_HAL_ConfigurePort(hw_uart5, // port type protocol
286  &pios_usart5_cfg, // usart_port_cfg
287  &pios_usart_com_driver, // com_driver
288  NULL, // i2c_id
289  NULL, // i2c_cfg
290  NULL, // ppm_cfg
291  NULL, // pwm_cfg
292  PIOS_LED_ALARM, // led_id
293  &pios_usart5_dsm_aux_cfg, // dsm_cfg
294  hw_DSMxMode, // dsm_mode
295  NULL); // sbus_cfg
296 
297  /* Configure the inport */
298  uint8_t hw_inport;
299  HwQuantonInPortGet(&hw_inport);
300 
301  switch (hw_inport) {
302  case HWQUANTON_INPORT_DISABLED:
303  break;
304 
305  case HWQUANTON_INPORT_PWM:
306  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM, // port type protocol
307  NULL, // usart_port_cfg
308  NULL, // com_driver
309  NULL, // i2c_id
310  NULL, // i2c_cfg
311  NULL, // ppm_cfg
312  &pios_pwm_cfg, // pwm_cfg
313  PIOS_LED_ALARM, // led_id
314  NULL, // dsm_cfg
315  0, // dsm_mode
316  NULL); // sbus_cfg
317  break;
318 
319  case HWQUANTON_INPORT_PWMADC:
320  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM, // port type protocol
321  NULL, // usart_port_cfg
322  NULL, // com_driver
323  NULL, // i2c_id
324  NULL, // i2c_cfg
325  NULL, // ppm_cfg
326  &pios_pwm_with_adc_cfg, // pwm_cfg
327  PIOS_LED_ALARM, // led_id
328  NULL, // dsm_cfg
329  0, // dsm_mode
330  NULL); // sbus_cfg
331  break;
332 
333  case HWQUANTON_INPORT_WS2811SERIALPPMADC:
334  /* set up alt ppm, then fall through to set up serial */
335  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM, // port type protocol
336  NULL, // usart_port_cfg
337  NULL, // com_driver
338  NULL, // i2c_id
339  NULL, // i2c_cfg
340  &pios_ppm_in4_cfg, // ppm_cfg
341  NULL, // pwm_cfg
342  PIOS_LED_ALARM, // led_id
343  NULL, // dsm_cfg
344  0, // dsm_mode
345  NULL); // sbus_cfg
346  case HWQUANTON_INPORT_PPMSERIAL:
347  case HWQUANTON_INPORT_PPMSERIALADC:
348  case HWQUANTON_INPORT_SERIAL:
349  {
350  uint8_t hw_inportserial;
351  HwQuantonInPortSerialGet(&hw_inportserial);
352 
353  PIOS_HAL_ConfigurePort(hw_inportserial, // port type protocol
354  &pios_usart_inportserial_cfg, // usart_port_cfg
355  &pios_usart_com_driver, // com_driver
356  NULL, // i2c_id
357  NULL, // i2c_cfg
358  NULL, // ppm_cfg
359  NULL, // pwm_cfg
360  PIOS_LED_ALARM, // led_id
361  &pios_inportserial_dsm_aux_cfg, // dsm_cfg
362  hw_DSMxMode, // dsm_mode
363  NULL); // sbus_cfg
364  }
365 
366  if (hw_inport == HWQUANTON_INPORT_SERIAL)
367  break;
368 
369  if (hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC)
370  break;
371 
372  // Else fall through to set up PPM.
373 
374  case HWQUANTON_INPORT_PPM:
375  case HWQUANTON_INPORT_PPMADC:
376  case HWQUANTON_INPORT_PPMOUTPUTS:
377  case HWQUANTON_INPORT_PPMOUTPUTSADC:
378  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM, // port type protocol
379  NULL, // usart_port_cfg
380  NULL, // com_driver
381  NULL, // i2c_id
382  NULL, // i2c_cfg
383  &pios_ppm_cfg, // ppm_cfg
384  NULL, // pwm_cfg
385  PIOS_LED_ALARM, // led_id
386  NULL, // dsm_cfg
387  0, // dsm_mode
388  NULL); // sbus_cfg
389  break;
390 
391  case HWQUANTON_INPORT_PPMPWM:
392  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM, // port type protocol
393  NULL, // usart_port_cfg
394  NULL, // com_driver
395  NULL, // i2c_id
396  NULL, // i2c_cfg
397  &pios_ppm_cfg, // ppm_cfg
398  NULL, // pwm_cfg
399  PIOS_LED_ALARM, // led_id
400  NULL, // dsm_cfg
401  0, // dsm_mode
402  NULL); // sbus_cfg
403 
404  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM, // port type protocol
405  NULL, // usart_port_cfg
406  NULL, // com_driver
407  NULL, // i2c_id
408  NULL, // i2c_cfg
409  NULL, // ppm_cfg
410  &pios_pwm_with_ppm_cfg, // pwm_cfg
411  PIOS_LED_ALARM, // led_id
412  NULL, // dsm_cfg
413  0, // dsm_mode
414  NULL); // sbus_cfg
415  break;
416 
417  case HWQUANTON_INPORT_PPMPWMADC:
418  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PPM, // port type protocol
419  NULL, // usart_port_cfg
420  NULL, // com_driver
421  NULL, // i2c_id
422  NULL, // i2c_cfg
423  &pios_ppm_cfg, // ppm_cfg
424  NULL, // pwm_cfg
425  PIOS_LED_ALARM, // led_id
426  NULL, // dsm_cfg
427  0, // dsm_mode
428  NULL); // sbus_cfg
429 
430  PIOS_HAL_ConfigurePort(HWSHARED_PORTTYPES_PWM, // port type protocol
431  NULL, // usart_port_cfg
432  NULL, // com_driver
433  NULL, // i2c_id
434  NULL, // i2c_cfg
435  NULL, // ppm_cfg
436  &pios_pwm_with_ppm_with_adc_cfg, // pwm_cfg
437  PIOS_LED_ALARM, // led_id
438  NULL, // dsm_cfg
439  0, // dsm_mode
440  NULL); // sbus_cfg
441  break;
442  }
443 
444 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
445  switch (hw_inport) {
446  case HWQUANTON_INPORT_DISABLED:
447  case HWQUANTON_INPORT_PWM:
448  case HWQUANTON_INPORT_PWMADC:
449  case HWQUANTON_INPORT_PPM:
450  case HWQUANTON_INPORT_PPMADC:
451  case HWQUANTON_INPORT_PPMPWM:
452  case HWQUANTON_INPORT_PPMPWMADC:
453  case HWQUANTON_INPORT_WS2811SERIALPPMADC:
454  /* Set up the servo outputs */
455 #ifdef PIOS_INCLUDE_SERVO
457 #endif
458  break;
459  case HWQUANTON_INPORT_PPMOUTPUTS:
460 #ifdef PIOS_INCLUDE_SERVO
461  PIOS_Servo_Init(&pios_servo_with_rcvr_ppm_cfg);
462 #endif
463  break;
464  case HWQUANTON_INPORT_OUTPUTS:
465 #ifdef PIOS_INCLUDE_SERVO
466  PIOS_Servo_Init(&pios_servo_with_rcvr_cfg);
467 #endif
468  break;
469  case HWQUANTON_INPORT_PPMOUTPUTSADC:
470 #ifdef PIOS_INCLUDE_SERVO
471  PIOS_Servo_Init(&pios_servo_with_rcvr_ppm_with_adc_cfg);
472 #endif
473  break;
474  case HWQUANTON_INPORT_OUTPUTSADC:
475 #ifdef PIOS_INCLUDE_SERVO
476  PIOS_Servo_Init(&pios_servo_with_rcvr_with_adc_cfg);
477 #endif
478  break;
479  }
480 #else
481  PIOS_DEBUG_Init(&pios_tim_servo_all_channels, NELEMENTS(pios_tim_servo_all_channels));
482 #endif
483 
484 #ifdef PIOS_INCLUDE_WS2811
485  RGBLEDSettingsInitialize();
486 
487  if (hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC) {
488  uint8_t temp;
489 
490  RGBLEDSettingsNumLedsGet(&temp);
491 
492  if (temp > 0) {
494 
495  // Drive default value (off) to strand once at startup
497  }
498  }
499 #endif
500 
501 /* init sensor queue registration */
503 
504  PIOS_WDG_Clear();
505  PIOS_DELAY_WaitmS(200);
506  PIOS_WDG_Clear();
507 
508 #if defined(PIOS_INCLUDE_MPU)
509  pios_mpu_dev_t mpu_dev = NULL;
510  if (PIOS_MPU_SPI_Init(&mpu_dev, pios_spi_gyro_accel_id, 0, &pios_mpu_cfg) != 0)
512 
513  HwQuantonGyroRangeOptions hw_gyro_range;
514  HwQuantonGyroRangeGet(&hw_gyro_range);
515  switch(hw_gyro_range) {
516  case HWQUANTON_GYRORANGE_250:
518  break;
519  case HWQUANTON_GYRORANGE_500:
521  break;
522  case HWQUANTON_GYRORANGE_1000:
524  break;
525  case HWQUANTON_GYRORANGE_2000:
527  break;
528  }
529 
530  HwQuantonAccelRangeOptions hw_accel_range;
531  HwQuantonAccelRangeGet(&hw_accel_range);
532  switch(hw_accel_range) {
533  case HWQUANTON_ACCELRANGE_2G:
535  break;
536  case HWQUANTON_ACCELRANGE_4G:
538  break;
539  case HWQUANTON_ACCELRANGE_8G:
541  break;
542  case HWQUANTON_ACCELRANGE_16G:
544  break;
545  }
546 
547  // the filter has to be set before rate else divisor calculation will fail
548  HwQuantonMPU6000DLPFOptions hw_mpu_dlpf;
549  HwQuantonMPU6000DLPFGet(&hw_mpu_dlpf);
550  uint16_t bandwidth = \
551  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_188) ? 188 : \
552  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_98) ? 98 : \
553  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_42) ? 42 : \
554  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_20) ? 20 : \
555  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_10) ? 10 : \
556  (hw_mpu_dlpf == HWQUANTON_MPU6000DLPF_5) ? 5 : \
557  188;
558  PIOS_MPU_SetGyroBandwidth(bandwidth);
559 #endif
560 
561 #if defined(PIOS_INCLUDE_I2C)
562 
563  PIOS_WDG_Clear();
564 
565  uint8_t hw_magnetometer;
566  HwQuantonMagnetometerGet(&hw_magnetometer);
567 
568  switch (hw_magnetometer) {
569  case HWQUANTON_MAGNETOMETER_NONE:
570  break;
571 
572  case HWQUANTON_MAGNETOMETER_INTERNAL:
573 #if defined(PIOS_INCLUDE_HMC5883)
574  if ((PIOS_HMC5883_Init(pios_i2c_internal_adapter_id, &pios_hmc5883_internal_cfg) != 0) ||
575  (PIOS_HMC5883_Test() != 0)) {
577  }
578 #endif /* PIOS_INCLUDE_HMC5883 */
579  break;
580 
581  /* default external mags and handle them in PiOS HAL rather than maintaining list here */
582  default:
583  {
584  HwQuantonExtMagPortOptions hw_mag_port;
585  HwQuantonExtMagPortGet(&hw_mag_port);
586 
587  pios_i2c_t i2c_mag_id = NULL;
588  const void *i2c_mag_cfg = NULL;
589  switch (hw_mag_port) {
590  case HWQUANTON_EXTMAGPORT_UART1:
591  if (hw_uart1 == HWSHARED_PORTTYPES_I2C) {
592  i2c_mag_id = pios_i2c_usart1_adapter_id;
593  i2c_mag_cfg = &pios_i2c_usart1_adapter_cfg;
594  }
595  break;
596  case HWQUANTON_EXTMAGPORT_UART3:
597  if (hw_uart3 == HWSHARED_PORTTYPES_I2C) {
598  i2c_mag_id = pios_i2c_usart3_adapter_id;
599  i2c_mag_cfg = &pios_i2c_usart3_adapter_cfg;
600  }
601  break;
602  }
603 
604  if (i2c_mag_id && i2c_mag_cfg) {
605  uint8_t hw_orientation;
606  HwQuantonExtMagOrientationGet(&hw_orientation);
607 
608  PIOS_HAL_ConfigureExternalMag(hw_magnetometer, hw_orientation,
609  &i2c_mag_id, i2c_mag_cfg);
610  } else {
612  }
613  }
614  break;
615  }
616 
617  /* I2C is slow, sensor init as well, reset watchdog to prevent reset here */
618  PIOS_WDG_Clear();
619 
620 #if defined(PIOS_INCLUDE_MS5611)
621  if ((PIOS_MS5611_Init(&pios_ms5611_cfg, pios_i2c_internal_adapter_id) != 0)
622  || (PIOS_MS5611_Test() != 0))
624 #endif
625 
626  //I2C is slow, sensor init as well, reset watchdog to prevent reset here
627  PIOS_WDG_Clear();
628 
629 #endif /* PIOS_INCLUDE_I2C */
630 
631 #if defined(PIOS_INCLUDE_ADC)
632  if (hw_inport == HWQUANTON_INPORT_OUTPUTSADC ||
633  hw_inport == HWQUANTON_INPORT_PPMADC ||
634  hw_inport == HWQUANTON_INPORT_PPMOUTPUTSADC ||
635  hw_inport == HWQUANTON_INPORT_PPMPWMADC ||
636  hw_inport == HWQUANTON_INPORT_PPMSERIALADC ||
637  hw_inport == HWQUANTON_INPORT_PWMADC ||
638  hw_inport == HWQUANTON_INPORT_WS2811SERIALPPMADC)
639  {
640  uintptr_t internal_adc_id;
641  PIOS_INTERNAL_ADC_Init(&internal_adc_id, &pios_adc_cfg);
643  }
644 #endif
645 
646  //Set battery input pin to output, because of the voltage divider usage as input is not useful
647  //Take care of the voltage divider connected to this pin
648  GPIO_InitTypeDef GPIO_InitStructure;
649  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
650  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
651  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
652  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
653  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
654  GPIO_Init(GPIOC, &GPIO_InitStructure);
655  GPIO_ResetBits(GPIOC, GPIO_Pin_15);
656 
657  //Set buzzer output to low as long as it is unused
658  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
659  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
660  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
661  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
662  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
663  GPIO_Init(GPIOA, &GPIO_InitStructure);
664  GPIO_ResetBits(GPIOA, GPIO_Pin_4);
665 
666  /* Make sure we have at least one telemetry link configured or else fail initialization */
668 }
669 
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
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)
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_INTERNAL_ADC_Init(uintptr_t *internal_adc_id, const struct pios_internal_adc_cfg *cfg)
int32_t PIOS_I2C_CheckClear(pios_i2c_t i2c_id)
int32_t PIOS_HMC5883_Test(void)
#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
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
Definition: pios_hal.c:1298
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
Definition: alarms.c:97
uintptr_t pios_uavo_settings_fs_id
Definition: pios_board.c:50
uint16_t PIOS_IAP_ReadBootCount(void)
Definition: pios_iap.c:93
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.
static const struct pios_tim_clock_cfg tim_8_cfg
const struct pios_board_info pios_board_info_blob
struct pios_mpu_dev * pios_mpu_dev_t
Definition: pios_mpu.h:150
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
#define PIOS_LED_ALARM
Definition: pios_board.h:86
Configuration structure for the MS5611 driver.
int32_t PIOS_I2C_Init(pios_i2c_t *i2c_id, const char *path)
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
Definition: pios_wdg.c:147
int32_t PIOS_MPU_SPI_Init(pios_mpu_dev_t *dev, pios_spi_t spi_id, uint32_t slave_num, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on SPI.
void PIOS_DEBUG_Init(const struct pios_tim_channel *channels, uint8_t num_channels)
Definition: pios_debug.c:44
uintptr_t pios_com_telem_serial_id
Definition: pios_hal.c:127
const struct pios_com_driver pios_usart_com_driver
pios_i2c_t external_i2c_adapter_id
Definition: pios_board.c:53
static const struct pios_tim_clock_cfg tim_5_cfg
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
Definition: pios_iap.c:44
int32_t PIOS_MPU_SetAccelRange(enum pios_mpu_accel_range range)
const struct pios_adc_driver pios_internal_adc_driver
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
Definition: pios_tim.c:62
uintptr_t pios_internal_adc_id
Definition: pios_board.c:51
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
ws2811_dev_t pios_ws2811
Definition: pios_board.c:66
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)
static const struct pios_tim_clock_cfg tim_1_cfg
int32_t PIOS_SENSORS_Init()
Initialize the PIOS_SENSORS interface.
Definition: pios_sensors.c:51
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_Servo_Init(const struct pios_servo_cfg *cfg)
Definition: pios_servo.c:109
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
uintptr_t pios_com_openlog_logging_id
Definition: pios_board.c:49
uintptr_t pios_com_telem_usb_id
Definition: pios_board.c:42
static const struct pios_tim_clock_cfg tim_12_cfg
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_HMC5883_Init(pios_i2c_t i2c_id, const struct pios_hmc5883_cfg *cfg)
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
Definition: alarms.c:171
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)
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)
void PIOS_IAP_WriteBootCount(uint16_t)
Definition: pios_iap.c:98
int32_t PIOS_MS5611_Init(const struct pios_ms5611_cfg *cfg, pios_i2c_t i2c_device)
static const struct pios_tim_clock_cfg tim_3_cfg
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
Definition: pios_hal.c:291
static const struct pios_tim_clock_cfg tim_2_cfg
static const struct pios_tim_clock_cfg tim_10_cfg
#define PIOS_Assert(test)
Definition: pios_debug.h:52
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
Definition: pios_delay.c:140
int32_t PIOS_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
int32_t PIOS_USB_BOARD_DATA_Init(void)
static const struct pios_tim_clock_cfg tim_11_cfg
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm)
Definition: alarms.c:129
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.
Definition: pios_reset.c:38
void PIOS_SENSORS_SetMissing(enum pios_sensor_type type)
Assert that an optional (non-accel/gyro), but expected sensor is missing.
Definition: pios_sensors.c:191