diff --git a/libraries/AP_HAL_ChibiOS/CANFDIface.cpp b/libraries/AP_HAL_ChibiOS/CANFDIface.cpp index b87b366193..c3a307ad7f 100644 --- a/libraries/AP_HAL_ChibiOS/CANFDIface.cpp +++ b/libraries/AP_HAL_ChibiOS/CANFDIface.cpp @@ -94,7 +94,7 @@ static_assert(STM32_FDCANCLK <= 80U*1000U*1000U, "FDCAN clock must be max 80MHz" using namespace ChibiOS; -#if HAL_MAX_CAN_PROTOCOL_DRIVERS +#if HAL_MAX_CAN_PROTOCOL_DRIVERS && !defined(HAL_BUILD_AP_PERIPH) #define Debug(fmt, args...) do { AP::can().log_text(AP_CANManager::LOG_DEBUG, "CANFDIface", fmt, ##args); } while (0) #else #define Debug(fmt, args...) @@ -763,7 +763,7 @@ void CANIface::handleTxCompleteInterrupt(const uint64_t timestamp_us) } if (event_handle_ != nullptr) { stats.num_events++; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE evt_src_.signalI(1 << self_index_); #endif } @@ -868,7 +868,7 @@ void CANIface::handleRxInterrupt(uint8_t fifo_index) } if (event_handle_ != nullptr) { stats.num_events++; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE evt_src_.signalI(1 << self_index_); #endif } @@ -936,7 +936,7 @@ uint32_t CANIface::getErrorCount() const stats.tx_timedout; } -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE ChibiOS::EventSource CANIface::evt_src_; bool CANIface::set_event_handle(AP_HAL::EventHandle* handle) { diff --git a/libraries/AP_HAL_ChibiOS/CANFDIface.h b/libraries/AP_HAL_ChibiOS/CANFDIface.h index 0edde8450d..ea94267dc6 100644 --- a/libraries/AP_HAL_ChibiOS/CANFDIface.h +++ b/libraries/AP_HAL_ChibiOS/CANFDIface.h @@ -116,7 +116,7 @@ class ChibiOS::CANIface : public AP_HAL::CANIface bool initialised_; bool had_activity_; AP_HAL::EventHandle* event_handle_; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE static ChibiOS::EventSource evt_src_; #endif const uint8_t self_index_; @@ -216,10 +216,12 @@ public: const AP_HAL::CANFrame* const pending_tx, uint64_t blocking_deadline) override; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE // setup event handle for waiting on events bool set_event_handle(AP_HAL::EventHandle* handle) override; +#endif +#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) // fetch stats text and return the size of the same, // results available via @SYS/can0_stats.txt or @SYS/can1_stats.txt void get_stats(ExpandingString &str) override; diff --git a/libraries/AP_HAL_ChibiOS/CANIface.h b/libraries/AP_HAL_ChibiOS/CANIface.h index 0be1e28daa..5c652af9a3 100644 --- a/libraries/AP_HAL_ChibiOS/CANIface.h +++ b/libraries/AP_HAL_ChibiOS/CANIface.h @@ -109,7 +109,7 @@ class ChibiOS::CANIface : public AP_HAL::CANIface bool irq_init_:1; bool initialised_:1; bool had_activity_:1; -#ifndef HAL_BUILD_AP_PERIPH +#if CH_CFG_USE_EVENTS == TRUE AP_HAL::EventHandle* event_handle_; static ChibiOS::EventSource evt_src_; #endif @@ -217,10 +217,11 @@ public: const AP_HAL::CANFrame* const pending_tx, uint64_t blocking_deadline) override; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE // setup event handle for waiting on events bool set_event_handle(AP_HAL::EventHandle* handle) override; - +#endif +#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) // fetch stats text and return the size of the same, // results available via @SYS/can0_stats.txt or @SYS/can1_stats.txt void get_stats(ExpandingString &str) override; diff --git a/libraries/AP_HAL_ChibiOS/CanIface.cpp b/libraries/AP_HAL_ChibiOS/CanIface.cpp index 6e36c61484..d2bb44ac16 100644 --- a/libraries/AP_HAL_ChibiOS/CanIface.cpp +++ b/libraries/AP_HAL_ChibiOS/CanIface.cpp @@ -509,7 +509,7 @@ void CANIface::handleTxInterrupt(const uint64_t utc_usec) handleTxMailboxInterrupt(2, txok, utc_usec); } -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE if (event_handle_ != nullptr) { PERF_STATS(stats.num_events); evt_src_.signalI(1 << self_index_); @@ -577,7 +577,7 @@ void CANIface::handleRxInterrupt(uint8_t fifo_index, uint64_t timestamp_us) had_activity_ = true; -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE if (event_handle_ != nullptr) { PERF_STATS(stats.num_events); evt_src_.signalI(1 << self_index_); @@ -687,6 +687,9 @@ uint32_t CANIface::getErrorCount() const stats.tx_timedout; } +#endif // #if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) + +#if CH_CFG_USE_EVENTS == TRUE ChibiOS::EventSource CANIface::evt_src_; bool CANIface::set_event_handle(AP_HAL::EventHandle* handle) { @@ -696,7 +699,7 @@ bool CANIface::set_event_handle(AP_HAL::EventHandle* handle) return event_handle_->register_event(1 << self_index_); } -#endif // #if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#endif // #if CH_CFG_USE_EVENTS == TRUE void CANIface::checkAvailable(bool& read, bool& write, const AP_HAL::CANFrame* pending_tx) const { @@ -729,7 +732,7 @@ bool CANIface::select(bool &read, bool &write, return true; } -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) +#if CH_CFG_USE_EVENTS == TRUE // we don't support blocking select in AP_Periph and bootloader while (time < blocking_deadline) { if (event_handle_ == nullptr) { diff --git a/libraries/AP_HAL_ChibiOS/EventSource.cpp b/libraries/AP_HAL_ChibiOS/EventSource.cpp index e530c8245f..203fd535e3 100644 --- a/libraries/AP_HAL_ChibiOS/EventSource.cpp +++ b/libraries/AP_HAL_ChibiOS/EventSource.cpp @@ -1,7 +1,5 @@ #include "EventSource.h" -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) - using namespace ChibiOS; #if CH_CFG_USE_EVENTS == TRUE @@ -33,4 +31,3 @@ void EventSource::signalI(uint32_t evt_mask) chSysUnlockFromISR(); } #endif //#if CH_CFG_USE_EVENTS == TRUE -#endif //#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) \ No newline at end of file diff --git a/libraries/AP_HAL_ChibiOS/EventSource.h b/libraries/AP_HAL_ChibiOS/EventSource.h index ad5de8649d..5990228441 100644 --- a/libraries/AP_HAL_ChibiOS/EventSource.h +++ b/libraries/AP_HAL_ChibiOS/EventSource.h @@ -1,7 +1,6 @@ #pragma once #include -#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD) #include #include #include @@ -25,4 +24,3 @@ public: bool wait(uint64_t duration, AP_HAL::EventHandle* evt_handle) override; }; #endif //#if CH_CFG_USE_EVENTS == TRUE -#endif //#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_BOOTLOADER_BUILD)