mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 03:53:33 +08:00
STM32 driver: Space optimized SystemClock constructor
This commit is contained in:
@@ -59,8 +59,6 @@ class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable
|
|||||||
{
|
{
|
||||||
SystemClock() { }
|
SystemClock() { }
|
||||||
|
|
||||||
static SystemClock self;
|
|
||||||
|
|
||||||
virtual uavcan::MonotonicTime getMonotonic() const { return clock::getMonotonic(); }
|
virtual uavcan::MonotonicTime getMonotonic() const { return clock::getMonotonic(); }
|
||||||
virtual uavcan::UtcTime getUtc() const { return clock::getUtc(); }
|
virtual uavcan::UtcTime getUtc() const { return clock::getUtc(); }
|
||||||
virtual void adjustUtc(uavcan::UtcDuration adjustment) { clock::adjustUtc(adjustment); }
|
virtual void adjustUtc(uavcan::UtcDuration adjustment) { clock::adjustUtc(adjustment); }
|
||||||
|
|||||||
@@ -217,16 +217,24 @@ uavcan::uint32_t getUtcAjdustmentJumpCount()
|
|||||||
|
|
||||||
} // namespace clock
|
} // namespace clock
|
||||||
|
|
||||||
SystemClock SystemClock::self;
|
|
||||||
|
|
||||||
SystemClock& SystemClock::instance()
|
SystemClock& SystemClock::instance()
|
||||||
{
|
{
|
||||||
MutexLocker mlocker(clock::mutex);
|
MutexLocker mlocker(clock::mutex);
|
||||||
|
|
||||||
|
static union SystemClockStorage
|
||||||
|
{
|
||||||
|
uavcan::uint8_t buffer[sizeof(SystemClock)];
|
||||||
|
long long _aligner_1;
|
||||||
|
long double _aligner_2;
|
||||||
|
} storage;
|
||||||
|
SystemClock* const ptr = reinterpret_cast<SystemClock*>(storage.buffer);
|
||||||
|
|
||||||
if (!clock::initialized)
|
if (!clock::initialized)
|
||||||
{
|
{
|
||||||
clock::init();
|
clock::init();
|
||||||
|
new (ptr) SystemClock();
|
||||||
}
|
}
|
||||||
return self;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace uavcan_stm32
|
} // namespace uavcan_stm32
|
||||||
|
|||||||
Reference in New Issue
Block a user