2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-07-06 23:03:26 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2015-10-19 11:38:47 -03:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
#include "HAL_Linux_Class.h"
|
|
|
|
#include "AP_HAL_Linux_Private.h"
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/utility/getopt_cpp.h>
|
2013-09-22 03:01:24 -03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.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>
|
2014-08-19 00:48:56 -03:00
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
using namespace Linux;
|
|
|
|
|
2013-09-28 11:51:43 -03:00
|
|
|
// 3 serial ports on Linux for now
|
2015-10-20 18:13:25 -03:00
|
|
|
static UARTDriver uartADriver(true);
|
2014-11-07 06:17:50 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
2015-10-20 18:13:25 -03:00
|
|
|
static SPIUARTDriver uartBDriver;
|
2014-11-07 06:17:50 -04:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static UARTDriver uartBDriver(false);
|
2014-11-07 06:17:50 -04:00
|
|
|
#endif
|
2015-08-17 23:34:28 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-10-20 18:13:25 -03:00
|
|
|
static RPIOUARTDriver uartCDriver;
|
2015-08-17 23:34:28 -03:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static UARTDriver uartCDriver(false);
|
2015-08-17 23:34:28 -03:00
|
|
|
#endif
|
2015-10-20 18:13:25 -03:00
|
|
|
static UARTDriver uartEDriver(false);
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2015-06-15 14:46:31 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-10-20 18:13:25 -03:00
|
|
|
static Semaphore i2cSemaphore0;
|
|
|
|
static I2CDriver i2cDriver0(&i2cSemaphore0, "/dev/i2c-0");
|
|
|
|
static Semaphore i2cSemaphore1;
|
|
|
|
static I2CDriver i2cDriver1(&i2cSemaphore1, "/dev/i2c-1");
|
|
|
|
static Semaphore i2cSemaphore2;
|
|
|
|
static I2CDriver i2cDriver2(&i2cSemaphore2, "/dev/i2c-2");
|
2015-06-15 14:46:31 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2015-10-20 18:13:25 -03:00
|
|
|
static Semaphore i2cSemaphore0;
|
|
|
|
static I2CDriver i2cDriver0(&i2cSemaphore0, "/dev/i2c-2");
|
2015-08-27 01:46:49 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
static Semaphore i2cSemaphore0;
|
|
|
|
static const char * const i2c_devpaths[] = {
|
|
|
|
/* UEFI with lpss set to ACPI */
|
|
|
|
"/devices/platform/80860F41:05",
|
|
|
|
/* UEFI with lpss set to PCI */
|
|
|
|
"/devices/pci0000:00/0000:00:18.6",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static I2CDriver i2cDriver0(&i2cSemaphore0, i2c_devpaths);
|
|
|
|
/* One additional emulated bus */
|
|
|
|
static Semaphore i2cSemaphore1;
|
|
|
|
static I2CDriver i2cDriver1(&i2cSemaphore1, "/dev/i2c-10");
|
2015-07-05 16:53:17 -03:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static Semaphore i2cSemaphore0;
|
|
|
|
static I2CDriver i2cDriver0(&i2cSemaphore0, "/dev/i2c-1");
|
2015-07-05 16:53:17 -03:00
|
|
|
#endif
|
2015-10-20 18:13:25 -03:00
|
|
|
static SPIDeviceManager spiDeviceManager;
|
2014-11-26 08:03:06 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
static NavioAnalogIn analogIn;
|
2015-08-17 23:34:28 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
|
|
|
static RaspilotAnalogIn analogIn;
|
2014-11-26 08:03:06 -04:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static AnalogIn analogIn;
|
2014-11-26 08:03:06 -04:00
|
|
|
#endif
|
2014-08-25 13:18:48 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
select between FRAM and FS
|
|
|
|
*/
|
|
|
|
#if LINUX_STORAGE_USE_FRAM == 1
|
2015-10-20 18:13:25 -03:00
|
|
|
static Storage_FRAM storageDriver;
|
2014-08-25 13:18:48 -03:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static Storage storageDriver;
|
2014-08-25 13:18:48 -03:00
|
|
|
#endif
|
2014-09-18 10:35:22 -03:00
|
|
|
|
|
|
|
/*
|
2015-01-10 19:20:38 -04:00
|
|
|
use the BBB gpio driver on ERLE, PXF and BBBMINI
|
2014-09-18 10:35:22 -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 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
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
|
|
|
|
*/
|
2015-08-17 23:34:28 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-10-20 18:13:25 -03:00
|
|
|
static GPIO_RPI gpioDriver;
|
2015-10-21 12:18:27 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
static GPIO_Sysfs gpioDriver;
|
2014-09-18 10:35:22 -03:00
|
|
|
#else
|
|
|
|
static Empty::EmptyGPIO gpioDriver;
|
|
|
|
#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;
|
2015-02-27 17:37:37 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_AioPRU rcinDriver;
|
2014-10-26 16:18:04 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_Navio rcinDriver;
|
2015-08-17 23:34:28 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_Raspilot rcinDriver;
|
2014-11-13 19:16:59 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_ZYNQ rcinDriver;
|
2015-09-04 13:37:09 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput_UDP rcinDriver;
|
2015-10-21 12:22:45 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
static RCInput_UART rcinDriver("/dev/ttyS2");
|
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;
|
2015-02-27 17:37:37 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_AioPRU rcoutDriver;
|
2014-09-18 10:29:47 -03:00
|
|
|
/*
|
|
|
|
use the PCA9685 based RCOutput driver on Navio
|
|
|
|
*/
|
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_PCA9685 rcoutDriver(PCA9685_PRIMARY_ADDRESS, true, 3, RPI_GPIO_27);
|
2015-08-17 23:34:28 -03:00
|
|
|
/*
|
|
|
|
use the STM32 based RCOutput driver on Raspilot
|
|
|
|
*/
|
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_Raspilot rcoutDriver;
|
2014-11-13 19:16:59 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_ZYNQ rcoutDriver;
|
2015-07-10 01:02:32 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCOutput_Bebop rcoutDriver;
|
2015-10-21 12:23:28 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
static RCOutput_PCA9685 rcoutDriver(PCA9685_PRIMARY_ADDRESS, false, 0, MINNOW_GPIO_S5_1);
|
2014-08-19 00:48:56 -03:00
|
|
|
#else
|
|
|
|
static Empty::EmptyRCOutput rcoutDriver;
|
|
|
|
#endif
|
2014-09-18 10:29:47 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
static Scheduler schedulerInstance;
|
2015-09-30 12:02:48 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-10-20 18:13:25 -03:00
|
|
|
static UtilRPI utilInstance;
|
2015-09-23 12:52:07 -03:00
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
static Util utilInstance;
|
2015-09-23 12:52:07 -03:00
|
|
|
#endif
|
2013-09-22 03:01:24 -03:00
|
|
|
|
|
|
|
HAL_Linux::HAL_Linux() :
|
|
|
|
AP_HAL::HAL(
|
|
|
|
&uartADriver,
|
|
|
|
&uartBDriver,
|
|
|
|
&uartCDriver,
|
2013-11-22 04:16:31 -04:00
|
|
|
NULL, /* no uartD */
|
2015-02-12 06:00:52 -04:00
|
|
|
&uartEDriver,
|
2015-06-15 14:46:31 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
|
|
|
&i2cDriver0,
|
|
|
|
&i2cDriver1,
|
|
|
|
&i2cDriver2,
|
2015-08-27 01:46:49 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
&i2cDriver0,
|
|
|
|
&i2cDriver1,
|
|
|
|
NULL,
|
2015-06-15 14:46:31 -03:00
|
|
|
#else
|
|
|
|
&i2cDriver0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#endif
|
2013-09-22 03:01:24 -03:00
|
|
|
&spiDeviceManager,
|
|
|
|
&analogIn,
|
|
|
|
&storageDriver,
|
2013-10-05 05:32:57 -03:00
|
|
|
&uartADriver,
|
2013-09-22 03:01:24 -03:00
|
|
|
&gpioDriver,
|
|
|
|
&rcinDriver,
|
|
|
|
&rcoutDriver,
|
|
|
|
&schedulerInstance,
|
|
|
|
&utilInstance)
|
|
|
|
{}
|
|
|
|
|
2014-06-11 03:34:07 -03:00
|
|
|
void _usage(void)
|
|
|
|
{
|
|
|
|
printf("Usage: -A uartAPath -B uartBPath -C uartCPath\n");
|
|
|
|
printf("Options:\n");
|
|
|
|
printf("\t-serial: -A /dev/ttyO4\n");
|
|
|
|
printf("\t -B /dev/ttyS1\n");
|
|
|
|
printf("\t-tcp: -C tcp:192.168.2.15:1243:wait\n");
|
|
|
|
printf("\t -A tcp:11.0.0.2:5678\n");
|
2015-06-03 08:46:42 -03:00
|
|
|
printf("\t -A udp:11.0.0.2:5678\n");
|
2015-06-28 16:04:08 -03:00
|
|
|
printf("\t-custom log path:\n");
|
|
|
|
printf("\t --log-directory /var/APM/logs\n");
|
|
|
|
printf("\t -l /var/APM/logs\n");
|
|
|
|
printf("\t-custom terrain path:\n");
|
|
|
|
printf("\t --terrain-directory /var/APM/terrain\n");
|
|
|
|
printf("\t -t /var/APM/terrain\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
|
|
|
{
|
2015-10-19 12:59:47 -03:00
|
|
|
assert(callbacks);
|
|
|
|
|
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'},
|
|
|
|
{"uartB", true, 0, 'B'},
|
|
|
|
{"uartC", true, 0, 'C'},
|
|
|
|
{"uartE", true, 0, 'E'},
|
|
|
|
{"log-directory", true, 0, 'l'},
|
|
|
|
{"terrain-directory", true, 0, 't'},
|
|
|
|
{"help", false, 0, 'h'},
|
|
|
|
{0, false, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
GetOptLong gopt(argc, argv, "A:B:C:E:l:t:h",
|
|
|
|
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':
|
2015-06-28 16:04:08 -03:00
|
|
|
uartADriver.set_device_path(gopt.optarg);
|
2013-09-22 03:01:24 -03:00
|
|
|
break;
|
|
|
|
case 'B':
|
2015-06-28 16:04:08 -03:00
|
|
|
uartBDriver.set_device_path(gopt.optarg);
|
2013-09-22 03:01:24 -03:00
|
|
|
break;
|
2013-09-28 11:51:43 -03:00
|
|
|
case 'C':
|
2015-06-28 16:04:08 -03:00
|
|
|
uartCDriver.set_device_path(gopt.optarg);
|
2013-09-28 11:51:43 -03:00
|
|
|
break;
|
2015-02-12 06:00:52 -04:00
|
|
|
case 'E':
|
2015-06-28 16:04:08 -03:00
|
|
|
uartEDriver.set_device_path(gopt.optarg);
|
|
|
|
break;
|
|
|
|
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;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduler->init(NULL);
|
2014-07-13 20:20:47 -03:00
|
|
|
gpio->init();
|
2015-06-15 14:46:31 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2015-07-10 01:02:32 -03:00
|
|
|
i2c->begin();
|
2015-06-15 14:46:31 -03:00
|
|
|
i2c1->begin();
|
|
|
|
i2c2->begin();
|
2015-08-27 01:46:49 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
|
|
|
i2c->begin();
|
|
|
|
i2c1->begin();
|
2015-06-15 14:46:31 -03:00
|
|
|
#else
|
2015-07-10 01:02:32 -03:00
|
|
|
i2c->begin();
|
2015-06-15 14:46:31 -03:00
|
|
|
#endif
|
2015-09-30 08:49:59 -03:00
|
|
|
spi->init(NULL);
|
2014-05-14 06:34:45 -03:00
|
|
|
rcout->init(NULL);
|
2014-08-14 13:48:17 -03:00
|
|
|
rcin->init(NULL);
|
2014-09-18 10:36:55 -03:00
|
|
|
uartA->begin(115200);
|
2015-02-12 06:00:52 -04:00
|
|
|
uartE->begin(115200);
|
2014-11-26 08:03:06 -04:00
|
|
|
analogin->init(NULL);
|
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.
|
|
|
|
scheduler->system_initialized();
|
|
|
|
callbacks->setup();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
callbacks->loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& AP_HAL::get_HAL() {
|
|
|
|
static const HAL_Linux hal;
|
|
|
|
return hal;
|
|
|
|
}
|
2013-09-22 03:01:24 -03:00
|
|
|
|
|
|
|
#endif
|