38 #include "board_hw_defs.c"
43 #include <uavobjectsinit.h>
45 #include "manualcontrolsettings.h"
46 #include "modulesettings.h"
49 #define PIOS_COM_CAN_RX_BUF_LEN 256
50 #define PIOS_COM_CAN_TX_BUF_LEN 256
70 #if defined(PIOS_INCLUDE_ANNUNC)
76 #if defined(PIOS_INCLUDE_CAN)
88 #if defined(PIOS_INCLUDE_FLASH)
95 uint32_t num_partitions;
96 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
102 #if defined(ERASE_FLASH)
111 HwSparkyInitialize();
112 ModuleSettingsInitialize();
114 #if defined(PIOS_INCLUDE_RTC)
122 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
140 if (boot_count < 3) {
145 HwSparkySetDefaults(HwSparkyHandle(), 0);
146 ModuleSettingsSetDefaults(ModuleSettingsHandle(), 0);
147 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
150 #if defined(PIOS_INCLUDE_USB)
155 bool usb_hid_present =
false;
157 #if defined(PIOS_INCLUDE_USB_CDC)
158 bool usb_cdc_present =
false;
162 usb_hid_present =
true;
163 usb_cdc_present =
true;
168 usb_hid_present =
true;
171 uintptr_t pios_usb_id;
174 #if defined(PIOS_INCLUDE_USB_CDC)
176 uint8_t hw_usb_vcpport;
178 HwSparkyUSB_VCPPortGet(&hw_usb_vcpport);
180 if (!usb_cdc_present) {
182 hw_usb_vcpport = HWSPARKY_USB_VCPPORT_DISABLED;
188 #if defined(PIOS_INCLUDE_USB_HID)
190 uint8_t hw_usb_hidport;
191 HwSparkyUSB_HIDPortGet(&hw_usb_hidport);
193 if (!usb_hid_present) {
195 hw_usb_hidport = HWSPARKY_USB_HIDPORT_DISABLED;
205 #if defined(PIOS_INCLUDE_I2C)
206 if (
PIOS_I2C_Init(&pios_i2c_internal_id, &pios_i2c_internal_cfg))
212 if (
AlarmsGet(SYSTEMALARMS_ALARM_I2C) == SYSTEMALARMS_ALARM_UNINITIALISED)
213 AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_OK);
214 #endif // PIOS_INCLUDE_I2C
216 HwSparkyDSMxModeOptions hw_DSMxMode;
217 HwSparkyDSMxModeGet(&hw_DSMxMode);
221 HwSparkyMainPortGet(&hw_mainport);
223 PIOS_HAL_ConfigurePort(hw_mainport,
224 &pios_main_usart_cfg,
231 &pios_main_dsm_aux_cfg,
236 uint8_t hw_flexiport;
237 HwSparkyFlexiPortGet(&hw_flexiport);
239 PIOS_HAL_ConfigurePort(hw_flexiport,
240 &pios_flexi_usart_cfg,
247 &pios_flexi_dsm_aux_cfg,
253 HwSparkyRcvrPortGet(&hw_rcvrport);
255 PIOS_HAL_ConfigurePort(hw_rcvrport,
256 &pios_rcvr_usart_cfg,
263 &pios_rcvr_dsm_aux_cfg,
268 uint8_t number_of_pwm_outputs;
269 uint8_t number_of_adc_ports;
271 HwSparkyOutPortGet(&hw_outport);
272 switch (hw_outport) {
273 case HWSPARKY_OUTPORT_PWM10:
274 number_of_pwm_outputs = 10;
275 number_of_adc_ports = 0;
278 case HWSPARKY_OUTPORT_PWM82ADC:
279 number_of_pwm_outputs = 8;
280 number_of_adc_ports = 2;
283 case HWSPARKY_OUTPORT_PWM73ADC:
284 number_of_pwm_outputs = 7;
285 number_of_adc_ports = 3;
288 case HWSPARKY_OUTPORT_PWM9PWM_IN:
289 number_of_pwm_outputs = 9;
291 number_of_adc_ports = 0;
293 case HWSPARKY_OUTPORT_PWM72ADCPWM_IN:
294 number_of_pwm_outputs = 7;
296 number_of_adc_ports = 2;
303 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
304 #ifdef PIOS_INCLUDE_SERVO
307 if (hw_rcvrport != HWSHARED_PORTTYPES_PPM) {
317 #if defined(PIOS_INCLUDE_ADC)
318 if (number_of_adc_ports > 0) {
319 internal_adc_cfg.adc_pin_count = number_of_adc_ports;
320 uintptr_t unused_adc;
327 #if defined(PIOS_INCLUDE_PWM)
329 if (number_of_adc_ports > 0)
331 uintptr_t pios_pwm_id;
334 uintptr_t pios_pwm_rcvr_id;
345 uint8_t hw_magnetometer;
346 HwSparkyMagnetometerGet(&hw_magnetometer);
348 #if defined(PIOS_INCLUDE_MPU)
349 if (hw_magnetometer != HWSPARKY_MAGNETOMETER_INTERNAL)
357 HwSparkyGyroRangeOptions hw_gyro_range;
358 HwSparkyGyroRangeGet(&hw_gyro_range);
359 switch(hw_gyro_range) {
360 case HWSPARKY_GYRORANGE_250:
363 case HWSPARKY_GYRORANGE_500:
366 case HWSPARKY_GYRORANGE_1000:
369 case HWSPARKY_GYRORANGE_2000:
374 HwSparkyAccelRangeOptions hw_accel_range;
375 HwSparkyAccelRangeGet(&hw_accel_range);
376 switch(hw_accel_range) {
377 case HWSPARKY_ACCELRANGE_2G:
380 case HWSPARKY_ACCELRANGE_4G:
383 case HWSPARKY_ACCELRANGE_8G:
386 case HWSPARKY_ACCELRANGE_16G:
392 HwSparkyMPU9150DLPFGet(&hw_mpu_dlpf);
394 uint16_t bandwidth = \
395 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_188) ? 188 : \
396 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_98) ? 98 : \
397 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_42) ? 42 : \
398 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_20) ? 20 : \
399 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_10) ? 10 : \
400 (hw_mpu_dlpf == HWSPARKY_MPU9150DLPF_5) ? 5 : \
408 switch (hw_magnetometer) {
409 case HWSPARKY_MAGNETOMETER_NONE:
410 case HWSPARKY_MAGNETOMETER_INTERNAL:
416 if (hw_flexiport == HWSHARED_PORTTYPES_I2C) {
417 uint8_t hw_orientation;
418 HwSparkyExtMagOrientationGet(&hw_orientation);
421 &pios_i2c_flexi_id, &pios_i2c_flexi_cfg);
431 #if defined(PIOS_INCLUDE_MS5611)
433 || (PIOS_MS5611_Test() != 0))
int32_t PIOS_MPU_I2C_Init(pios_mpu_dev_t *dev, pios_i2c_t i2c_id, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on I2C.
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)
int32_t PIOS_PWM_Init(uintptr_t *pwm_id, const struct pios_pwm_cfg *cfg)
const struct pios_rcvr_driver pios_pwm_rcvr_driver
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)
uintptr_t pios_rcvr_group_map[]
int32_t PIOS_I2C_CheckClear(pios_i2c_t i2c_id)
#define PIOS_DEBUG_Assert(test)
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
uintptr_t pios_uavo_settings_fs_id
uint16_t PIOS_IAP_ReadBootCount(void)
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.
const struct pios_board_info pios_board_info_blob
struct pios_mpu_dev * pios_mpu_dev_t
uintptr_t pios_com_aux_id
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.
void PIOS_DEBUG_Init(const struct pios_tim_channel *channels, uint8_t num_channels)
uintptr_t pios_com_telem_serial_id
const struct pios_com_driver pios_usart_com_driver
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
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)
int32_t PIOS_RCVR_Init(uintptr_t *rcvr_id, const struct pios_rcvr_driver *driver, const uintptr_t lower_id)
uintptr_t pios_internal_adc_id
static const struct pios_tim_clock_cfg tim_15_cfg
const struct pios_tim_channel * channels
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)
int32_t PIOS_CAN_Init(uintptr_t *id, const struct pios_can_cfg *cfg)
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)
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
const struct pios_com_driver pios_can_com_driver
uintptr_t pios_com_openlog_logging_id
uintptr_t pios_com_telem_usb_id
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)
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
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.
int32_t PIOS_ADC_Init(uintptr_t *adc_id, const struct pios_adc_driver *driver, uintptr_t lower_id)
#define PIOS_COM_CAN_TX_BUF_LEN
void PIOS_IAP_WriteBootCount(uint16_t)
static const struct pios_tim_clock_cfg tim_17_cfg
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
static const struct pios_tim_clock_cfg tim_16_cfg
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
int32_t PIOS_FLASHFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
uintptr_t pios_com_bridge_id
#define PIOS_COM_CAN_RX_BUF_LEN
static const struct pios_tim_clock_cfg tim_2_cfg
#define PIOS_Assert(test)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
int32_t PIOS_USB_BOARD_DATA_Init(void)
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm)
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.
void PIOS_SENSORS_SetMissing(enum pios_sensor_type type)
Assert that an optional (non-accel/gyro), but expected sensor is missing.
uintptr_t pios_com_can_id