2013-09-22 03:01:24 -03:00
|
|
|
#include <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
|
|
|
|
|
|
|
#include "HAL_Linux_Class.h"
|
|
|
|
#include "AP_HAL_Linux_Private.h"
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-08-19 00:48:56 -03:00
|
|
|
#include <AP_HAL_Empty.h>
|
|
|
|
#include <AP_HAL_Empty_Private.h>
|
|
|
|
|
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
|
2013-09-30 23:49:58 -03:00
|
|
|
static LinuxUARTDriver uartADriver(true);
|
2014-11-07 06:17:50 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
static LinuxSPIUARTDriver uartBDriver;
|
|
|
|
#else
|
2013-09-30 23:49:58 -03:00
|
|
|
static LinuxUARTDriver uartBDriver(false);
|
2014-11-07 06:17:50 -04:00
|
|
|
#endif
|
2013-09-30 23:49:58 -03:00
|
|
|
static LinuxUARTDriver uartCDriver(false);
|
2015-02-12 06:00:52 -04:00
|
|
|
static LinuxUARTDriver uartEDriver(false);
|
2013-09-22 03:01:24 -03:00
|
|
|
|
|
|
|
static LinuxSemaphore i2cSemaphore;
|
2013-09-27 21:00:49 -03:00
|
|
|
static LinuxI2CDriver i2cDriver(&i2cSemaphore, "/dev/i2c-1");
|
2013-09-28 11:51:43 -03:00
|
|
|
static LinuxSPIDeviceManager spiDeviceManager;
|
2014-11-26 08:03:06 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
static NavioAnalogIn analogIn;
|
|
|
|
#else
|
2013-09-22 03:01:24 -03:00
|
|
|
static LinuxAnalogIn 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
|
|
|
|
static LinuxStorage_FRAM storageDriver;
|
|
|
|
#else
|
2013-09-22 03:01:24 -03:00
|
|
|
static LinuxStorage 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-01-10 19:20:38 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLE || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2014-09-18 10:35:22 -03:00
|
|
|
static LinuxGPIO_BBB gpioDriver;
|
|
|
|
/*
|
|
|
|
use the RPI gpio driver on Navio
|
|
|
|
*/
|
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
static LinuxGPIO_RPI gpioDriver;
|
|
|
|
#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-02-27 17:37:37 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLE
|
2014-08-19 00:37:10 -03:00
|
|
|
static LinuxRCInput_PRU rcinDriver;
|
2015-02-27 17:37:37 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
|
|
|
static LinuxRCInput_AioPRU rcinDriver;
|
2014-10-26 16:18:04 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
static LinuxRCInput_Navio rcinDriver;
|
2014-11-13 19:16:59 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ
|
|
|
|
static LinuxRCInput_ZYNQ rcinDriver;
|
2014-08-19 00:37:10 -03:00
|
|
|
#else
|
2013-09-22 03:01:24 -03:00
|
|
|
static LinuxRCInput 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-02-27 17:37:37 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLE
|
2014-08-19 00:48:56 -03:00
|
|
|
static LinuxRCOutput_PRU rcoutDriver;
|
2015-02-27 17:37:37 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
|
|
|
static LinuxRCOutput_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
|
|
|
|
static LinuxRCOutput_Navio rcoutDriver;
|
2014-11-13 19:16:59 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ZYNQ
|
|
|
|
static LinuxRCOutput_ZYNQ rcoutDriver;
|
2014-08-19 00:48:56 -03:00
|
|
|
#else
|
|
|
|
static Empty::EmptyRCOutput rcoutDriver;
|
|
|
|
#endif
|
2014-09-18 10:29:47 -03:00
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
static LinuxScheduler schedulerInstance;
|
|
|
|
static LinuxUtil utilInstance;
|
|
|
|
|
|
|
|
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,
|
2013-09-22 03:01:24 -03:00
|
|
|
&i2cDriver,
|
|
|
|
&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");
|
2014-06-11 03:34:07 -03:00
|
|
|
}
|
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
void HAL_Linux::init(int argc,char* const argv[]) const
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
/*
|
|
|
|
parse command line options
|
|
|
|
*/
|
2015-02-12 06:00:52 -04:00
|
|
|
while ((opt = getopt(argc, argv, "A:B:C:E:h")) != -1) {
|
2013-09-22 03:01:24 -03:00
|
|
|
switch (opt) {
|
|
|
|
case 'A':
|
|
|
|
uartADriver.set_device_path(optarg);
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
uartBDriver.set_device_path(optarg);
|
|
|
|
break;
|
2013-09-28 11:51:43 -03:00
|
|
|
case 'C':
|
|
|
|
uartCDriver.set_device_path(optarg);
|
|
|
|
break;
|
2015-02-12 06:00:52 -04:00
|
|
|
case 'E':
|
|
|
|
uartEDriver.set_device_path(optarg);
|
|
|
|
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();
|
2014-09-18 10:36:55 -03:00
|
|
|
i2c->begin();
|
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);
|
2013-09-28 11:51:43 -03:00
|
|
|
spi->init(NULL);
|
2014-11-26 08:03:06 -04:00
|
|
|
analogin->init(NULL);
|
2014-02-22 17:15:39 -04:00
|
|
|
utilInstance.init(argc, argv);
|
2013-09-22 03:01:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
const HAL_Linux AP_HAL_Linux;
|
|
|
|
|
|
|
|
#endif
|