mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 12:43:33 +08:00
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <uavcan/driver/system_clock.hpp>
|
|
|
|
namespace uavcan_stm32
|
|
{
|
|
|
|
namespace clock
|
|
{
|
|
/**
|
|
* Starts the clock.
|
|
* Can be called multiple times, only the first call will be effective.
|
|
*/
|
|
void init();
|
|
|
|
/**
|
|
* For general usage.
|
|
*/
|
|
uavcan::MonotonicTime getMonotonic();
|
|
uavcan::UtcTime getUtc();
|
|
|
|
/**
|
|
* Performs UTC time adjustment.
|
|
* The UTC time will be zero until first adjustment has been performed.
|
|
*/
|
|
void adjustUtc(uavcan::UtcDuration adjustment);
|
|
|
|
/**
|
|
* Clock speed error.
|
|
* Positive if the hardware timer is slower than reference time
|
|
*/
|
|
uavcan::int32_t getUtcSpeedCorrectionPPM();
|
|
|
|
/**
|
|
* Number of non-gradual adjustments performed so far.
|
|
* Ideally should be zero.
|
|
*/
|
|
uavcan::uint32_t getUtcAjdustmentJumpCount();
|
|
|
|
}
|
|
|
|
/**
|
|
* Trivial system clock implementation; can be redefined by the application.
|
|
* Uses a simple 16-bit hardware timer for both UTC and monotonic clocks.
|
|
*/
|
|
class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable
|
|
{
|
|
SystemClock() { }
|
|
|
|
public:
|
|
static SystemClock& instance();
|
|
|
|
virtual uavcan::MonotonicTime getMonotonic() const { return clock::getMonotonic(); }
|
|
virtual uavcan::UtcTime getUtc() const { return clock::getUtc(); }
|
|
virtual void adjustUtc(uavcan::UtcDuration adjustment) { clock::adjustUtc(adjustment); }
|
|
};
|
|
|
|
}
|