AP_BoardConfig.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #pragma once
  2. #include <AP_HAL/AP_HAL.h>
  3. #include <AP_Common/AP_Common.h>
  4. #include <AP_Param/AP_Param.h>
  5. #include <AP_RTC/AP_RTC.h>
  6. #ifndef AP_FEATURE_BOARD_DETECT
  7. #if defined(HAL_CHIBIOS_ARCH_FMUV3) || defined(HAL_CHIBIOS_ARCH_FMUV4) || defined(HAL_CHIBIOS_ARCH_FMUV5) || defined(HAL_CHIBIOS_ARCH_MINDPXV2) || defined(HAL_CHIBIOS_ARCH_FMUV4PRO) || defined(HAL_CHIBIOS_ARCH_BRAINV51) || defined(HAL_CHIBIOS_ARCH_BRAINV52) || defined(HAL_CHIBIOS_ARCH_UBRAINV51) || defined(HAL_CHIBIOS_ARCH_COREV10) || defined(HAL_CHIBIOS_ARCH_BRAINV54)
  8. #define AP_FEATURE_BOARD_DETECT 1
  9. #else
  10. #define AP_FEATURE_BOARD_DETECT 0
  11. #endif
  12. #endif
  13. #ifndef AP_FEATURE_RTSCTS
  14. #define AP_FEATURE_RTSCTS 0
  15. #endif
  16. #ifndef AP_FEATURE_RTSCTS
  17. #define AP_FEATURE_RTSCTS 0
  18. #endif
  19. #ifndef AP_FEATURE_SBUS_OUT
  20. #define AP_FEATURE_SBUS_OUT 0
  21. #endif
  22. #if HAL_RCINPUT_WITH_AP_RADIO
  23. #include <AP_Radio/AP_Radio.h>
  24. #endif
  25. extern "C" typedef int (*main_fn_t)(int argc, char **);
  26. class AP_BoardConfig {
  27. public:
  28. AP_BoardConfig() {
  29. _singleton = this;
  30. AP_Param::setup_object_defaults(this, var_info);
  31. };
  32. /* Do not allow copies */
  33. AP_BoardConfig(const AP_BoardConfig &other) = delete;
  34. AP_BoardConfig &operator=(const AP_BoardConfig&) = delete;
  35. // singleton support
  36. static AP_BoardConfig *get_singleton(void) {
  37. return _singleton;
  38. }
  39. void init(void);
  40. void init_safety(void);
  41. static const struct AP_Param::GroupInfo var_info[];
  42. // notify user of a fatal startup error related to available sensors.
  43. static void sensor_config_error(const char *reason);
  44. // permit other libraries (in particular, GCS_MAVLink) to detect
  45. // that we're never going to boot properly:
  46. static bool in_sensor_config_error(void) { return _in_sensor_config_error; }
  47. // valid types for BRD_TYPE: these values need to be in sync with the
  48. // values from the param description
  49. enum px4_board_type {
  50. BOARD_TYPE_UNKNOWN = -1,
  51. PX4_BOARD_AUTO = 0,
  52. PX4_BOARD_PX4V1 = 1,
  53. PX4_BOARD_PIXHAWK = 2,
  54. PX4_BOARD_PIXHAWK2 = 3,
  55. PX4_BOARD_PIXRACER = 4,
  56. PX4_BOARD_PHMINI = 5,
  57. PX4_BOARD_PH2SLIM = 6,
  58. PX4_BOARD_AEROFC = 13,
  59. PX4_BOARD_PIXHAWK_PRO = 14,
  60. PX4_BOARD_AUAV21 = 20,
  61. PX4_BOARD_PCNC1 = 21,
  62. PX4_BOARD_MINDPXV2 = 22,
  63. PX4_BOARD_SP01 = 23,
  64. PX4_BOARD_FMUV5 = 24,
  65. VRX_BOARD_BRAIN51 = 30,
  66. VRX_BOARD_BRAIN52 = 32,
  67. VRX_BOARD_BRAIN52E = 33,
  68. VRX_BOARD_UBRAIN51 = 34,
  69. VRX_BOARD_UBRAIN52 = 35,
  70. VRX_BOARD_CORE10 = 36,
  71. VRX_BOARD_BRAIN54 = 38,
  72. PX4_BOARD_OLDDRIVERS = 100,
  73. PX4_BOARD_FMUV6 = 39,
  74. };
  75. // set default value for BRD_SAFETY_MASK
  76. void set_default_safety_ignore_mask(uint16_t mask);
  77. static enum px4_board_type get_board_type(void) {
  78. #if AP_FEATURE_BOARD_DETECT
  79. return px4_configured_board;
  80. #else
  81. return BOARD_TYPE_UNKNOWN;
  82. #endif
  83. }
  84. // ask if IOMCU is enabled. This is a uint8_t to allow
  85. // developer debugging by setting BRD_IO_ENABLE=100 to avoid the
  86. // crc check of IO firmware on startup
  87. static uint8_t io_enabled(void) {
  88. #if AP_FEATURE_BOARD_DETECT
  89. return _singleton?uint8_t(_singleton->state.io_enable.get()):0;
  90. #else
  91. return 0;
  92. #endif
  93. }
  94. // get number of PWM outputs enabled on FMU
  95. static uint8_t get_pwm_count(void) {
  96. return _singleton?_singleton->pwm_count.get():8;
  97. }
  98. enum board_safety_button_option {
  99. BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF= (1 << 0),
  100. BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON= (1 << 1),
  101. BOARD_SAFETY_OPTION_BUTTON_ACTIVE_ARMED= (1 << 2),
  102. BOARD_SAFETY_OPTION_SAFETY_ON_DISARM= (1 << 3),
  103. };
  104. // return safety button options. Bits are in enum board_safety_button_option
  105. uint16_t get_safety_button_options(void) {
  106. return uint16_t(state.safety_option.get());
  107. }
  108. // return the value of BRD_SAFETY_MASK
  109. uint16_t get_safety_mask(void) const {
  110. #if AP_FEATURE_BOARD_DETECT || defined(AP_FEATURE_BRD_PWM_COUNT_PARAM)
  111. return uint16_t(state.ignore_safety_channels.get());
  112. #else
  113. return 0;
  114. #endif
  115. }
  116. #if HAL_HAVE_BOARD_VOLTAGE
  117. // get minimum board voltage
  118. static float get_minimum_board_voltage(void) {
  119. return _singleton?_singleton->_vbus_min.get():0;
  120. }
  121. #endif
  122. #if HAL_HAVE_SERVO_VOLTAGE
  123. // get minimum servo voltage
  124. static float get_minimum_servo_voltage(void) {
  125. return _singleton?_singleton->_vservo_min.get():0;
  126. }
  127. #endif
  128. #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  129. static uint8_t get_sdcard_slowdown(void) {
  130. return _singleton?_singleton->_sdcard_slowdown.get():0;
  131. }
  132. #endif
  133. enum board_options {
  134. BOARD_OPTION_WATCHDOG = (1 << 0),
  135. };
  136. // return true if watchdog enabled
  137. static bool watchdog_enabled(void) {
  138. return _singleton?(_singleton->_options & BOARD_OPTION_WATCHDOG)!=0:false;
  139. }
  140. // handle press of safety button. Return true if safety state
  141. // should be toggled
  142. bool safety_button_handle_pressed(uint8_t press_count);
  143. private:
  144. static AP_BoardConfig *_singleton;
  145. AP_Int16 vehicleSerialNumber;
  146. AP_Int8 pwm_count;
  147. struct {
  148. AP_Int8 safety_enable;
  149. AP_Int16 safety_option;
  150. AP_Int32 ignore_safety_channels;
  151. #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  152. AP_Int8 ser1_rtscts;
  153. AP_Int8 ser2_rtscts;
  154. AP_Int8 sbus_out_rate;
  155. #endif
  156. AP_Int8 board_type;
  157. AP_Int8 io_enable;
  158. } state;
  159. #if AP_FEATURE_BOARD_DETECT
  160. static enum px4_board_type px4_configured_board;
  161. void board_setup_drivers(void);
  162. bool spi_check_register(const char *devname, uint8_t regnum, uint8_t value, uint8_t read_flag = 0x80);
  163. void validate_board_type(void);
  164. void check_cubeblack(void);
  165. void board_autodetect(void);
  166. #endif // AP_FEATURE_BOARD_DETECT
  167. void board_init_safety(void);
  168. void board_setup_uart(void);
  169. void board_setup_sbus(void);
  170. void board_setup(void);
  171. static bool _in_sensor_config_error;
  172. // target temperarure for IMU in Celsius, or -1 to disable
  173. AP_Int8 _imu_target_temperature;
  174. #if HAL_RCINPUT_WITH_AP_RADIO
  175. // direct attached radio
  176. AP_Radio _radio;
  177. #endif
  178. // real-time-clock; private because access is via the singleton
  179. AP_RTC rtc;
  180. #if HAL_HAVE_BOARD_VOLTAGE
  181. AP_Float _vbus_min;
  182. #endif
  183. #if HAL_HAVE_SERVO_VOLTAGE
  184. AP_Float _vservo_min;
  185. #endif
  186. #ifdef HAL_GPIO_PWM_VOLT_PIN
  187. AP_Int8 _pwm_volt_sel;
  188. #endif
  189. #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  190. AP_Int8 _sdcard_slowdown;
  191. #endif
  192. AP_Int16 _boot_delay_ms;
  193. AP_Int32 _options;
  194. };