mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
UAVCAN_TINY preprocessor option - STM32 test compiles into 41kB in release mode (-Os, LTO)
This commit is contained in:
parent
bbbcf97cae
commit
627dc5f2d9
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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<unsigned long>(can.driver.getIface(0)->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",
|
||||
uavcan_stm32::clock::getUtc().toMSec() / 1000,
|
||||
uavcan_stm32::clock::getUtcSpeedCorrectionPPM(),
|
||||
uavcan_stm32::clock::getUtcAjdustmentJumpCount());
|
||||
#endif
|
||||
}
|
||||
return msg_t();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user