diff --git a/libuavcan/include/uavcan/impl_constants.hpp b/libuavcan/include/uavcan/impl_constants.hpp index b82578a170..c429b1f6b1 100644 --- a/libuavcan/include/uavcan/impl_constants.hpp +++ b/libuavcan/include/uavcan/impl_constants.hpp @@ -60,6 +60,15 @@ # define UAVCAN_EXPORT #endif +/** + * Functionality / Code Size trade-off. + * Use code search for UAVCAN_TINY to find what functionality will be disabled. + * This is particularly useful for embedded systems with less than 64kB of ROM. + */ +#ifndef UAVCAN_TINY +# define UAVCAN_TINY 0 +#endif + /** * It might make sense to remove toString() methods for an embedded system */ diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index 92ffba92e6..d40c33eabe 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -13,11 +13,14 @@ // High-level functionality available by default #include -#include #include -#include -#include -#include + +#if !UAVCAN_TINY +# include +# include +# include +# include +#endif #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) # error UAVCAN_CPP_VERSION @@ -44,10 +47,12 @@ class UAVCAN_EXPORT Node : public INode Scheduler scheduler_; DataTypeInfoProvider proto_dtp_; - Logger proto_logger_; NodeStatusProvider proto_nsp_; +#if !UAVCAN_TINY + Logger proto_logger_; RestartRequestServer proto_rrs_; TransportStatsProvider proto_tsp_; +#endif bool started_; @@ -55,7 +60,11 @@ protected: virtual void registerInternalFailure(const char* msg) { UAVCAN_TRACE("Node", "Internal failure: %s", msg); +#if UAVCAN_TINY + (void)msg; +#else (void)getLogger().log(protocol::debug::LogLevel::ERROR, "UAVCAN", msg); +#endif } virtual IMarshalBufferProvider& getMarshalBufferProvider() { return marsh_buf_; } @@ -65,10 +74,12 @@ public: : outgoing_trans_reg_(pool_allocator_) , scheduler_(can_driver, pool_allocator_, system_clock, outgoing_trans_reg_) , proto_dtp_(*this) - , proto_logger_(*this) , proto_nsp_(*this) +#if !UAVCAN_TINY + , proto_logger_(*this) , proto_rrs_(*this) , proto_tsp_(*this) +#endif , started_(false) { } @@ -99,7 +110,9 @@ public: int start(); +#if !UAVCAN_TINY int checkNetworkCompatibility(NetworkCompatibilityCheckResult& result); +#endif /* * Initialization methods @@ -121,6 +134,7 @@ public: NodeStatusProvider& getNodeStatusProvider() { return proto_nsp_; } +#if !UAVCAN_TINY /* * Restart handler */ @@ -167,6 +181,8 @@ public: #endif Logger& getLogger() { return proto_logger_; } + +#endif // UAVCAN_TINY }; // ---------------------------------------------------------------------------- @@ -187,12 +203,13 @@ int Node= 0; return res; fail: @@ -214,6 +232,8 @@ fail: return res; } +#if !UAVCAN_TINY + template int Node:: @@ -237,4 +257,6 @@ checkNetworkCompatibility(NetworkCompatibilityCheckResult& result) return res; } +#endif + } diff --git a/libuavcan/include/uavcan/transport/perf_counter.hpp b/libuavcan/include/uavcan/transport/perf_counter.hpp index 85b2cc56f4..431ab3aaf8 100644 --- a/libuavcan/include/uavcan/transport/perf_counter.hpp +++ b/libuavcan/include/uavcan/transport/perf_counter.hpp @@ -10,6 +10,22 @@ namespace uavcan { +#if UAVCAN_TINY + +class UAVCAN_EXPORT TransferPerfCounter +{ +public: + void addTxTransfer() { } + void addRxTransfer() { } + void addError() { } + void addErrors(unsigned) { } + uint64_t getTxTransferCount() const { return 0; } + uint64_t getRxTransferCount() const { return 0; } + uint64_t getErrorCount() const { return 0; } +}; + +#else + class UAVCAN_EXPORT TransferPerfCounter { uint64_t transfers_tx_; @@ -38,4 +54,6 @@ public: uint64_t getErrorCount() const { return errors_; } }; +#endif + } diff --git a/libuavcan_drivers/stm32/test_stm32f107/Makefile b/libuavcan_drivers/stm32/test_stm32f107/Makefile index ef53576784..eacb69a5fb 100644 --- a/libuavcan_drivers/stm32/test_stm32f107/Makefile +++ b/libuavcan_drivers/stm32/test_stm32f107/Makefile @@ -18,7 +18,8 @@ UDEFS = -DUAVCAN_STM32_CHIBIOS=1 \ -DUAVCAN_STM32_TIMER_NUMBER=6 \ -DUAVCAN_MEM_POOL_BLOCK_SIZE=56 \ -DUAVCAN_TOSTRING=0 \ - -DUAVCAN_EXCEPTIONS=0 + -DUAVCAN_EXCEPTIONS=0 \ + -DUAVCAN_TINY=1 include ../../../libuavcan/include.mk CPPSRC += $(LIBUAVCAN_SRC) diff --git a/libuavcan_drivers/stm32/test_stm32f107/src/main.cpp b/libuavcan_drivers/stm32/test_stm32f107/src/main.cpp index 9dd671eea9..8afbe2f583 100644 --- a/libuavcan_drivers/stm32/test_stm32f107/src/main.cpp +++ b/libuavcan_drivers/stm32/test_stm32f107/src/main.cpp @@ -84,21 +84,25 @@ public: // Calling start() multiple times is OK - only the first successfull call will be effective int res = node.start(); +#if !UAVCAN_TINY uavcan::NetworkCompatibilityCheckResult ncc_result; if (res >= 0) { lowsyslog("Checking network compatibility...\n"); res = node.checkNetworkCompatibility(ncc_result); } +#endif if (res < 0) { lowsyslog("Node initialization failure: %i, will try agin soon\n", res); } +#if !UAVCAN_TINY else if (!ncc_result.isOk()) { lowsyslog("Network conflict with %u, will try again soon\n", ncc_result.conflicting_node.get()); } +#endif else { break; @@ -123,7 +127,6 @@ public: */ lowsyslog("UAVCAN node started\n"); node.setStatusOk(); - node.getLogger().setLevel(uavcan::protocol::debug::LogLevel::INFO); while (true) { const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(5000)); @@ -141,10 +144,13 @@ public: static_cast(can.driver.getIface(0)->getErrorCount()), static_cast(can.driver.getIface(1)->getErrorCount())); +#if !UAVCAN_TINY + node.getLogger().setLevel(uavcan::protocol::debug::LogLevel::INFO); node.logInfo("app", "UTC %* sec, %* corr, %* jumps", uavcan_stm32::clock::getUtc().toMSec() / 1000, uavcan_stm32::clock::getUtcSpeedCorrectionPPM(), uavcan_stm32::clock::getUtcAjdustmentJumpCount()); +#endif } return msg_t(); }