From f1fc72ef7a1ce490564ae1df10cd76223a3b538e Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 23 Jan 2017 04:09:00 +0300 Subject: [PATCH] Added proper support for ChibiOS 4; added compile-time check that fails if IRQ vectors are not properly defined --- libuavcan_drivers/stm32/driver/src/internal.hpp | 2 +- .../stm32/driver/src/uc_stm32_can.cpp | 16 +++++++++++++++- .../stm32/driver/src/uc_stm32_thread.cpp | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp index eaf61c78b4..d29dae43c2 100644 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ b/libuavcan_drivers/stm32/driver/src/internal.hpp @@ -59,7 +59,7 @@ # ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK # if (CH_KERNEL_MAJOR == 2) # define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_PRIORITY_MASK(CORTEX_MAX_KERNEL_PRIORITY) -# else // ChibiOS 3 +# else // ChibiOS 3+ # define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_MAX_KERNEL_PRIORITY # endif # endif diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 45eafaf65d..241981340f 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -34,7 +34,7 @@ # endif #endif -#if (UAVCAN_STM32_CHIBIOS && CH_KERNEL_MAJOR == 3) +#if (UAVCAN_STM32_CHIBIOS && (CH_KERNEL_MAJOR == 3 || CH_KERNEL_MAJOR == 4)) #define CAN1_TX_IRQHandler STM32_CAN1_TX_HANDLER #define CAN1_RX0_IRQHandler STM32_CAN1_RX0_HANDLER #define CAN1_RX1_IRQHandler STM32_CAN1_RX1_HANDLER @@ -1084,7 +1084,15 @@ static int can2_irq(const int irq, void*) } # endif + #else // UAVCAN_STM32_NUTTX + +#if !defined(CAN1_TX_IRQHandler) ||\ + !defined(CAN1_RX0_IRQHandler) ||\ + !defined(CAN1_RX1_IRQHandler) +# error "Misconfigured build" +#endif + UAVCAN_STM32_IRQ_HANDLER(CAN1_TX_IRQHandler); UAVCAN_STM32_IRQ_HANDLER(CAN1_TX_IRQHandler) { @@ -1111,6 +1119,12 @@ UAVCAN_STM32_IRQ_HANDLER(CAN1_RX1_IRQHandler) # if UAVCAN_STM32_NUM_IFACES > 1 +#if !defined(CAN2_TX_IRQHandler) ||\ + !defined(CAN2_RX0_IRQHandler) ||\ + !defined(CAN2_RX1_IRQHandler) +# error "Misconfigured build" +#endif + UAVCAN_STM32_IRQ_HANDLER(CAN2_TX_IRQHandler); UAVCAN_STM32_IRQ_HANDLER(CAN2_TX_IRQHandler) { diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp index 61d73d4fad..0c91c4e6a1 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp @@ -26,7 +26,7 @@ bool BusEvent::wait(uavcan::MonotonicDuration duration) { # if (CH_KERNEL_MAJOR == 2) ret = sem_.waitTimeout(TIME_IMMEDIATE); -# else // ChibiOS 3 +# else // ChibiOS 3+ ret = sem_.wait(TIME_IMMEDIATE); # endif } @@ -34,13 +34,13 @@ bool BusEvent::wait(uavcan::MonotonicDuration duration) { # if (CH_KERNEL_MAJOR == 2) ret = sem_.waitTimeout((msec > MaxDelayMSec) ? MS2ST(MaxDelayMSec) : MS2ST(msec)); -# else // ChibiOS 3 +# else // ChibiOS 3+ ret = sem_.wait((msec > MaxDelayMSec) ? MS2ST(MaxDelayMSec) : MS2ST(msec)); # endif } # if (CH_KERNEL_MAJOR == 2) return ret == RDY_OK; -# else // ChibiOS 3 +# else // ChibiOS 3+ return ret == MSG_OK; # endif } @@ -56,7 +56,7 @@ void BusEvent::signalFromInterrupt() chSysLockFromIsr(); sem_.signalI(); chSysUnlockFromIsr(); -# else // ChibiOS 3 +# else // ChibiOS 3+ chSysLockFromISR(); sem_.signalI(); chSysUnlockFromISR(); @@ -75,7 +75,7 @@ void Mutex::unlock() { # if (CH_KERNEL_MAJOR == 2) chibios_rt::BaseThread::unlockMutex(); -# else // ChibiOS 3 +# else // ChibiOS 3+ mtx_.unlock(); # endif }