mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 04:33:34 +08:00
STM32: Clock speed PPM limit
This commit is contained in:
@@ -43,6 +43,12 @@ void adjustUtc(uavcan::UtcDuration adjustment);
|
|||||||
*/
|
*/
|
||||||
uavcan::int32_t getUtcSpeedCorrectionPPM();
|
uavcan::int32_t getUtcSpeedCorrectionPPM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets maximum absolute UTC speed correction in ppm.
|
||||||
|
* This function is thread safe.
|
||||||
|
*/
|
||||||
|
void setMaxUtcSpeedCorrectionPPM(uavcan::uint32_t ppm);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of non-gradual adjustments performed so far.
|
* Number of non-gradual adjustments performed so far.
|
||||||
* Ideally should be zero.
|
* Ideally should be zero.
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ uavcan::int32_t utc_correction_usec_per_overflow_x16 = 0;
|
|||||||
uavcan::int64_t prev_adjustment = 0;
|
uavcan::int64_t prev_adjustment = 0;
|
||||||
|
|
||||||
uavcan::UtcDuration min_utc_jump = uavcan::UtcDuration::fromMSec(10);
|
uavcan::UtcDuration min_utc_jump = uavcan::UtcDuration::fromMSec(10);
|
||||||
|
uavcan::int32_t max_utc_speed_correction_x16 = 20 * 16;
|
||||||
|
|
||||||
uavcan::uint64_t time_mono = 0;
|
uavcan::uint64_t time_mono = 0;
|
||||||
uavcan::uint64_t time_utc = 0;
|
uavcan::uint64_t time_utc = 0;
|
||||||
|
|
||||||
const uavcan::uint32_t USecPerOverflow = 65536;
|
const uavcan::uint32_t USecPerOverflow = 65536;
|
||||||
const uavcan::int32_t MaxUtcSpeedCorrectionX16 = 30 * 16;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,8 +158,8 @@ void adjustUtc(uavcan::UtcDuration adjustment)
|
|||||||
utc_correction_usec_per_overflow_x16 += adjustment.isPositive() ? 1 : -1;
|
utc_correction_usec_per_overflow_x16 += adjustment.isPositive() ? 1 : -1;
|
||||||
utc_correction_usec_per_overflow_x16 += (adj_delta > 0) ? 1 : -1;
|
utc_correction_usec_per_overflow_x16 += (adj_delta > 0) ? 1 : -1;
|
||||||
|
|
||||||
utc_correction_usec_per_overflow_x16 = std::max(utc_correction_usec_per_overflow_x16, -MaxUtcSpeedCorrectionX16);
|
utc_correction_usec_per_overflow_x16 = std::max(utc_correction_usec_per_overflow_x16,-max_utc_speed_correction_x16);
|
||||||
utc_correction_usec_per_overflow_x16 = std::min(utc_correction_usec_per_overflow_x16, MaxUtcSpeedCorrectionX16);
|
utc_correction_usec_per_overflow_x16 = std::min(utc_correction_usec_per_overflow_x16, max_utc_speed_correction_x16);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clock value adjustment
|
* Clock value adjustment
|
||||||
@@ -199,6 +199,12 @@ uavcan::int32_t getUtcSpeedCorrectionPPM()
|
|||||||
return uavcan::int64_t((utc_correction_usec_per_overflow_x16 * 1000000) / 16) / USecPerOverflow;
|
return uavcan::int64_t((utc_correction_usec_per_overflow_x16 * 1000000) / 16) / USecPerOverflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMaxUtcSpeedCorrectionPPM(uavcan::uint32_t ppm)
|
||||||
|
{
|
||||||
|
MutexLocker mlocker(mutex);
|
||||||
|
max_utc_speed_correction_x16 = (USecPerOverflow * 16LL * uavcan::int64_t(ppm)) / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
uavcan::uint32_t getUtcAjdustmentJumpCount()
|
uavcan::uint32_t getUtcAjdustmentJumpCount()
|
||||||
{
|
{
|
||||||
MutexLocker mlocker(mutex);
|
MutexLocker mlocker(mutex);
|
||||||
|
|||||||
Reference in New Issue
Block a user