mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 08:31:35 +08:00
STM32 clock driver
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 CAN timestamping.
|
||||
*/
|
||||
uavcan::uint64_t getUtcUSecFromInterrupt();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clock interface for CAN driver.
|
||||
*/
|
||||
class ICanTimestampingClock : public uavcan::ISystemClock
|
||||
{
|
||||
public:
|
||||
virtual uavcan::uint64_t getUtcUSecFromInterrupt() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 ICanTimestampingClock, uavcan::Noncopyable
|
||||
{
|
||||
SystemClock() { }
|
||||
|
||||
public:
|
||||
static SystemClock& instance();
|
||||
|
||||
virtual uavcan::uint64_t getUtcUSecFromInterrupt() const { return clock::getUtcUSecFromInterrupt(); }
|
||||
|
||||
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); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -15,11 +15,11 @@
|
||||
namespace uavcan_stm32
|
||||
{
|
||||
|
||||
#if UAVCAN_STM32_CHIBIOS
|
||||
|
||||
class Event
|
||||
{
|
||||
#if UAVCAN_STM32_CHIBIOS
|
||||
chibios_rt::CounterSemaphore sem_;
|
||||
#endif
|
||||
|
||||
public:
|
||||
Event() : sem_(0) { }
|
||||
@@ -31,6 +31,4 @@ public:
|
||||
void signalFromInterrupt();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan_stm32/can.hpp>
|
||||
#include <uavcan_stm32/thread.hpp>
|
||||
#include <uavcan_stm32/clock.hpp>
|
||||
#include <uavcan_stm32/can.hpp>
|
||||
|
||||
Reference in New Issue
Block a user