UAVCAN_TINY preprocessor option - STM32 test compiles into 41kB in release mode (-Os, LTO)

This commit is contained in:
Pavel Kirienko
2014-04-12 23:28:32 +04:00
parent bbbcf97cae
commit 627dc5f2d9
5 changed files with 66 additions and 10 deletions
@@ -60,6 +60,15 @@
# define UAVCAN_EXPORT # define UAVCAN_EXPORT
#endif #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 * It might make sense to remove toString() methods for an embedded system
*/ */
+30 -8
View File
@@ -13,11 +13,14 @@
// High-level functionality available by default // High-level functionality available by default
#include <uavcan/protocol/data_type_info_provider.hpp> #include <uavcan/protocol/data_type_info_provider.hpp>
#include <uavcan/protocol/logger.hpp>
#include <uavcan/protocol/node_status_provider.hpp> #include <uavcan/protocol/node_status_provider.hpp>
#include <uavcan/protocol/restart_request_server.hpp>
#include <uavcan/protocol/transport_stats_provider.hpp> #if !UAVCAN_TINY
#include <uavcan/protocol/network_compat_checker.hpp> # include <uavcan/protocol/logger.hpp>
# include <uavcan/protocol/restart_request_server.hpp>
# include <uavcan/protocol/transport_stats_provider.hpp>
# include <uavcan/protocol/network_compat_checker.hpp>
#endif
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
# error UAVCAN_CPP_VERSION # error UAVCAN_CPP_VERSION
@@ -44,10 +47,12 @@ class UAVCAN_EXPORT Node : public INode
Scheduler scheduler_; Scheduler scheduler_;
DataTypeInfoProvider proto_dtp_; DataTypeInfoProvider proto_dtp_;
Logger proto_logger_;
NodeStatusProvider proto_nsp_; NodeStatusProvider proto_nsp_;
#if !UAVCAN_TINY
Logger proto_logger_;
RestartRequestServer proto_rrs_; RestartRequestServer proto_rrs_;
TransportStatsProvider proto_tsp_; TransportStatsProvider proto_tsp_;
#endif
bool started_; bool started_;
@@ -55,7 +60,11 @@ protected:
virtual void registerInternalFailure(const char* msg) virtual void registerInternalFailure(const char* msg)
{ {
UAVCAN_TRACE("Node", "Internal failure: %s", msg); UAVCAN_TRACE("Node", "Internal failure: %s", msg);
#if UAVCAN_TINY
(void)msg;
#else
(void)getLogger().log(protocol::debug::LogLevel::ERROR, "UAVCAN", msg); (void)getLogger().log(protocol::debug::LogLevel::ERROR, "UAVCAN", msg);
#endif
} }
virtual IMarshalBufferProvider& getMarshalBufferProvider() { return marsh_buf_; } virtual IMarshalBufferProvider& getMarshalBufferProvider() { return marsh_buf_; }
@@ -65,10 +74,12 @@ public:
: outgoing_trans_reg_(pool_allocator_) : outgoing_trans_reg_(pool_allocator_)
, scheduler_(can_driver, pool_allocator_, system_clock, outgoing_trans_reg_) , scheduler_(can_driver, pool_allocator_, system_clock, outgoing_trans_reg_)
, proto_dtp_(*this) , proto_dtp_(*this)
, proto_logger_(*this)
, proto_nsp_(*this) , proto_nsp_(*this)
#if !UAVCAN_TINY
, proto_logger_(*this)
, proto_rrs_(*this) , proto_rrs_(*this)
, proto_tsp_(*this) , proto_tsp_(*this)
#endif
, started_(false) , started_(false)
{ } { }
@@ -99,7 +110,9 @@ public:
int start(); int start();
#if !UAVCAN_TINY
int checkNetworkCompatibility(NetworkCompatibilityCheckResult& result); int checkNetworkCompatibility(NetworkCompatibilityCheckResult& result);
#endif
/* /*
* Initialization methods * Initialization methods
@@ -121,6 +134,7 @@ public:
NodeStatusProvider& getNodeStatusProvider() { return proto_nsp_; } NodeStatusProvider& getNodeStatusProvider() { return proto_nsp_; }
#if !UAVCAN_TINY
/* /*
* Restart handler * Restart handler
*/ */
@@ -167,6 +181,8 @@ public:
#endif #endif
Logger& getLogger() { return proto_logger_; } Logger& getLogger() { return proto_logger_; }
#endif // UAVCAN_TINY
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -187,12 +203,13 @@ int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMa
{ {
goto fail; goto fail;
} }
res = proto_logger_.init(); res = proto_nsp_.startAndPublish();
if (res < 0) if (res < 0)
{ {
goto fail; goto fail;
} }
res = proto_nsp_.startAndPublish(); #if !UAVCAN_TINY
res = proto_logger_.init();
if (res < 0) if (res < 0)
{ {
goto fail; goto fail;
@@ -207,6 +224,7 @@ int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMa
{ {
goto fail; goto fail;
} }
#endif
started_ = res >= 0; started_ = res >= 0;
return res; return res;
fail: fail:
@@ -214,6 +232,8 @@ fail:
return res; return res;
} }
#if !UAVCAN_TINY
template <std::size_t MemPoolSize_, unsigned OutgoingTransferRegistryStaticEntries, template <std::size_t MemPoolSize_, unsigned OutgoingTransferRegistryStaticEntries,
unsigned OutgoingTransferMaxPayloadLen> unsigned OutgoingTransferMaxPayloadLen>
int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMaxPayloadLen>:: int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMaxPayloadLen>::
@@ -237,4 +257,6 @@ checkNetworkCompatibility(NetworkCompatibilityCheckResult& result)
return res; return res;
} }
#endif
} }
@@ -10,6 +10,22 @@
namespace uavcan 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 class UAVCAN_EXPORT TransferPerfCounter
{ {
uint64_t transfers_tx_; uint64_t transfers_tx_;
@@ -38,4 +54,6 @@ public:
uint64_t getErrorCount() const { return errors_; } uint64_t getErrorCount() const { return errors_; }
}; };
#endif
} }
@@ -18,7 +18,8 @@ UDEFS = -DUAVCAN_STM32_CHIBIOS=1 \
-DUAVCAN_STM32_TIMER_NUMBER=6 \ -DUAVCAN_STM32_TIMER_NUMBER=6 \
-DUAVCAN_MEM_POOL_BLOCK_SIZE=56 \ -DUAVCAN_MEM_POOL_BLOCK_SIZE=56 \
-DUAVCAN_TOSTRING=0 \ -DUAVCAN_TOSTRING=0 \
-DUAVCAN_EXCEPTIONS=0 -DUAVCAN_EXCEPTIONS=0 \
-DUAVCAN_TINY=1
include ../../../libuavcan/include.mk include ../../../libuavcan/include.mk
CPPSRC += $(LIBUAVCAN_SRC) CPPSRC += $(LIBUAVCAN_SRC)
@@ -84,21 +84,25 @@ public:
// Calling start() multiple times is OK - only the first successfull call will be effective // Calling start() multiple times is OK - only the first successfull call will be effective
int res = node.start(); int res = node.start();
#if !UAVCAN_TINY
uavcan::NetworkCompatibilityCheckResult ncc_result; uavcan::NetworkCompatibilityCheckResult ncc_result;
if (res >= 0) if (res >= 0)
{ {
lowsyslog("Checking network compatibility...\n"); lowsyslog("Checking network compatibility...\n");
res = node.checkNetworkCompatibility(ncc_result); res = node.checkNetworkCompatibility(ncc_result);
} }
#endif
if (res < 0) if (res < 0)
{ {
lowsyslog("Node initialization failure: %i, will try agin soon\n", res); lowsyslog("Node initialization failure: %i, will try agin soon\n", res);
} }
#if !UAVCAN_TINY
else if (!ncc_result.isOk()) else if (!ncc_result.isOk())
{ {
lowsyslog("Network conflict with %u, will try again soon\n", ncc_result.conflicting_node.get()); lowsyslog("Network conflict with %u, will try again soon\n", ncc_result.conflicting_node.get());
} }
#endif
else else
{ {
break; break;
@@ -123,7 +127,6 @@ public:
*/ */
lowsyslog("UAVCAN node started\n"); lowsyslog("UAVCAN node started\n");
node.setStatusOk(); node.setStatusOk();
node.getLogger().setLevel(uavcan::protocol::debug::LogLevel::INFO);
while (true) while (true)
{ {
const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(5000)); const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(5000));
@@ -141,10 +144,13 @@ public:
static_cast<unsigned long>(can.driver.getIface(0)->getErrorCount()), static_cast<unsigned long>(can.driver.getIface(0)->getErrorCount()),
static_cast<unsigned long>(can.driver.getIface(1)->getErrorCount())); static_cast<unsigned long>(can.driver.getIface(1)->getErrorCount()));
#if !UAVCAN_TINY
node.getLogger().setLevel(uavcan::protocol::debug::LogLevel::INFO);
node.logInfo("app", "UTC %* sec, %* corr, %* jumps", node.logInfo("app", "UTC %* sec, %* corr, %* jumps",
uavcan_stm32::clock::getUtc().toMSec() / 1000, uavcan_stm32::clock::getUtc().toMSec() / 1000,
uavcan_stm32::clock::getUtcSpeedCorrectionPPM(), uavcan_stm32::clock::getUtcSpeedCorrectionPPM(),
uavcan_stm32::clock::getUtcAjdustmentJumpCount()); uavcan_stm32::clock::getUtcAjdustmentJumpCount());
#endif
} }
return msg_t(); return msg_t();
} }