2016-07-29 16:31:02 -03:00
|
|
|
#include "HAL_Linux_Class.h"
|
|
|
|
|
2015-10-19 11:38:47 -03:00
|
|
|
#include <assert.h>
|
2016-10-26 18:27:12 -03:00
|
|
|
#include <signal.h>
|
2021-09-17 00:28:40 -03:00
|
|
|
#include <sched.h>
|
2013-09-22 03:01:24 -03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <unistd.h>
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2017-05-18 21:42:48 -03:00
|
|
|
#include <AP_HAL/utility/RCOutput_Tap.h>
|
2016-05-17 23:26:57 -03:00
|
|
|
#include <AP_HAL/utility/getopt_cpp.h>
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty.h>
|
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty_Private.h>
|
2016-07-13 20:25:46 -03:00
|
|
|
#include <AP_Module/AP_Module.h>
|
2014-08-19 00:48:56 -03:00
|
|
|
|
2016-07-29 16:31:02 -03:00
|
|
|
#include "AnalogIn_ADS1115.h"
|
|
|
|
#include "AnalogIn_IIO.h"
|
|
|
|
#include "AnalogIn_Navio2.h"
|
|
|
|
#include "GPIO.h"
|
|
|
|
#include "I2CDevice.h"
|
|
|
|
#include "OpticalFlow_Onboard.h"
|
|
|
|
#include "RCInput.h"
|
|
|
|
#include "RCInput_AioPRU.h"
|
|
|
|
#include "RCInput_Navio2.h"
|
|
|
|
#include "RCInput_PRU.h"
|
|
|
|
#include "RCInput_RPI.h"
|
2017-05-26 19:00:03 -03:00
|
|
|
#include "RCInput_SoloLink.h"
|
2016-07-29 16:31:02 -03:00
|
|
|
#include "RCInput_UART.h"
|
|
|
|
#include "RCInput_UDP.h"
|
2016-09-16 05:43:27 -03:00
|
|
|
#include "RCInput_Multi.h"
|
2017-08-17 19:41:58 -03:00
|
|
|
#include "RCInput_ZYNQ.h"
|
2019-05-01 06:13:58 -03:00
|
|
|
#include "RCInput_RCProtocol.h"
|
2016-07-29 16:31:02 -03:00
|
|
|
#include "RCOutput_AioPRU.h"
|
|
|
|
#include "RCOutput_Bebop.h"
|
|
|
|
#include "RCOutput_Disco.h"
|
|
|
|
#include "RCOutput_PCA9685.h"
|
|
|
|
#include "RCOutput_PRU.h"
|
|
|
|
#include "RCOutput_Sysfs.h"
|
|
|
|
#include "RCOutput_ZYNQ.h"
|
2016-07-22 11:18:25 -03:00
|
|
|
#include "SPIDevice.h"
|
2016-07-29 16:31:02 -03:00
|
|
|
#include "SPIUARTDriver.h"
|
|
|
|
#include "Scheduler.h"
|
|
|
|
#include "Storage.h"
|
|
|
|
#include "UARTDriver.h"
|
|
|
|
#include "Util.h"
|
|
|
|
#include "Util_RPI.h"
|
2020-05-31 09:28:24 -03:00
|
|
|
#include "CANSocketIface.h"
|
2016-05-17 23:26:57 -03:00
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
using namespace Linux;
|
|
|
|
|
2015-11-28 05:38:56 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
2016-01-20 09:14:48 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
2016-06-29 06:10:21 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \
|
2015-11-28 05:38:56 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:30 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2016-10-17 15:02:48 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \
|
2020-01-10 15:25:03 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2021-09-07 02:17:32 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR || \
|
2023-10-22 14:50:57 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
2015-11-10 13:58:59 -04:00
|
|
|
static UtilRPI utilInstance;
|
|
|
|
#else
|
|
|
|
static Util utilInstance;
|
|
|
|
#endif
|
|
|
|
|
2023-12-10 23:32:18 -04:00
|
|
|
// 10 serial ports on Linux
|
|
|
|
static UARTDriver serial0Driver(true);
|
|
|
|
static UARTDriver serial1Driver(false);
|
|
|
|
static UARTDriver serial2Driver(false);
|
|
|
|
// serial3Driver declared below depending on board type
|
|
|
|
static UARTDriver serial4Driver(false);
|
|
|
|
static UARTDriver serial5Driver(false);
|
|
|
|
static UARTDriver serial6Driver(false);
|
|
|
|
static UARTDriver serial7Driver(false);
|
|
|
|
static UARTDriver serial8Driver(false);
|
|
|
|
static UARTDriver serial9Driver(false);
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2015-11-22 20:07:42 -04:00
|
|
|
static I2CDeviceManager i2c_mgr_instance;
|
2016-07-22 11:22:14 -03:00
|
|
|
static SPIDeviceManager spi_mgr_instance;
|
2015-11-22 20:07:42 -04:00
|
|
|
|
2017-09-07 12:36:13 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
|
2023-12-10 23:32:18 -04:00
|
|
|
static SPIUARTDriver serial3Driver;
|
2017-09-07 12:36:13 -03:00
|
|
|
#else
|
2023-12-10 23:32:18 -04:00
|
|
|
static UARTDriver serial3Driver(false);
|
2017-09-07 12:36:13 -03:00
|
|
|
#endif
|
|
|
|
|
2023-12-12 13:43:50 -04:00
|
|
|
static UARTDriver* serialDrivers[] = {
|
|
|
|
&serial0Driver,
|
|
|
|
&serial1Driver,
|
|
|
|
&serial2Driver,
|
|
|
|
&serial3Driver,
|
|
|
|
&serial4Driver,
|
|
|
|
&serial5Driver,
|
|
|
|
&serial6Driver,
|
|
|
|
&serial7Driver,
|
|
|
|
&serial8Driver,
|
|
|
|
&serial9Driver,
|
|
|
|
};
|
|
|
|
|
2015-11-28 05:38:56 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:30 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2020-01-10 15:25:03 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2021-09-07 02:17:32 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR|| \
|
2023-10-22 14:50:57 -03:00
|
|
|
((CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1) && (OBAL_ALLOW_ADC ==1)) || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
2016-01-28 20:34:51 -04:00
|
|
|
static AnalogIn_ADS1115 analogIn;
|
2016-01-25 15:36:27 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || \
|
2016-02-18 00:11:12 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD || \
|
2016-12-29 10:49:38 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
|
2018-06-21 20:40:22 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2016-01-11 12:48:07 -04:00
|
|
|
static AnalogIn_IIO analogIn;
|
2016-06-29 06:10:21 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
|
2016-01-20 09:14:48 -04:00
|
|
|
static AnalogIn_Navio2 analogIn;
|
2014-11-26 08:03:06 -04:00
|
|
|
#else
|
2016-07-28 11:01:53 -03:00
|
|
|
static Empty::AnalogIn analogIn;
|
2014-11-26 08:03:06 -04:00
|
|
|
#endif
|
2014-08-25 13:18:48 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
static Storage storageDriver;
|
2014-09-18 10:35:22 -03:00
|
|
|
|
|
|
|
/*
|
2017-12-13 15:35:47 -04:00
|
|
|
use the BBB gpio driver on ERLE, PXF, BBBMINI, BLUE and PocketPilot
|
2014-09-18 10:35:22 -03:00
|
|
|
*/
|
2016-12-29 10:49:38 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
|
2017-12-13 15:35:47 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2015-10-20 18:13:25 -03:00
|
|
|
static GPIO_BBB gpioDriver;
|
2014-09-18 10:35:22 -03:00
|
|
|
/*
|
|
|
|
use the RPI gpio driver on Navio
|
|
|
|
*/
|
2017-11-02 10:45:18 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:30 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2016-10-17 15:02:48 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \
|
2020-01-10 15:25:03 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2023-10-22 14:50:57 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
2015-10-20 18:13:25 -03:00
|
|
|
static GPIO_RPI gpioDriver;
|
2022-08-30 15:15:11 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
|
|
|
|
static GPIO_Navigator gpioDriver;
|
2017-11-02 10:45:18 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
2017-10-31 13:36:51 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
|
2017-11-02 10:44:55 -03:00
|
|
|
static GPIO_Sysfs gpioDriver;
|
2018-06-21 20:40:22 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP || \
|
2016-08-29 14:10:04 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO
|
2015-10-21 12:18:27 -03:00
|
|
|
static GPIO_Sysfs gpioDriver;
|
2014-09-18 10:35:22 -03:00
|
|
|
#else
|
2015-12-07 15:01:33 -04:00
|
|
|
static Empty::GPIO gpioDriver;
|
2014-09-18 10:35:22 -03:00
|
|
|
#endif
|
2014-08-19 00:48:56 -03:00
|
|
|
|
|
|
|
/*
|
2015-02-27 17:37:37 -04:00
|
|
|
use the PRU based RCInput driver on ERLE and PXF
|
2014-08-19 00:48:56 -03:00
|
|
|
*/
|
2015-09-06 18:35:13 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_PRU rcinDriver;
|
2016-12-29 10:49:38 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
|
2017-12-13 15:35:47 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_AioPRU rcinDriver;
|
2018-01-17 15:05:17 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
|
2024-05-26 22:24:12 -03:00
|
|
|
static RCInput_Multi rcinDriver{2, NEW_NOTHROW RCInput_AioPRU, NEW_NOTHROW RCInput_RCProtocol(NULL, "/dev/ttyO4")};
|
2015-11-28 05:38:56 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:30 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2016-10-17 15:02:48 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \
|
2021-09-07 02:17:32 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2023-10-22 14:50:57 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
2015-11-02 11:24:33 -04:00
|
|
|
static RCInput_RPI rcinDriver;
|
2017-11-01 13:22:10 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_ZYNQ rcinDriver;
|
2016-06-07 02:06:35 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_UDP rcinDriver;
|
2016-09-16 05:43:27 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
2024-05-26 22:24:12 -03:00
|
|
|
static RCInput_Multi rcinDriver{2, NEW_NOTHROW RCInput_RCProtocol("/dev/uart-sbus", "/dev/uart-sumd"), NEW_NOTHROW RCInput_UDP()};
|
2016-09-16 05:43:27 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO
|
2017-05-26 19:00:03 -03:00
|
|
|
static RCInput_SoloLink rcinDriver;
|
2016-06-29 06:10:21 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
|
2016-01-20 09:14:48 -04:00
|
|
|
static RCInput_Navio2 rcinDriver;
|
2017-10-30 06:03:04 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
|
2019-05-02 04:22:42 -03:00
|
|
|
static RCInput_RCProtocol rcinDriver{"/dev/ttyPS0", NULL};
|
2022-09-26 12:52:40 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_VNAV || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
|
2021-01-19 19:23:45 -04:00
|
|
|
// this is needed to allow for RC input using SERIALn_PROTOCOL=23. No fd is opened
|
|
|
|
// in the linux driver and instead user needs to provide a uart via SERIALn_PROTOCOL
|
|
|
|
static RCInput_RCProtocol rcinDriver{nullptr, nullptr};
|
2014-08-19 00:37:10 -03:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput rcinDriver;
|
2014-08-19 00:37:10 -03:00
|
|
|
#endif
|
2014-08-19 00:48:56 -03:00
|
|
|
|
|
|
|
/*
|
2015-02-27 17:37:37 -04:00
|
|
|
use the PRU based RCOutput driver on ERLE and PXF
|
2014-08-19 00:48:56 -03:00
|
|
|
*/
|
2015-09-06 18:35:13 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_PRU rcoutDriver;
|
2016-12-29 10:49:38 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
|
2017-12-13 15:35:47 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_AioPRU rcoutDriver;
|
2014-09-18 10:29:47 -03:00
|
|
|
/*
|
2015-11-02 11:24:33 -04:00
|
|
|
use the PCA9685 based RCOutput driver on Navio and Erle-Brain 2
|
2014-09-18 10:29:47 -03:00
|
|
|
*/
|
2017-11-02 10:45:18 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:30 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI
|
2020-11-17 14:31:18 -04:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(1, PCA9685_PRIMARY_ADDRESS), 24576000, 3, RPI_GPIO_<27>());
|
2017-11-02 10:45:18 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
2020-11-17 14:31:18 -04:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(1, PCA9685_PRIMARY_ADDRESS), 24576000, 3, NAVIO_GPIO_PCA_OE);
|
2015-11-28 05:38:56 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
|
2020-11-17 14:31:18 -04:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(1, PCA9685_QUATENARY_ADDRESS), 0, 0, RPI_GPIO_<4>());
|
2016-10-17 15:02:48 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK
|
2020-11-17 14:31:18 -04:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(1, PCA9685_QUINARY_ADDRESS), 0, 0, RPI_GPIO_<27>());
|
2020-01-10 15:25:03 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
|
2021-03-23 22:01:34 -03:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(4, PCA9685_PRIMARY_ADDRESS), 24576000, 0, RPI_GPIO_<26>());
|
2017-08-17 19:41:58 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_ZYNQ rcoutDriver;
|
2016-06-07 02:06:35 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2016-07-12 15:55:39 -03:00
|
|
|
static RCOutput_Bebop rcoutDriver(i2c_mgr_instance.get_device(HAL_RCOUT_BEBOP_BLDC_I2C_BUS, HAL_RCOUT_BEBOP_BLDC_I2C_ADDR));
|
2016-06-07 02:06:35 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
2016-07-14 07:16:06 -03:00
|
|
|
static RCOutput_Disco rcoutDriver(i2c_mgr_instance.get_device(HAL_RCOUT_DISCO_BLDC_I2C_BUS, HAL_RCOUT_DISCO_BLDC_I2C_ADDR));
|
2016-01-20 09:14:48 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
|
2016-06-07 02:06:35 -03:00
|
|
|
static RCOutput_Sysfs rcoutDriver(0, 0, 14);
|
2016-08-29 14:10:04 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO
|
2017-05-18 21:42:48 -03:00
|
|
|
static ap::RCOutput_Tap rcoutDriver;
|
2016-06-29 06:10:21 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
|
|
|
|
static RCOutput_Sysfs rcoutDriver(0, 0, 15);
|
2017-10-30 06:03:04 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
|
|
|
|
static RCOutput_Sysfs rcoutDriver(0, 0, 8);
|
2021-09-07 02:17:32 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
|
|
|
|
static RCOutput_PCA9685 rcoutDriver(i2c_mgr_instance.get_device(1, PCA9685_PRIMARY_ADDRESS), 0, 0, RPI_GPIO_<17>());
|
2023-10-22 14:50:57 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
|
|
|
static RCOutput_Sysfs rcoutDriver(0, 0, 2);
|
2014-08-19 00:48:56 -03:00
|
|
|
#else
|
2015-12-07 15:01:33 -04:00
|
|
|
static Empty::RCOutput rcoutDriver;
|
2014-08-19 00:48:56 -03:00
|
|
|
#endif
|
2014-09-18 10:29:47 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
static Scheduler schedulerInstance;
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2018-06-21 20:40:22 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-11-24 09:46:26 -04:00
|
|
|
static OpticalFlow_Onboard opticalFlow;
|
|
|
|
#else
|
|
|
|
static Empty::OpticalFlow opticalFlow;
|
|
|
|
#endif
|
|
|
|
|
2024-01-01 21:49:00 -04:00
|
|
|
#if HAL_WITH_DSP
|
2019-08-15 18:15:31 -03:00
|
|
|
static Empty::DSP dspDriver;
|
2024-01-01 21:49:00 -04:00
|
|
|
#endif
|
2019-03-25 21:14:17 -03:00
|
|
|
static Empty::Flash flashDriver;
|
2022-08-19 06:47:48 -03:00
|
|
|
static Empty::WSPIDeviceManager wspi_mgr_instance;
|
2019-03-25 21:14:17 -03:00
|
|
|
|
2020-05-31 09:28:24 -03:00
|
|
|
#if HAL_NUM_CAN_IFACES
|
|
|
|
static CANIface* canDrivers[HAL_NUM_CAN_IFACES];
|
|
|
|
#endif
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
HAL_Linux::HAL_Linux() :
|
|
|
|
AP_HAL::HAL(
|
2023-12-10 23:32:18 -04:00
|
|
|
&serial0Driver,
|
|
|
|
&serial1Driver,
|
|
|
|
&serial2Driver,
|
|
|
|
&serial3Driver,
|
|
|
|
&serial4Driver,
|
|
|
|
&serial5Driver,
|
|
|
|
&serial6Driver,
|
|
|
|
&serial7Driver,
|
|
|
|
&serial8Driver,
|
|
|
|
&serial9Driver,
|
2015-11-22 20:07:42 -04:00
|
|
|
&i2c_mgr_instance,
|
2016-07-22 11:22:14 -03:00
|
|
|
&spi_mgr_instance,
|
2022-08-19 06:47:48 -03:00
|
|
|
&wspi_mgr_instance,
|
2013-09-22 03:01:24 -03:00
|
|
|
&analogIn,
|
|
|
|
&storageDriver,
|
2023-12-10 23:32:18 -04:00
|
|
|
&serial0Driver,
|
2013-09-22 03:01:24 -03:00
|
|
|
&gpioDriver,
|
|
|
|
&rcinDriver,
|
|
|
|
&rcoutDriver,
|
|
|
|
&schedulerInstance,
|
2015-11-24 09:46:26 -04:00
|
|
|
&utilInstance,
|
2017-04-02 11:55:29 -03:00
|
|
|
&opticalFlow,
|
2019-03-25 21:14:17 -03:00
|
|
|
&flashDriver,
|
2024-01-01 21:49:00 -04:00
|
|
|
#if HAL_WITH_DSP
|
2019-08-15 18:15:31 -03:00
|
|
|
&dspDriver,
|
2024-01-01 21:49:00 -04:00
|
|
|
#endif
|
2020-05-31 09:28:24 -03:00
|
|
|
#if HAL_NUM_CAN_IFACES
|
|
|
|
(AP_HAL::CANIface**)canDrivers
|
|
|
|
#else
|
|
|
|
nullptr
|
|
|
|
#endif
|
|
|
|
)
|
2013-09-22 03:01:24 -03:00
|
|
|
{}
|
|
|
|
|
2014-06-11 03:34:07 -03:00
|
|
|
void _usage(void)
|
|
|
|
{
|
2023-12-10 23:32:18 -04:00
|
|
|
printf("Usage: --serial0 serial0Path --serial1 serial1Path \n");
|
2023-06-17 01:47:56 -03:00
|
|
|
printf("Examples:\n");
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\tserial (0 through 9 available):\n");
|
|
|
|
printf("\t --serial0 /dev/ttyO4\n");
|
|
|
|
printf("\t --serial3 /dev/ttyS1\n");
|
2023-12-12 13:43:50 -04:00
|
|
|
printf("\tlegacy UART options are deprecated, their mappings are:\n");
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\t -A/--uartA is SERIAL0\n");
|
2023-12-12 13:43:50 -04:00
|
|
|
printf("\t -C/--uartC is SERIAL1\n"); // ordering captures the historical use of uartB as SERIAL3
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\t -D/--uartD is SERIAL2\n");
|
2023-12-10 23:32:18 -04:00
|
|
|
printf("\t -B/--uartB is SERIAL3\n");
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\t -E/--uartE is SERIAL4\n");
|
|
|
|
printf("\t -F/--uartF is SERIAL5\n");
|
|
|
|
printf("\t -G/--uartG is SERIAL6\n");
|
|
|
|
printf("\t -H/--uartH is SERIAL7\n");
|
|
|
|
printf("\t -I/--uartI is SERIAL8\n");
|
|
|
|
printf("\t -J/--uartJ is SERIAL9\n");
|
2016-07-07 05:27:07 -03:00
|
|
|
printf("\tnetworking tcp:\n");
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\t --serial1 tcp:192.168.2.15:1243:wait\n");
|
|
|
|
printf("\t --serial0 tcp:11.0.0.2:5678\n");
|
|
|
|
printf("\t --serial0 udp:11.0.0.2:14550\n");
|
|
|
|
printf("\t --serial0 udp:11.0.0.2:14550\n");
|
2016-07-07 05:27:07 -03:00
|
|
|
printf("\tnetworking UDP:\n");
|
2022-09-20 07:31:27 -03:00
|
|
|
printf("\t --serial0 udp:11.0.0.255:14550:bcast\n");
|
|
|
|
printf("\t --serial0 udpin:0.0.0.0:14550\n");
|
2016-07-07 05:27:07 -03:00
|
|
|
printf("\tcustom log path:\n");
|
2015-06-28 16:04:08 -03:00
|
|
|
printf("\t --log-directory /var/APM/logs\n");
|
|
|
|
printf("\t -l /var/APM/logs\n");
|
2016-07-07 05:27:07 -03:00
|
|
|
printf("\tcustom terrain path:\n");
|
2015-06-28 16:04:08 -03:00
|
|
|
printf("\t --terrain-directory /var/APM/terrain\n");
|
|
|
|
printf("\t -t /var/APM/terrain\n");
|
2020-01-17 11:05:19 -04:00
|
|
|
printf("\tcustom storage path:\n");
|
|
|
|
printf("\t --storage-directory /var/APM/storage\n");
|
|
|
|
printf("\t -s /var/APM/storage\n");
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-07 05:27:07 -03:00
|
|
|
printf("\tmodule support:\n");
|
2016-07-13 20:24:11 -03:00
|
|
|
printf("\t --module-directory %s\n", AP_MODULE_DEFAULT_DIRECTORY);
|
|
|
|
printf("\t -M %s\n", AP_MODULE_DEFAULT_DIRECTORY);
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2021-10-08 17:40:49 -03:00
|
|
|
printf("\tcpu affinity:\n");
|
|
|
|
printf("\t --cpu-affinity 1 (single cpu) or 1,3 (multiple cpus) or 1-3 (range of cpus)\n");
|
|
|
|
printf("\t -c 1 (single cpu) or 1,3 (multiple cpus) or 1-3 (range of cpus)\n");
|
2014-06-11 03:34:07 -03:00
|
|
|
}
|
|
|
|
|
2015-10-19 12:59:47 -03:00
|
|
|
void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const
|
2013-09-22 03:01:24 -03:00
|
|
|
{
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-13 20:24:11 -03:00
|
|
|
const char *module_path = AP_MODULE_DEFAULT_DIRECTORY;
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2021-10-08 17:40:49 -03:00
|
|
|
|
2023-12-12 13:43:50 -04:00
|
|
|
enum long_options {
|
|
|
|
CMDLINE_SERIAL0 = 1, // must be in 0-9 order and numbered consecutively
|
|
|
|
CMDLINE_SERIAL1,
|
|
|
|
CMDLINE_SERIAL2,
|
|
|
|
CMDLINE_SERIAL3,
|
|
|
|
CMDLINE_SERIAL4,
|
|
|
|
CMDLINE_SERIAL5,
|
|
|
|
CMDLINE_SERIAL6,
|
|
|
|
CMDLINE_SERIAL7,
|
|
|
|
CMDLINE_SERIAL8,
|
|
|
|
CMDLINE_SERIAL9,
|
|
|
|
};
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
int opt;
|
2015-06-28 16:04:08 -03:00
|
|
|
const struct GetOptLong::option options[] = {
|
|
|
|
{"uartA", true, 0, 'A'},
|
2023-12-10 23:32:18 -04:00
|
|
|
{"uartB", true, 0, 'B'},
|
2023-12-12 13:43:50 -04:00
|
|
|
{"uartC", true, 0, 'C'},
|
|
|
|
{"uartD", true, 0, 'D'},
|
2015-06-28 16:04:08 -03:00
|
|
|
{"uartE", true, 0, 'E'},
|
2016-04-19 00:47:25 -03:00
|
|
|
{"uartF", true, 0, 'F'},
|
2018-06-27 08:34:24 -03:00
|
|
|
{"uartG", true, 0, 'G'},
|
2019-07-12 01:58:31 -03:00
|
|
|
{"uartH", true, 0, 'H'},
|
2020-11-26 02:49:00 -04:00
|
|
|
{"uartI", true, 0, 'I'},
|
2021-11-05 00:17:40 -03:00
|
|
|
{"uartJ", true, 0, 'J'},
|
2023-12-12 13:43:50 -04:00
|
|
|
{"serial0", true, 0, CMDLINE_SERIAL0},
|
|
|
|
{"serial1", true, 0, CMDLINE_SERIAL1},
|
|
|
|
{"serial2", true, 0, CMDLINE_SERIAL2},
|
|
|
|
{"serial3", true, 0, CMDLINE_SERIAL3},
|
|
|
|
{"serial4", true, 0, CMDLINE_SERIAL4},
|
|
|
|
{"serial5", true, 0, CMDLINE_SERIAL5},
|
|
|
|
{"serial6", true, 0, CMDLINE_SERIAL6},
|
|
|
|
{"serial7", true, 0, CMDLINE_SERIAL7},
|
|
|
|
{"serial8", true, 0, CMDLINE_SERIAL8},
|
|
|
|
{"serial9", true, 0, CMDLINE_SERIAL9},
|
2015-06-28 16:04:08 -03:00
|
|
|
{"log-directory", true, 0, 'l'},
|
|
|
|
{"terrain-directory", true, 0, 't'},
|
2018-03-28 03:19:37 -03:00
|
|
|
{"storage-directory", true, 0, 's'},
|
2016-07-07 05:27:07 -03:00
|
|
|
{"module-directory", true, 0, 'M'},
|
2021-02-06 02:59:54 -04:00
|
|
|
{"defaults", true, 0, 'd'},
|
2021-09-17 00:28:40 -03:00
|
|
|
{"cpu-affinity", true, 0, 'c'},
|
2015-06-28 16:04:08 -03:00
|
|
|
{"help", false, 0, 'h'},
|
|
|
|
{0, false, 0, 0}
|
|
|
|
};
|
|
|
|
|
2022-09-20 07:31:27 -03:00
|
|
|
GetOptLong gopt(argc, argv, "A:B:C:D:E:F:G:H:I:J:l:t:s:he:SM:c:",
|
2015-06-28 16:04:08 -03:00
|
|
|
options);
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
/*
|
|
|
|
parse command line options
|
|
|
|
*/
|
2015-06-28 16:04:08 -03:00
|
|
|
while ((opt = gopt.getoption()) != -1) {
|
2013-09-22 03:01:24 -03:00
|
|
|
switch (opt) {
|
|
|
|
case 'A':
|
2023-12-12 13:43:50 -04:00
|
|
|
case 'B':
|
2013-09-28 11:51:43 -03:00
|
|
|
case 'C':
|
2015-12-13 23:19:54 -04:00
|
|
|
case 'D':
|
2015-02-12 06:00:52 -04:00
|
|
|
case 'E':
|
2016-04-19 00:47:25 -03:00
|
|
|
case 'F':
|
2018-06-27 08:34:24 -03:00
|
|
|
case 'G':
|
2019-07-12 01:58:31 -03:00
|
|
|
case 'H':
|
2020-11-26 02:49:00 -04:00
|
|
|
case 'I':
|
2023-12-12 13:43:50 -04:00
|
|
|
case 'J': {
|
|
|
|
int uart_idx = opt - 'A';
|
|
|
|
// ordering captures the historical use of uartB as SERIAL3
|
|
|
|
static const uint8_t mapping[] = { 0, 3, 1, 2, 4, 5, 6, 7, 8, 9 };
|
|
|
|
int serial_idx = mapping[uart_idx];
|
|
|
|
printf("WARNING: deprecated option --uart%c/-%c will be removed in "
|
|
|
|
"a future release. Use --serial%d instead.\n",
|
|
|
|
(char)opt, (char)opt, serial_idx);
|
|
|
|
serialDrivers[serial_idx]->set_device_path(gopt.optarg);
|
2020-11-26 02:49:00 -04:00
|
|
|
break;
|
2023-12-12 13:43:50 -04:00
|
|
|
}
|
|
|
|
case CMDLINE_SERIAL0:
|
|
|
|
case CMDLINE_SERIAL1:
|
|
|
|
case CMDLINE_SERIAL2:
|
|
|
|
case CMDLINE_SERIAL3:
|
|
|
|
case CMDLINE_SERIAL4:
|
|
|
|
case CMDLINE_SERIAL5:
|
|
|
|
case CMDLINE_SERIAL6:
|
|
|
|
case CMDLINE_SERIAL7:
|
|
|
|
case CMDLINE_SERIAL8:
|
|
|
|
case CMDLINE_SERIAL9:
|
|
|
|
serialDrivers[opt - CMDLINE_SERIAL0]->set_device_path(gopt.optarg);
|
2021-11-05 00:17:40 -03:00
|
|
|
break;
|
2016-05-17 23:26:57 -03:00
|
|
|
case 'l':
|
2015-06-29 22:42:30 -03:00
|
|
|
utilInstance.set_custom_log_directory(gopt.optarg);
|
2015-06-28 16:04:08 -03:00
|
|
|
break;
|
|
|
|
case 't':
|
2015-06-29 22:42:30 -03:00
|
|
|
utilInstance.set_custom_terrain_directory(gopt.optarg);
|
2015-02-12 06:00:52 -04:00
|
|
|
break;
|
2018-03-28 03:19:37 -03:00
|
|
|
case 's':
|
|
|
|
utilInstance.set_custom_storage_directory(gopt.optarg);
|
|
|
|
break;
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-07 05:27:07 -03:00
|
|
|
case 'M':
|
|
|
|
module_path = gopt.optarg;
|
|
|
|
break;
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2021-02-06 02:59:54 -04:00
|
|
|
case 'd':
|
|
|
|
utilInstance.set_custom_defaults_path(gopt.optarg);
|
|
|
|
break;
|
2021-09-17 00:28:40 -03:00
|
|
|
case 'c':
|
|
|
|
cpu_set_t cpu_affinity;
|
|
|
|
if (!utilInstance.parse_cpu_set(gopt.optarg, &cpu_affinity)) {
|
2021-10-08 17:40:49 -03:00
|
|
|
fprintf(stderr, "Could not parse cpu affinity: %s\n", gopt.optarg);
|
2021-09-17 00:28:40 -03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
Linux::Scheduler::from(scheduler)->set_cpu_affinity(cpu_affinity);
|
|
|
|
break;
|
2013-09-22 03:01:24 -03:00
|
|
|
case 'h':
|
2014-06-11 03:34:07 -03:00
|
|
|
_usage();
|
2013-09-22 03:01:24 -03:00
|
|
|
exit(0);
|
|
|
|
default:
|
|
|
|
printf("Unknown option '%c'\n", (char)opt);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 16:52:09 -04:00
|
|
|
// NOTE: signal handlers are only set before the main loop, so
|
|
|
|
// that if anything before the loops hangs, the default signals
|
|
|
|
// can still stop the process proprely, although without proper
|
|
|
|
// teardown.
|
|
|
|
// This isn't perfect, but still prevents an unkillable process.
|
2016-10-26 18:27:12 -03:00
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
scheduler->init();
|
2014-07-13 20:20:47 -03:00
|
|
|
gpio->init();
|
2015-12-02 11:14:20 -04:00
|
|
|
rcout->init();
|
|
|
|
rcin->init();
|
2020-12-10 21:15:09 -04:00
|
|
|
serial(0)->begin(115200);
|
2015-12-02 11:14:20 -04:00
|
|
|
analogin->init();
|
2015-07-01 07:40:07 -03:00
|
|
|
utilInstance.init(argc+gopt.optind-1, &argv[gopt.optind-1]);
|
2015-10-19 11:38:47 -03:00
|
|
|
|
|
|
|
// NOTE: See commit 9f5b4ffca ("AP_HAL_Linux_Class: Correct
|
|
|
|
// deadlock, and infinite loop in setup()") for details about the
|
|
|
|
// order of scheduler initialize and setup on Linux.
|
2020-12-23 07:27:27 -04:00
|
|
|
scheduler->set_system_initialized();
|
2016-07-07 05:27:07 -03:00
|
|
|
|
|
|
|
// possibly load external modules
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-07 05:27:07 -03:00
|
|
|
if (module_path != nullptr) {
|
|
|
|
AP_Module::init(module_path);
|
|
|
|
}
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2016-07-07 05:27:07 -03:00
|
|
|
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-07 05:27:07 -03:00
|
|
|
AP_Module::call_hook_setup_start();
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2015-10-19 11:38:47 -03:00
|
|
|
callbacks->setup();
|
2018-02-26 03:56:23 -04:00
|
|
|
#if AP_MODULE_SUPPORTED
|
2016-07-07 05:27:07 -03:00
|
|
|
AP_Module::call_hook_setup_complete();
|
2018-02-26 03:56:23 -04:00
|
|
|
#endif
|
2015-10-19 11:38:47 -03:00
|
|
|
|
2023-12-18 16:52:09 -04:00
|
|
|
setup_signal_handlers();
|
|
|
|
|
2016-10-26 18:27:12 -03:00
|
|
|
while (!_should_exit) {
|
2015-10-19 11:38:47 -03:00
|
|
|
callbacks->loop();
|
|
|
|
}
|
2016-10-26 18:27:12 -03:00
|
|
|
|
2021-09-08 13:24:45 -03:00
|
|
|
// At least try to stop all PWM before shutting down
|
|
|
|
rcout->force_safety_on();
|
2016-10-26 18:27:12 -03:00
|
|
|
rcin->teardown();
|
|
|
|
I2CDeviceManager::from(i2c_mgr)->teardown();
|
|
|
|
SPIDeviceManager::from(spi)->teardown();
|
2016-10-26 18:58:57 -03:00
|
|
|
Scheduler::from(scheduler)->teardown();
|
2016-10-26 18:27:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_Linux::setup_signal_handlers() const
|
|
|
|
{
|
|
|
|
struct sigaction sa = { };
|
|
|
|
|
|
|
|
sa.sa_flags = SA_NOCLDSTOP;
|
|
|
|
sa.sa_handler = HAL_Linux::exit_signal_handler;
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
2015-10-19 11:38:47 -03:00
|
|
|
}
|
|
|
|
|
2020-03-01 19:50:34 -04:00
|
|
|
HAL_Linux hal_linux;
|
2016-10-26 18:27:12 -03:00
|
|
|
|
|
|
|
void HAL_Linux::exit_signal_handler(int signum)
|
|
|
|
{
|
2020-03-01 19:50:34 -04:00
|
|
|
hal_linux._should_exit = true;
|
2016-10-26 18:27:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
const AP_HAL::HAL &AP_HAL::get_HAL()
|
|
|
|
{
|
2020-03-01 19:50:34 -04:00
|
|
|
return hal_linux;
|
2015-10-16 17:22:11 -03:00
|
|
|
}
|
2023-11-23 21:56:36 -04:00
|
|
|
|
|
|
|
AP_HAL::HAL &AP_HAL::get_HAL_mutable()
|
|
|
|
{
|
|
|
|
return hal_linux;
|
|
|
|
}
|