From 1c73f4884c27843074ead81b92703b0e6697236f Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 15 Apr 2014 23:11:55 +0400 Subject: [PATCH] LPC11C24 iface activity LED support --- .../lpc11c24/driver/include/uavcan_lpc11c24/can.hpp | 2 ++ libuavcan_drivers/lpc11c24/driver/src/can.cpp | 12 ++++++++++++ .../lpc11c24/test_olimex_lpc_p11c24/src/main.cpp | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp b/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp index bd3579d2bf..2ece3f9959 100644 --- a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp +++ b/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp @@ -26,6 +26,8 @@ public: bool hasPendingRx() const; bool hasEmptyTx() const; + bool hadActivity(); + virtual uavcan::int16_t send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags); diff --git a/libuavcan_drivers/lpc11c24/driver/src/can.cpp b/libuavcan_drivers/lpc11c24/driver/src/can.cpp index 67d96d6704..95861ba4e0 100644 --- a/libuavcan_drivers/lpc11c24/driver/src/can.cpp +++ b/libuavcan_drivers/lpc11c24/driver/src/can.cpp @@ -52,6 +52,8 @@ uint32_t tx_msgobj_free_mask = (1 << NumTxMsgObjects) - 1; */ uint64_t last_irq_utc_timestamp = 0; +bool had_activity; + /** * After a received message gets extracted from C_CAN, it will be stored in the RX queue until libuavcan * reads it via select()/receive() calls. @@ -216,6 +218,14 @@ bool CanDriver::hasEmptyTx() const return tx_msgobj_free_mask != 0; } +bool CanDriver::hadActivity() +{ + CriticalSectionLocker locker; + const bool ret = had_activity; + had_activity = false; + return ret; +} + uavcan::int16_t CanDriver::send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags) { @@ -353,11 +363,13 @@ void canRxCallback(uint8_t msg_obj_num) std::copy(msg_obj.data, msg_obj.data + msg_obj.dlc, frame.data); uavcan_lpc11c24::rx_queue.push(frame, uavcan_lpc11c24::last_irq_utc_timestamp); + uavcan_lpc11c24::had_activity = true; } void canTxCallback(uint8_t msg_obj_num) { uavcan_lpc11c24::tx_msgobj_free_mask |= 1U << (msg_obj_num - 1); + uavcan_lpc11c24::had_activity = true; } void canErrorCallback(uint32_t error_info) diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp index 28d24863f6..716ffb8718 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp @@ -32,7 +32,8 @@ int main() } prev_mono = ts_mono; - board::setErrorLed(uavcan_lpc11c24::CanDriver::instance().getErrorCount() > 0); + board::setErrorLed(uavcan_lpc11c24::CanDriver::instance().getErrorCount() > 0 || + uavcan_lpc11c24::CanDriver::instance().hadActivity()); if (uavcan_lpc11c24::CanDriver::instance().hasPendingRx()) {