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
#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
*/
+30 -8
View File
@@ -13,11 +13,14 @@
// High-level functionality available by default
#include <uavcan/protocol/data_type_info_provider.hpp>
#include <uavcan/protocol/logger.hpp>
#include <uavcan/protocol/node_status_provider.hpp>
#include <uavcan/protocol/restart_request_server.hpp>
#include <uavcan/protocol/transport_stats_provider.hpp>
#include <uavcan/protocol/network_compat_checker.hpp>
#if !UAVCAN_TINY
# 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)
# 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<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMa
{
goto fail;
}
res = proto_logger_.init();
res = proto_nsp_.startAndPublish();
if (res < 0)
{
goto fail;
}
res = proto_nsp_.startAndPublish();
#if !UAVCAN_TINY
res = proto_logger_.init();
if (res < 0)
{
goto fail;
@@ -207,6 +224,7 @@ int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMa
{
goto fail;
}
#endif
started_ = res >= 0;
return res;
fail:
@@ -214,6 +232,8 @@ fail:
return res;
}
#if !UAVCAN_TINY
template <std::size_t MemPoolSize_, unsigned OutgoingTransferRegistryStaticEntries,
unsigned OutgoingTransferMaxPayloadLen>
int Node<MemPoolSize_, OutgoingTransferRegistryStaticEntries, OutgoingTransferMaxPayloadLen>::
@@ -237,4 +257,6 @@ checkNetworkCompatibility(NetworkCompatibilityCheckResult& result)
return res;
}
#endif
}
@@ -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
}