LCOV - code coverage report
Current view: top level - AP_BoardConfig - AP_BoardConfig.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 40 64 62.5 %
Date: 2026-09-09 11:02:08 Functions: 7 9 77.8 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : /*
      16             :  *   AP_BoardConfig - board specific configuration
      17             :  */
      18             : 
      19             : #include "AP_BoardConfig.h"
      20             : 
      21             : #include <AP_Common/AP_Common.h>
      22             : #include <AP_HAL/AP_HAL.h>
      23             : #include <AP_Math/AP_Math.h>
      24             : #include <AP_RTC/AP_RTC.h>
      25             : #include <AP_Vehicle/AP_Vehicle_Type.h>
      26             : #include <GCS_MAVLink/GCS.h>
      27             : #include <AP_Filesystem/AP_Filesystem.h>
      28             : #include <GCS_MAVLink/GCS.h>
      29             : #include <GCS_MAVLink/GCS_MAVLink.h>
      30             : #include <AP_InertialSensor/AP_InertialSensor_rate_config.h>
      31             : 
      32             : #include <stdio.h>
      33             : 
      34             : #ifndef BOARD_TYPE_DEFAULT
      35             : #define BOARD_TYPE_DEFAULT PX4_BOARD_AUTO
      36             : #endif
      37             : 
      38             : #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
      39             : #ifndef BOARD_SER1_RTSCTS_DEFAULT
      40             : # define BOARD_SER1_RTSCTS_DEFAULT 0
      41             : #endif
      42             : #ifndef BOARD_SER2_RTSCTS_DEFAULT
      43             : # define BOARD_SER2_RTSCTS_DEFAULT 0
      44             : #endif
      45             : #ifndef BOARD_SER3_RTSCTS_DEFAULT
      46             : # define BOARD_SER3_RTSCTS_DEFAULT 0
      47             : #endif
      48             : #ifndef BOARD_SER4_RTSCTS_DEFAULT
      49             : # define BOARD_SER4_RTSCTS_DEFAULT 0
      50             : #endif
      51             : #ifndef BOARD_SER5_RTSCTS_DEFAULT
      52             : # define BOARD_SER5_RTSCTS_DEFAULT 0
      53             : #endif
      54             : #ifndef BOARD_SER6_RTSCTS_DEFAULT
      55             : # define BOARD_SER6_RTSCTS_DEFAULT 0
      56             : #endif
      57             : #ifndef BOARD_SER7_RTSCTS_DEFAULT
      58             : # define BOARD_SER7_RTSCTS_DEFAULT 0
      59             : #endif
      60             : #ifndef BOARD_SER8_RTSCTS_DEFAULT
      61             : # define BOARD_SER8_RTSCTS_DEFAULT 0
      62             : #endif
      63             : #endif
      64             : 
      65             : 
      66             : #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
      67             : #ifndef BOARD_SER1_RTSCTS_DEFAULT
      68             : # define BOARD_SER1_RTSCTS_DEFAULT 2
      69             : #endif
      70             : #ifndef BOARD_SER2_RTSCTS_DEFAULT
      71             : # define BOARD_SER2_RTSCTS_DEFAULT 2
      72             : #endif
      73             : #ifndef BOARD_SER3_RTSCTS_DEFAULT
      74             : # define BOARD_SER3_RTSCTS_DEFAULT 2
      75             : #endif
      76             : #ifndef BOARD_SER4_RTSCTS_DEFAULT
      77             : # define BOARD_SER4_RTSCTS_DEFAULT 2
      78             : #endif
      79             : #ifndef BOARD_SER5_RTSCTS_DEFAULT
      80             : # define BOARD_SER5_RTSCTS_DEFAULT 2
      81             : #endif
      82             : #ifndef BOARD_SER6_RTSCTS_DEFAULT
      83             : # define BOARD_SER6_RTSCTS_DEFAULT 2
      84             : #endif
      85             : #ifndef BOARD_SER7_RTSCTS_DEFAULT
      86             : # define BOARD_SER7_RTSCTS_DEFAULT 2
      87             : #endif
      88             : #ifndef BOARD_SER8_RTSCTS_DEFAULT
      89             : # define BOARD_SER8_RTSCTS_DEFAULT 2
      90             : #endif
      91             : #ifndef BOARD_TYPE_DEFAULT
      92             : # define BOARD_TYPE_DEFAULT PX4_BOARD_AUTO
      93             : #endif
      94             : #endif
      95             : 
      96             : #ifndef BOARD_SAFETY_ENABLE_DEFAULT
      97             : #if defined(HAL_GPIO_PIN_SAFETY_IN)
      98             :   // have safety startup enabled if we have a safety pin
      99             :   # define BOARD_SAFETY_ENABLE_DEFAULT 1
     100             : #elif defined(HAL_WITH_IO_MCU)
     101             :   // if we have an IOMCU then enable by default
     102             :   # define BOARD_SAFETY_ENABLE_DEFAULT HAL_WITH_IO_MCU
     103             : #else
     104             :   # define BOARD_SAFETY_ENABLE_DEFAULT 0
     105             : #endif
     106             : #endif
     107             : 
     108             : #ifndef HAL_IMU_TEMP_DEFAULT
     109             : #define HAL_IMU_TEMP_DEFAULT       -1 // disabled
     110             : #endif
     111             : 
     112             : #ifndef HAL_IMU_TEMP_MARGIN_LOW_DEFAULT
     113             : #define HAL_IMU_TEMP_MARGIN_LOW_DEFAULT 0 // disabled
     114             : #endif
     115             : 
     116             : #ifndef BOARD_SAFETY_OPTION_DEFAULT
     117             : #  define BOARD_SAFETY_OPTION_DEFAULT (BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF|BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON)
     118             : #endif
     119             : #ifndef BOARD_SAFETY_ENABLE
     120             : #  define BOARD_SAFETY_ENABLE 1
     121             : #endif
     122             : 
     123             : #ifndef BOARD_CONFIG_BOARD_VOLTAGE_MIN
     124             : #define BOARD_CONFIG_BOARD_VOLTAGE_MIN 4.3f
     125             : #endif
     126             : 
     127             : #ifndef HAL_BRD_OPTIONS_DEFAULT
     128             : #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS && !APM_BUILD_TYPE(APM_BUILD_UNKNOWN) && !APM_BUILD_TYPE(APM_BUILD_Replay)
     129             : #ifdef HAL_DEBUG_BUILD
     130             : #define HAL_BRD_OPTIONS_DEFAULT BOARD_OPTION_WATCHDOG | BOARD_OPTION_DEBUG_ENABLE
     131             : #else
     132             : #define HAL_BRD_OPTIONS_DEFAULT BOARD_OPTION_WATCHDOG
     133             : #endif
     134             : #else
     135             : #define HAL_BRD_OPTIONS_DEFAULT 0
     136             : #endif
     137             : #endif
     138             : 
     139             : #ifndef HAL_DEFAULT_BOOT_DELAY
     140             : #define HAL_DEFAULT_BOOT_DELAY 0
     141             : #endif
     142             : 
     143             : extern const AP_HAL::HAL& hal;
     144             : AP_BoardConfig *AP_BoardConfig::_singleton;
     145             : 
     146             : // constructor
     147        2098 : AP_BoardConfig::AP_BoardConfig()
     148             : #if HAL_HAVE_IMU_HEATER
     149             :     // initialise heater PI controller. Note we do this in the cpp file
     150             :     // for ccache efficiency
     151             :     : heater{{HAL_IMUHEAT_P_DEFAULT, HAL_IMUHEAT_I_DEFAULT, 70},}
     152             : #endif
     153             : {
     154        2098 :     _singleton = this;
     155        2098 :     AP_Param::setup_object_defaults(this, var_info);
     156        2098 : };
     157             : 
     158             : // table of user settable parameters
     159             : const AP_Param::GroupInfo AP_BoardConfig::var_info[] = {
     160             : 
     161             :     // index 0 was used by PWM_COUNT
     162             : 
     163             : #if AP_FEATURE_RTSCTS
     164             : #ifdef HAL_HAVE_RTSCTS_SERIAL1
     165             :     // @Param: SER1_RTSCTS
     166             :     // @DisplayName: Serial 1 flow control
     167             :     // @Description: Enable flow control on serial 1 (telemetry 1). You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup. Note that the PX4v1 does not have hardware flow control pins on this port, so you should leave this disabled.
     168             :     // @Values: 0:Disabled,1:Enabled,2:Auto,3:RS-485 Driver enable RTS pin
     169             :     // @RebootRequired: True
     170             :     // @User: Advanced
     171             :     AP_GROUPINFO("SER1_RTSCTS",    1, AP_BoardConfig, state.ser_rtscts[1], BOARD_SER1_RTSCTS_DEFAULT),
     172             : #endif
     173             : 
     174             : #ifdef HAL_HAVE_RTSCTS_SERIAL2
     175             :     // @Param: SER2_RTSCTS
     176             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     177             :     // @DisplayName: Serial 2 flow control
     178             :     // @Description: Enable flow control on serial 2 (telemetry 2). You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     179             :     AP_GROUPINFO("SER2_RTSCTS",    2, AP_BoardConfig, state.ser_rtscts[2], BOARD_SER2_RTSCTS_DEFAULT),
     180             : #endif
     181             : 
     182             : #ifdef HAL_HAVE_RTSCTS_SERIAL3
     183             :     // @Param: SER3_RTSCTS
     184             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     185             :     // @DisplayName: Serial 3 flow control
     186             :     // @Description: Enable flow control on serial 3. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     187             :     AP_GROUPINFO("SER3_RTSCTS",    26, AP_BoardConfig, state.ser_rtscts[3], BOARD_SER3_RTSCTS_DEFAULT),
     188             : #endif
     189             : 
     190             : #ifdef HAL_HAVE_RTSCTS_SERIAL4
     191             :     // @Param: SER4_RTSCTS
     192             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     193             :     // @DisplayName: Serial 4 flow control
     194             :     // @Description: Enable flow control on serial 4. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     195             :     AP_GROUPINFO("SER4_RTSCTS",    27, AP_BoardConfig, state.ser_rtscts[4], BOARD_SER4_RTSCTS_DEFAULT),
     196             : #endif
     197             : 
     198             : #ifdef HAL_HAVE_RTSCTS_SERIAL5
     199             :     // @Param: SER5_RTSCTS
     200             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     201             :     // @DisplayName: Serial 5 flow control
     202             :     // @Description: Enable flow control on serial 5. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     203             :     AP_GROUPINFO("SER5_RTSCTS",    25, AP_BoardConfig, state.ser_rtscts[5], BOARD_SER5_RTSCTS_DEFAULT),
     204             : #endif
     205             : 
     206             : #ifdef HAL_HAVE_RTSCTS_SERIAL6
     207             :     // @Param: SER6_RTSCTS
     208             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     209             :     // @DisplayName: Serial 6 flow control
     210             :     // @Description: Enable flow control on serial 6. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     211             :     AP_GROUPINFO("SER6_RTSCTS",    30, AP_BoardConfig, state.ser_rtscts[6], BOARD_SER6_RTSCTS_DEFAULT),
     212             : #endif
     213             : 
     214             : #ifdef HAL_HAVE_RTSCTS_SERIAL7
     215             :     // @Param: SER7_RTSCTS
     216             :     // @CopyFieldsFrom: BRD_SER1_RTSCTS
     217             :     // @DisplayName: Serial 7 flow control
     218             :     // @Description: Enable flow control on serial 7. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     219             :     AP_GROUPINFO("SER7_RTSCTS",    31, AP_BoardConfig, state.ser_rtscts[7], BOARD_SER7_RTSCTS_DEFAULT),
     220             : #endif
     221             : 
     222             : #ifdef HAL_HAVE_RTSCTS_SERIAL8
     223             :     // @Param: SER8_RTSCTS
     224             :     // @CopyFieldsFrom: BRD_SER8_RTSCTS
     225             :     // @DisplayName: Serial 8 flow control
     226             :     // @Description: Enable flow control on serial 8. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
     227             :     AP_GROUPINFO("SER8_RTSCTS",    32, AP_BoardConfig, state.ser_rtscts[8], BOARD_SER8_RTSCTS_DEFAULT),
     228             : #endif
     229             : #endif
     230             : 
     231             :     // @Param: SAFETY_DEFLT
     232             :     // @DisplayName: Sets default state of the safety switch
     233             :     // @Description: This controls the default state of the safety switch at startup. When set to 1 the safety switch will start in the safe state (flashing) at boot. When set to zero the safety switch will start in the unsafe state (solid) at startup. Note that if a safety switch is fitted the user can still control the safety state after startup using the switch. The safety state can also be controlled in software using a MAVLink message.
     234             :     // @Values: 0:Disabled,1:Enabled
     235             :     // @RebootRequired: True
     236             :     // @User: Standard
     237             :     AP_GROUPINFO("SAFETY_DEFLT",   3, AP_BoardConfig, state.safety_enable, BOARD_SAFETY_ENABLE_DEFAULT),
     238             : 
     239             : #if AP_FEATURE_SBUS_OUT
     240             :     // @Param: SBUS_OUT
     241             :     // @DisplayName:  SBUS output rate
     242             :     // @Description: This sets the SBUS output frame rate in Hz
     243             :     // @Values: 0:Disabled,1:50Hz,2:75Hz,3:100Hz,4:150Hz,5:200Hz,6:250Hz,7:300Hz
     244             :     // @RebootRequired: True
     245             :     // @User: Advanced
     246             :     AP_GROUPINFO("SBUS_OUT",   4, AP_BoardConfig, state.sbus_out_rate, 0),
     247             : #endif
     248             : 
     249             :     // @Param: SERIAL_NUM
     250             :     // @DisplayName: User-defined serial number
     251             :     // @Description: User-defined serial number of this vehicle, it can be any arbitrary number you want and has no effect on the autopilot
     252             :     // @Range: -8388608 8388607
     253             :     // @User: Standard
     254             :     AP_GROUPINFO("SERIAL_NUM", 5, AP_BoardConfig, vehicleSerialNumber, 0),
     255             : 
     256             :     // @Param: SAFETY_MASK
     257             :     // @DisplayName: Outputs which ignore the safety switch state
     258             :     // @Description: A bitmask which controls what outputs can move while the safety switch has not been pressed
     259             :     // @Bitmask: 0:Output1
     260             :     // @Bitmask: 1:Output2
     261             :     // @Bitmask: 2:Output3
     262             :     // @Bitmask: 3:Output4
     263             :     // @Bitmask: 4:Output5
     264             :     // @Bitmask: 5:Output6
     265             :     // @Bitmask: 6:Output7
     266             :     // @Bitmask: 7:Output8
     267             :     // @Bitmask: 8:Output9
     268             :     // @Bitmask: 9:Output10
     269             :     // @Bitmask: 10:Output11
     270             :     // @Bitmask: 11:Output12
     271             :     // @Bitmask: 12:Output13
     272             :     // @Bitmask: 13:Output14
     273             :     // @Bitmask: 14:Output15
     274             :     // @Bitmask: 15:Output16
     275             :     // @Bitmask: 16:Output17
     276             :     // @Bitmask: 17:Output18
     277             :     // @Bitmask: 18:Output19
     278             :     // @Bitmask: 19:Output20
     279             :     // @Bitmask: 20:Output21
     280             :     // @Bitmask: 21:Output22
     281             :     // @Bitmask: 22:Output23
     282             :     // @Bitmask: 23:Output24
     283             :     // @Bitmask: 24:Output25
     284             :     // @Bitmask: 25:Output26
     285             :     // @Bitmask: 26:Output27
     286             :     // @Bitmask: 27:Output28
     287             :     // @Bitmask: 28:Output29
     288             :     // @Bitmask: 29:Output30
     289             :     // @Bitmask: 30:Output31
     290             :     // @Bitmask: 31:Output32
     291             :     // @RebootRequired: True
     292             :     // @User: Advanced
     293             :     AP_GROUPINFO("SAFETY_MASK", 7, AP_BoardConfig, state.ignore_safety_channels, 0),
     294             : 
     295             : #if HAL_HAVE_IMU_HEATER
     296             :     // @Param: HEAT_TARG
     297             :     // @DisplayName: Board heater temperature target
     298             :     // @Description: Board heater target temperature for boards with controllable heating units. Set to -1 to disable the heater, please reboot after setting to -1.
     299             :     // @Range: -1 80
     300             :     // @Units: degC
     301             :     // @User: Advanced
     302             :     AP_GROUPINFO("HEAT_TARG", 8, AP_BoardConfig, heater.imu_target_temperature, HAL_IMU_TEMP_DEFAULT),
     303             : #endif
     304             : 
     305             : #if AP_FEATURE_BOARD_DETECT
     306             :     // @Param: TYPE
     307             :     // @DisplayName: Board type
     308             :     // @Description: This allows selection of a PX4 or VRBRAIN board type. If set to zero then the board type is auto-detected (PX4)
     309             :     // @Values: 0:AUTO,1:PX4V1,2:Pixhawk,3:Cube/Pixhawk2,5:PixhawkMini,6:Pixhawk2Slim,13:Intel Aero FC,14:Pixhawk Pro,20:AUAV2.1,39:PX4 FMUV6,100:PX4 OLDDRIVERS
     310             :     // @RebootRequired: True
     311             :     // @User: Advanced
     312             :     AP_GROUPINFO("TYPE", 9, AP_BoardConfig, state.board_type, BOARD_TYPE_DEFAULT),
     313             : #endif
     314             : 
     315             : #if HAL_WITH_IO_MCU
     316             :     // @Param: IO_ENABLE
     317             :     // @DisplayName: Enable IO co-processor
     318             :     // @Description: This allows for the IO co-processor on boards with an IOMCU to be disabled. Setting to 2 will enable the IOMCU but not attempt to update firmware on startup
     319             :     // @Values: 0:Disabled,1:Enabled,2:EnableNoFWUpdate
     320             :     // @RebootRequired: True
     321             :     // @User: Advanced
     322             :     AP_GROUPINFO("IO_ENABLE", 10, AP_BoardConfig, state.io_enable, 1),
     323             : #endif
     324             : 
     325             : #if AP_RADIO_ENABLED
     326             :     // @Group: RADIO
     327             :     // @Path: ../AP_Radio/AP_Radio.cpp
     328             :     AP_SUBGROUPINFO(_radio, "RADIO", 11, AP_BoardConfig, AP_Radio),
     329             : #endif
     330             : 
     331             :     // @Param: SAFETYOPTION
     332             :     // @DisplayName: Options for safety button behavior
     333             :     // @Description: This controls the activation of the safety button. It allows you to control if the safety button can be used for safety enable and/or disable, and whether the button is only active when disarmed
     334             :     // @Bitmask: 0:ActiveForSafetyDisable,1:ActiveForSafetyEnable,2:ActiveWhenArmed,3:Force safety on when the aircraft disarms
     335             :     // @User: Standard
     336             :     AP_GROUPINFO("SAFETYOPTION",   13, AP_BoardConfig, state.safety_option, BOARD_SAFETY_OPTION_DEFAULT),
     337             : 
     338             : #if AP_RTC_ENABLED
     339             :     // @Group: RTC
     340             :     // @Path: ../AP_RTC/AP_RTC.cpp
     341             :     AP_SUBGROUPINFO(rtc, "RTC", 14, AP_BoardConfig, AP_RTC),
     342             : #endif
     343             : 
     344             : #if HAL_HAVE_BOARD_VOLTAGE
     345             :     // @Param: VBUS_MIN
     346             :     // @DisplayName: Autopilot board voltage requirement
     347             :     // @Description: Minimum voltage on the autopilot power rail to allow the aircraft to arm. 0 to disable the check.
     348             :     // @Units: V
     349             :     // @Range: 4.0 5.5
     350             :     // @Increment: 0.1
     351             :     // @User: Advanced
     352             :     AP_GROUPINFO("VBUS_MIN",    15,     AP_BoardConfig,  _vbus_min,  BOARD_CONFIG_BOARD_VOLTAGE_MIN),
     353             : 
     354             : #endif
     355             : 
     356             : #if HAL_HAVE_SERVO_VOLTAGE
     357             :     // @Param: VSERVO_MIN
     358             :     // @DisplayName: Servo voltage requirement
     359             :     // @Description: Minimum voltage on the servo rail to allow the aircraft to arm. 0 to disable the check.
     360             :     // @Units: V
     361             :     // @Range: 3.3 12.0
     362             :     // @Increment: 0.1
     363             :     // @User: Advanced
     364             :     AP_GROUPINFO("VSERVO_MIN",    16,     AP_BoardConfig, _vservo_min,  0),
     365             : #endif
     366             : 
     367             : #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
     368             :     // @Param: SD_SLOWDOWN
     369             :     // @DisplayName: microSD slowdown
     370             :     // @Description: This is a scaling factor to slow down microSD operation. It can be used on flight board and microSD card combinations where full speed is not reliable. For normal full speed operation a value of 0 should be used.
     371             :     // @Range: 0 32
     372             :     // @Increment: 1
     373             :     // @User: Advanced
     374             :     AP_GROUPINFO("SD_SLOWDOWN",  17,     AP_BoardConfig, _sdcard_slowdown,  0),
     375             : #endif
     376             : 
     377             : #ifdef HAL_GPIO_PWM_VOLT_PIN
     378             :     // @Param: PWM_VOLT_SEL
     379             :     // @DisplayName: Set PWM Out Voltage
     380             :     // @Description: This sets the voltage max for PWM output pulses. 0 for 3.3V and 1 for 5V output. On boards with an IOMCU that support this parameter this option only affects the 8 main outputs, not the 6 auxiliary outputs. Using 5V output can help to reduce the impact of ESC noise interference corrupting signals to the ESCs.
     381             :     // @Values: 0:3.3V,1:5V
     382             :     // @User: Advanced
     383             :     AP_GROUPINFO("PWM_VOLT_SEL", 18, AP_BoardConfig, _pwm_volt_sel, 0),
     384             : #endif
     385             : 
     386             :     // @Param: OPTIONS
     387             :     // @DisplayName: Board options
     388             :     // @Description: Board specific option flags
     389             :     // @Bitmask: 0:Enable hardware watchdog, 1:Disable MAVftp, 2:Enable set of internal parameters, 3:Enable Debug Pins, 4:Unlock flash on reboot, 5:Write protect firmware flash on reboot, 6:Write protect bootloader flash on reboot, 7:Skip board validation, 8:Disable board arming gpio output change on arm/disarm, 9:Use safety pins as profiled
     390             :     // @User: Advanced
     391             :     AP_GROUPINFO("OPTIONS", 19, AP_BoardConfig, _options, HAL_BRD_OPTIONS_DEFAULT),
     392             : 
     393             :     // @Param: BOOT_DELAY
     394             :     // @DisplayName: Boot delay
     395             :     // @Description: This adds a delay in milliseconds to boot to ensure peripherals initialise fully
     396             :     // @Range: 0 10000
     397             :     // @Units: ms
     398             :     // @User: Advanced
     399             :     AP_GROUPINFO("BOOT_DELAY", 20, AP_BoardConfig, _boot_delay_ms, HAL_DEFAULT_BOOT_DELAY),
     400             : 
     401             : #if HAL_HAVE_IMU_HEATER
     402             :     // @Param: HEAT_P
     403             :     // @DisplayName: Board Heater P gain
     404             :     // @Description: Board Heater P gain
     405             :     // @Range: 1 500
     406             :     // @Increment: 1
     407             :     // @User: Advanced
     408             : 
     409             :     // @Param: HEAT_I
     410             :     // @DisplayName: Board Heater I gain
     411             :     // @Description: Board Heater integrator gain
     412             :     // @Range: 0 1
     413             :     // @Increment: 0.1
     414             :     // @User: Advanced
     415             : 
     416             :     // @Param: HEAT_IMAX
     417             :     // @DisplayName: Board Heater IMAX
     418             :     // @Description: Board Heater integrator maximum
     419             :     // @Range: 0 100
     420             :     // @Increment: 1
     421             :     // @User: Advanced
     422             :     AP_SUBGROUPINFO(heater.pi_controller, "HEAT_",  21, AP_BoardConfig, AC_PI),
     423             : #endif
     424             : 
     425             : #ifdef HAL_PIN_ALT_CONFIG
     426             :     // @Param: ALT_CONFIG
     427             :     // @DisplayName: Alternative HW config
     428             :     // @Description: Select an alternative hardware configuration. A value of zero selects the default configuration for this board. Other values are board specific. Please see the documentation for your board for details on any alternative configuration values that may be available.
     429             :     // @Range: 0 10
     430             :     // @Increment: 1
     431             :     // @User: Advanced
     432             :     // @RebootRequired: True
     433             :     AP_GROUPINFO("ALT_CONFIG", 22, AP_BoardConfig, _alt_config, 0),
     434             : #endif // HAL_PIN_ALT_CONFIG
     435             : 
     436             : #if HAL_HAVE_IMU_HEATER
     437             :     // @Param: HEAT_LOWMGN
     438             :     // @DisplayName: Board heater temp lower margin
     439             :     // @Description: Arming check will fail if temp is lower than this margin below BRD_HEAT_TARG. 0 disables the low temperature check
     440             :     // @Range: 0 20
     441             :     // @Units: degC
     442             :     // @User: Advanced
     443             :     AP_GROUPINFO("HEAT_LOWMGN", 23, AP_BoardConfig, heater.imu_arming_temperature_margin_low, HAL_IMU_TEMP_MARGIN_LOW_DEFAULT),
     444             : #endif
     445             : 
     446             : #if AP_SDCARD_STORAGE_ENABLED
     447             :     // @Param: SD_MISSION
     448             :     // @DisplayName:  SDCard Mission size
     449             :     // @Description: This sets the amount of storage in kilobytes reserved on the microsd card in mission.stg for waypoint storage. Each waypoint uses 15 bytes.
     450             :     // @Range: 0 64
     451             :     // @RebootRequired: True
     452             :     // @User: Advanced
     453             :     AP_GROUPINFO("SD_MISSION", 24, AP_BoardConfig, sdcard_storage.mission_kb, 0),
     454             : 
     455             :     // @Param: SD_FENCE
     456             :     // @DisplayName:  SDCard Fence size
     457             :     // @Description: This sets the amount of storage in kilobytes reserved on the microsd card in fence.stg for fence storage.
     458             :     // @Range: 0 64
     459             :     // @RebootRequired: True
     460             :     // @User: Advanced
     461             :     AP_GROUPINFO("SD_FENCE", 29, AP_BoardConfig, sdcard_storage.fence_kb, 0),
     462             : #endif
     463             : 
     464             :     // index 25 used by SER5_RTSCTS
     465             :     // index 26 used by SER3_RTSCTS
     466             :     // index 27 used by SER4_RTSCTS
     467             : 
     468             :     
     469             : #if HAL_WITH_IO_MCU_DSHOT
     470             :     // @Param: IO_DSHOT
     471             :     // @DisplayName: Load DShot FW on IO
     472             :     // @Description: This loads the DShot firmware on the IO co-processor
     473             :     // @Values: 0:StandardFW,1:DshotFW
     474             :     // @RebootRequired: True
     475             :     // @User: Advanced
     476             :     AP_GROUPINFO("IO_DSHOT", 28, AP_BoardConfig, state.io_dshot, 0),
     477             : #endif
     478             : 
     479             :     // index 30 used by SER6_RTSCTS
     480             :     // index 31 used by SER7_RTSCTS
     481             :     // index 32 used by SER8_RTSCTS
     482             : 
     483             : #if AP_CPU_IDLE_STATS_ENABLED
     484             :     // @Param: IDLE_STATS
     485             :     // @DisplayName: Capture and calculate true CPU load using idle threads
     486             :     // @Description: Capture and calculate true CPU load using idle threads
     487             :     // @Values: 0:Disable,1:Enable
     488             :     // @RebootRequired: True
     489             :     // @User: Advanced
     490             :     AP_GROUPINFO("IDLE_STATS", 33, AP_BoardConfig, state.idle_stats, 0),
     491             : #endif
     492             : 
     493             :     AP_GROUPEND
     494             : };
     495             : 
     496        2094 : void AP_BoardConfig::init()
     497             : {
     498        2094 :     board_setup();
     499             : 
     500             : #if AP_RTC_ENABLED
     501        2094 :     AP::rtc().set_utc_usec(hal.util->get_hw_rtc(), AP_RTC::SOURCE_HW);
     502             : #endif
     503             : 
     504        2094 :     if (_boot_delay_ms > 0) {
     505           0 :         uint16_t delay_ms = uint16_t(_boot_delay_ms.get());
     506           0 :         if (hal.util->was_watchdog_armed() && delay_ms > 200) {
     507             :             // don't delay a long time on watchdog reset, the pilot
     508             :             // may be able to save the vehicle
     509           0 :             delay_ms = 200;
     510             :         }
     511           0 :         hal.scheduler->delay(delay_ms);
     512             :     }
     513             :     
     514             : #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS && defined(USE_POSIX)
     515             :     uint8_t slowdown = constrain_int16(_sdcard_slowdown.get(), 0, 32);
     516             :     const uint8_t max_slowdown = 8;
     517             :     do {
     518             :         if (AP::FS().retry_mount()) {
     519             :             break;
     520             :         }
     521             :         slowdown++;
     522             :         hal.scheduler->delay(5);
     523             :     } while (slowdown < max_slowdown);
     524             :     if (slowdown < max_slowdown) {
     525             :         _sdcard_slowdown.set(slowdown);
     526             :     } else {
     527             :         printf("SDCard failed to start\n");
     528             :     }
     529             : #endif
     530        2094 : }
     531             : 
     532             : // set default value for BRD_SAFETY_MASK
     533         918 : void AP_BoardConfig::set_default_safety_ignore_mask(uint32_t mask)
     534             : {
     535         918 :     state.ignore_safety_channels.set_default(mask);
     536         918 : }
     537             : 
     538        2086 : void AP_BoardConfig::init_safety()
     539             : {
     540        2086 :     board_init_safety();
     541        2086 :     board_init_debug();
     542        2086 : }
     543             : 
     544             : /*
     545             :   notify user of a fatal startup error related to available sensors. 
     546             : */
     547             : bool AP_BoardConfig::_in_error_loop;
     548             : 
     549           8 : void AP_BoardConfig::throw_error(const char *err_type, const char *fmt, va_list arg)
     550             : {
     551           8 :     _in_error_loop = true;
     552             :     /*
     553             :       to give the user the opportunity to connect to USB we keep
     554             :       repeating the error.  The mavlink delay callback is initialised
     555             :       before this, so the user can change parameters (and in
     556             :       particular BRD_TYPE if needed)
     557             :     */
     558           8 :     uint32_t last_print_ms = 0;
     559             :     while (true) {
     560       25986 :         uint32_t now = AP_HAL::millis();
     561       25986 :         if (now - last_print_ms >= 5000) {
     562          24 :             last_print_ms = now;
     563             :             char printfmt[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN+2];
     564          24 :             hal.util->snprintf(printfmt, sizeof(printfmt), "%s: %s\n", err_type, fmt);
     565             :             {
     566             :                 va_list arg_copy;
     567          24 :                 va_copy(arg_copy, arg);
     568          24 :                 vprintf(printfmt, arg_copy);
     569          24 :                 va_end(arg_copy);
     570             :             }
     571             : #if HAL_GCS_ENABLED
     572          24 :             hal.util->snprintf(printfmt, sizeof(printfmt), "%s: %s", err_type, fmt);
     573             :             {
     574             :                 va_list arg_copy;
     575          24 :                 va_copy(arg_copy, arg);
     576          24 :                 gcs().send_textv(MAV_SEVERITY_CRITICAL, printfmt, arg_copy);
     577          24 :                 va_end(arg_copy);
     578             :             }
     579             : #endif
     580             :         }
     581             : #if HAL_GCS_ENABLED
     582       25986 :         gcs().update_receive();
     583       25978 :         gcs().update_send();
     584             : #endif
     585       25978 :         EXPECT_DELAY_MS(10);
     586       25978 :         hal.scheduler->delay(5);
     587       25978 :     }
     588             : }
     589             : 
     590           0 : void AP_BoardConfig::allocation_error(const char *fmt, ...)
     591             : {
     592             :     va_list arg_list;
     593           0 :     va_start(arg_list, fmt);
     594           0 :     char newfmt[64] {};
     595           0 :     snprintf(newfmt, sizeof(newfmt), "Unable to allocate %s", fmt);
     596           0 :     throw_error("Allocation Error", newfmt, arg_list);
     597             :     va_end(arg_list);
     598             : }
     599             : 
     600           8 : void AP_BoardConfig::config_error(const char *fmt, ...)
     601             : {
     602             :     va_list arg_list;
     603           8 :     va_start(arg_list, fmt);
     604           8 :     throw_error("Config Error", fmt, arg_list);
     605             :     va_end(arg_list);
     606             : }
     607             : 
     608             : /*
     609             :   handle logic for safety state button press. This should be called at
     610             :   10Hz when the button is pressed. The button can either be directly
     611             :   on a pin or on a UAVCAN device
     612             :   This function returns true if the safety state should be toggled
     613             :  */
     614           0 : bool AP_BoardConfig::safety_button_handle_pressed(uint8_t press_count)
     615             : {
     616           0 :     if (press_count != 10) {
     617           0 :         return false;
     618             :     }
     619             :     // get button options
     620           0 :     uint16_t safety_options = get_safety_button_options();
     621           0 :     if (!(safety_options & BOARD_SAFETY_OPTION_BUTTON_ACTIVE_ARMED) &&
     622           0 :         hal.util->get_soft_armed()) {
     623           0 :         return false;
     624             :     }
     625           0 :     AP_HAL::Util::safety_state safety_state = hal.util->safety_switch_state();
     626           0 :     if (safety_state == AP_HAL::Util::SAFETY_DISARMED &&
     627           0 :         !(safety_options & BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF)) {
     628           0 :         return false;
     629             :     }
     630           0 :     if (safety_state == AP_HAL::Util::SAFETY_ARMED &&
     631           0 :         !(safety_options & BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON)) {
     632           0 :         return false;
     633             :     }
     634           0 :     return true;
     635             : }
     636             : 
     637             : namespace AP {
     638        4108 :     AP_BoardConfig *boardConfig(void) {
     639        4108 :         return AP_BoardConfig::get_singleton();
     640             :     }
     641             : };

Generated by: LCOV version 1.14