From 391affc02dd9ce1c5f3eb9a6cf40a799f61ff2bb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 Jan 2018 18:07:23 +1100 Subject: [PATCH] AP_HAL: support ChibiOS --- libraries/AP_HAL/AP_HAL_Boards.h | 12 +++++ libraries/AP_HAL/GPIO.h | 1 + libraries/AP_HAL/UARTDriver.h | 7 +++ libraries/AP_HAL/Util.cpp | 8 ++- libraries/AP_HAL/board/chibios.h | 86 ++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 libraries/AP_HAL/board/chibios.h diff --git a/libraries/AP_HAL/AP_HAL_Boards.h b/libraries/AP_HAL/AP_HAL_Boards.h index d9f0126676..2104acf39c 100644 --- a/libraries/AP_HAL/AP_HAL_Boards.h +++ b/libraries/AP_HAL/AP_HAL_Boards.h @@ -12,6 +12,7 @@ #define HAL_BOARD_LINUX 7 #define HAL_BOARD_VRBRAIN 8 #define HAL_BOARD_QURT 9 +#define HAL_BOARD_CHIBIOS 10 #define HAL_BOARD_EMPTY 99 /* Default board subtype is -1 */ @@ -57,6 +58,11 @@ #define HAL_BOARD_SUBTYPE_VRCORE_V10 4005 #define HAL_BOARD_SUBTYPE_VRBRAIN_V54 4006 + +/* HAL CHIBIOS sub-types, starting at 5000 */ +#define HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 5000 +#define HAL_BOARD_SUBTYPE_CHIBIOS_FMUV3 5001 + /* InertialSensor driver types */ #define HAL_INS_MPU60XX_SPI 2 #define HAL_INS_MPU60XX_I2C 3 @@ -147,6 +153,8 @@ #include #elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN #include +#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS + #include #else #error "Unknown CONFIG_HAL_BOARD type" #endif @@ -185,3 +193,7 @@ #ifndef HAL_MINIMIZE_FEATURES #define HAL_MINIMIZE_FEATURES 0 #endif + +#ifndef HAL_OS_FATFS_IO +#define HAL_OS_FATFS_IO 0 +#endif diff --git a/libraries/AP_HAL/GPIO.h b/libraries/AP_HAL/GPIO.h index d21721ebfa..c6588ea91e 100644 --- a/libraries/AP_HAL/GPIO.h +++ b/libraries/AP_HAL/GPIO.h @@ -11,6 +11,7 @@ #define HAL_GPIO_INTERRUPT_HIGH 1 #define HAL_GPIO_INTERRUPT_FALLING 2 #define HAL_GPIO_INTERRUPT_RISING 3 +#define HAL_GPIO_INTERRUPT_BOTH 4 class AP_HAL::DigitalSource { public: diff --git a/libraries/AP_HAL/UARTDriver.h b/libraries/AP_HAL/UARTDriver.h index a25e77e8f0..8e93aaf52a 100644 --- a/libraries/AP_HAL/UARTDriver.h +++ b/libraries/AP_HAL/UARTDriver.h @@ -59,4 +59,11 @@ public: */ void printf(const char *s, ...) FMT_PRINTF(2, 3); void vprintf(const char *s, va_list ap); + + /* + wait for at least n bytes of incoming data, with timeout in + milliseconds. Return true if n bytes are available, false if + timeout + */ + virtual bool wait_timeout(uint16_t n, uint32_t timeout_ms) { return false; } }; diff --git a/libraries/AP_HAL/Util.cpp b/libraries/AP_HAL/Util.cpp index cc89f219dd..ecc91d7885 100644 --- a/libraries/AP_HAL/Util.cpp +++ b/libraries/AP_HAL/Util.cpp @@ -1,9 +1,13 @@ #include "AP_HAL.h" #include "Util.h" #include "utility/print_vprintf.h" -#include #if defined(__APPLE__) && defined(__MACH__) #include +#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#include "ch.h" +#include "hal.h" +#else +#include #endif /* Helper class implements AP_HAL::Print so we can use utility/vprintf */ @@ -57,6 +61,8 @@ uint64_t AP_HAL::Util::get_system_clock_ms() const struct timeval ts; gettimeofday(&ts, nullptr); return ((long long)((ts.tv_sec * 1000) + (ts.tv_usec / 1000))); +#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS + return ST2MS(chVTGetSystemTime()); #else struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); diff --git a/libraries/AP_HAL/board/chibios.h b/libraries/AP_HAL/board/chibios.h new file mode 100644 index 0000000000..c063eda6eb --- /dev/null +++ b/libraries/AP_HAL/board/chibios.h @@ -0,0 +1,86 @@ +#pragma once + +#define HAL_BOARD_NAME "ChibiOS" +#define HAL_CPU_CLASS HAL_CPU_CLASS_150 + +#define HAL_GPIO_A_LED_PIN 0 +#define HAL_GPIO_B_LED_PIN 0 +#define HAL_GPIO_C_LED_PIN 0 +#define HAL_GPIO_LED_ON LOW +#define HAL_GPIO_LED_OFF HIGH + +#define HAL_HAVE_BOARD_VOLTAGE 0 +#define HAL_HAVE_SAFETY_SWITCH 0 + +#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 +#define HAL_CHIBIOS_ARCH_F412 1 + +#define HAL_INS_DEFAULT HAL_INS_MPU60XX_I2C +#define HAL_INS_DEFAULT_ROTATION ROTATION_NONE +#define HAL_INS_MPU60x0_I2C_BUS 1 +#define HAL_INS_MPU60x0_I2C_ADDR 0x68 + +#define HAL_GPIO_RADIO_RESET 1 +#define HAL_GPIO_RADIO_IRQ 2 + +#define HAL_RCINPUT_WITH_AP_RADIO 1 +#define STORAGE_FLASH_PAGE 1 +#define HAL_STORAGE_SIZE 8192 +#define HAL_USE_EKF3 + +#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_FMUV3 +#define HAL_CHIBIOS_ARCH_FMUV3 1 + +#define HAL_BARO_MS5611_NAME "ms5611" +#define HAL_BARO_MS5611_SPI_INT_NAME "ms5611_int" +#define HAL_BARO_MS5611_SPI_EXT_NAME "ms5611_ext" + +#define HAL_INS_MPU60x0_NAME "mpu6000" +#define HAL_INS_MPU60x0_EXT_NAME "mpu6000_ext" + +#define HAL_INS_LSM9DS0_G_NAME "lsm9ds0_g" +#define HAL_INS_LSM9DS0_A_NAME "lsm9ds0_am" + +#define HAL_INS_LSM9DS0_EXT_G_NAME "lsm9ds0_ext_g" +#define HAL_INS_LSM9DS0_EXT_A_NAME "lsm9ds0_ext_am" + +#define HAL_INS_MPU9250_NAME "mpu9250" +#define HAL_INS_MPU9250_EXT_NAME "mpu9250_ext" + +#define HAL_INS_MPU6500_NAME "mpu6500" + +#define HAL_INS_ICM20608_NAME "icm20608" +#define HAL_INS_ICM20608_AM_NAME "icm20608-am" +#define HAL_INS_ICM20608_EXT_NAME "icm20608_ext" + +#define HAL_COMPASS_HMC5843_NAME "hmc5843" +#define HAL_COMPASS_LIS3MDL_NAME "lis3mdl" + +#define HAL_BOARD_LOG_DIRECTORY "/APM/LOGS" + +#define STORAGE_FLASH_PAGE 22 +#define HAL_STORAGE_SIZE 16384 + +// enable access to IO microcontroller +#define HAL_WITH_IO_MCU 1 + +// enable RAMTROM parameter storage +#define HAL_WITH_RAMTRON 1 + +// pixhawk2 cube has an IMU header +#define HAL_HAVE_IMU_HEATER 1 + +// enable FAT filesystem +#define HAL_OS_FATFS_IO 1 + +#endif // CONFIG_HAL_BOARD_SUBTYPE + +#define HAL_STORAGE_SIZE_AVAILABLE HAL_STORAGE_SIZE + +#ifndef HAL_WITH_IO_MCU +#define HAL_WITH_IO_MCU 0 +#endif + +#ifndef HAL_WITH_RAMTRON +#define HAL_WITH_RAMTRON 0 +#endif