42 #include "board_hw_defs.c"
47 #include <uavobjectsinit.h>
49 #include "manualcontrolsettings.h"
50 #include "modulesettings.h"
51 #include "flightbatterysettings.h"
53 #if defined(PIOS_INCLUDE_DEBUG_CONSOLE)
54 #define PIOS_COM_DEBUGCONSOLE_TX_BUF_LEN 40
76 #if defined(PIOS_INCLUDE_ANNUNC)
89 #if defined(PIOS_INCLUDE_FLASH)
97 uint32_t num_partitions;
98 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
110 ModuleSettingsInitialize();
112 #if defined(PIOS_INCLUDE_RTC)
120 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
137 if (boot_count < 3) {
142 HwDtfcSetDefaults(HwDtfcHandle(), 0);
143 ModuleSettingsSetDefaults(ModuleSettingsHandle(), 0);
144 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
147 #if defined(PIOS_INCLUDE_USB)
152 bool usb_hid_present =
false;
154 #if defined(PIOS_INCLUDE_USB_CDC)
155 bool usb_cdc_present =
false;
159 usb_hid_present =
true;
160 usb_cdc_present =
true;
165 usb_hid_present =
true;
168 uintptr_t pios_usb_id;
171 #if defined(PIOS_INCLUDE_USB_CDC)
173 HwDtfcUSB_VCPPortOptions hw_usb_vcpport;
175 HwDtfcUSB_VCPPortGet(&hw_usb_vcpport);
177 if (!usb_cdc_present) {
179 hw_usb_vcpport = HWDTFC_USB_VCPPORT_DISABLED;
185 #if defined(PIOS_INCLUDE_USB_HID)
187 HwDtfcUSB_HIDPortOptions hw_usb_hidport;
188 HwDtfcUSB_HIDPortGet(&hw_usb_hidport);
190 if (!usb_hid_present) {
192 hw_usb_hidport = HWDTFC_USB_HIDPORT_DISABLED;
201 HwSharedDSMxModeOptions hw_DSMxMode;
202 HwDtfcDSMxModeGet(&hw_DSMxMode);
205 HwSharedPortTypesOptions hw_rcvrport;
206 HwDtfcRcvrPortGet(&hw_rcvrport);
207 PIOS_HAL_ConfigurePort(hw_rcvrport,
208 &pios_uart3_usart_cfg,
220 HwSharedPortTypesOptions hw_uart1;
221 HwDtfcUart1Get(&hw_uart1);
222 PIOS_HAL_ConfigurePort(hw_uart1,
223 &pios_uart1_usart_cfg,
235 HwSharedPortTypesOptions hw_uart2;
236 HwDtfcUart2Get(&hw_uart2);
237 PIOS_HAL_ConfigurePort(hw_uart2,
238 &pios_uart2_usart_cfg,
249 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
250 #ifdef PIOS_INCLUDE_SERVO
257 #if defined(PIOS_INCLUDE_ADC)
258 uintptr_t unused_adc;
264 FlightBatterySettingsInitialize();
265 FlightBatterySettingsData batterysettings;
266 FlightBatterySettingsGet(&batterysettings);
268 if(batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_CURRENT] == (
float)36.6)
269 batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_CURRENT] = (float)DTFC_CURRENT_CALIBRATION_VALUE;
270 if(batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_VOLTAGE] == (
float)63.69)
271 batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_VOLTAGE] = (float)DTFC_VOLTAGE_CALIBRATION_VALUE;
272 FlightBatterySettingsSet(&batterysettings);
279 #if defined(PIOS_INCLUDE_MPU)
284 HwDtfcGyroRangeOptions hw_gyro_range;
285 HwDtfcGyroRangeGet(&hw_gyro_range);
286 switch(hw_gyro_range) {
287 case HWDTFC_GYRORANGE_250:
290 case HWDTFC_GYRORANGE_500:
293 case HWDTFC_GYRORANGE_1000:
296 case HWDTFC_GYRORANGE_2000:
301 HwDtfcAccelRangeOptions hw_accel_range;
302 HwDtfcAccelRangeGet(&hw_accel_range);
303 switch(hw_accel_range) {
304 case HWDTFC_ACCELRANGE_2G:
307 case HWDTFC_ACCELRANGE_4G:
310 case HWDTFC_ACCELRANGE_8G:
313 case HWDTFC_ACCELRANGE_16G:
319 HwDtfcICM20608G_GyroLPFOptions hw_mpu_gyro_dlpf;
320 HwDtfcICM20608G_GyroLPFGet(&hw_mpu_gyro_dlpf);
321 uint16_t gyro_bandwidth =
322 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_176) ? 176 :
323 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_92) ? 92 :
324 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_41) ? 41 :
325 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_20) ? 20 :
326 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_10) ? 10 :
327 (hw_mpu_gyro_dlpf == HWDTFC_ICM20608G_GYROLPF_5) ? 5 :
331 HwDtfcICM20608G_AccelLPFOptions hw_mpu_accel_dlpf;
332 HwDtfcICM20608G_AccelLPFGet(&hw_mpu_accel_dlpf);
333 uint16_t acc_bandwidth =
334 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_218) ? 218 :
335 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_99) ? 99 :
336 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_45) ? 45 :
337 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_21) ? 21 :
338 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_10) ? 10 :
339 (hw_mpu_accel_dlpf = HWDTFC_ICM20608G_ACCELLPF_5) ? 5 :
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)
uintptr_t pios_com_debug_id
#define PIOS_DEBUG_Assert(test)
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
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
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)
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)
uintptr_t pios_internal_adc_id
static const struct pios_tim_clock_cfg tim_15_cfg
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
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_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...
uintptr_t pios_com_openlog_logging_id
uintptr_t pios_com_telem_usb_id
void PIOS_MPU_SetAccelBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the accelerometer. The driver will automatically select the lowest ba...
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)
void PIOS_IAP_WriteBootCount(uint16_t)
static const struct pios_tim_clock_cfg tim_17_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.
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)
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.