pub struct EthernetPTP { /* private fields */ }
Expand description
Access to the IEEE 1588v2 PTP peripheral present on the ethernet peripheral.
On STM32FXXX’s, the PTP peripheral has/uses the following important parts:
- HCLK (the chip’s high speed clock, configured externally).
- The global timestamp (
global_time
, aTimestamp
). - A subsecond increment register (
subsecond_increment
, aSubseconds
with a value of 0 to 255, seeEthernetPTP::subsecond_increment
). - An accumulator register (
accumulator
, anu32
). - An addend register (
addend
, anu32
, seeEthernetPTP::addend
andEthernetPTP::set_addend
).
To ensure that global_time
advances at the correct rate, the system performs the following steps:
- On every clock of HCLK,
addend
is added toaccumulator
. - If
accumulator
overflows during step 1, addsubsecond_increment
toglobal_time
.
When a new EthernetPTP
is created, it is assumed that the frequency of HCLK is exactly correct.
Using HCLK, values for subsecond_increment
and addend
are calculated so that global_time
represents
real-time.
Subsequently, addend
can be adjusted to compensate for possible errors in HCLK, using EthernetPTP::addend
and EthernetPTP::set_addend
To assess the correctness of the current speed at which global_time
is running, one can use the
following equation:
clock_ratio = ((2^31 / subsecond_increment) / (HCLK_HZ * (addend / 2^32)))
Values greater than 1 indicate that the provided HCLK_HZ
is less than the actual frequency of HCLK, which should
be compensated by increasing addend
. Values less than 1 indicate that the provided HCLK_HZ
is greater than the
actual frequency of HCLK, which should be compensated by decreasing addend
.
Implementations§
Source§impl EthernetPTP
impl EthernetPTP
Sourcepub fn subsecond_increment(&self) -> Subseconds
pub fn subsecond_increment(&self) -> Subseconds
Get the configured subsecond increment.
Sourcepub fn set_addend(&mut self, rate: u32)
pub fn set_addend(&mut self, rate: u32)
Set the PTP clock addend.
Sourcepub fn update_time(&mut self, time: Timestamp)
pub fn update_time(&mut self, time: Timestamp)
Add the provided time to the current time, atomically.
If time
is negative, it will instead be subtracted from the
system time.
Sourcepub fn enable_pps<P>(&mut self, pin: P) -> P::Outputwhere
P: PPSPin,
pub fn enable_pps<P>(&mut self, pin: P) -> P::Outputwhere
P: PPSPin,
Enable the PPS output on the provided pin.
Source§impl EthernetPTP
Setting and configuring target time interrupts on the STM32F107 does not
make any sense: we can generate the interrupt, but it is impossible to
clear the flag as the register required to do so does not exist.
impl EthernetPTP
Setting and configuring target time interrupts on the STM32F107 does not make any sense: we can generate the interrupt, but it is impossible to clear the flag as the register required to do so does not exist.
Sourcepub fn configure_target_time_interrupt(&mut self, timestamp: Timestamp)
pub fn configure_target_time_interrupt(&mut self, timestamp: Timestamp)
Configure the target time interrupt.
You must call EthernetPTP::interrupt_handler
in the ETH
interrupt to detect (and clear) the correct status bits.
Sourcepub async fn wait_until(&mut self, timestamp: Timestamp)
pub async fn wait_until(&mut self, timestamp: Timestamp)
Wait until the specified time.
Sourcepub fn interrupt_handler() -> bool
pub fn interrupt_handler() -> bool
Handle the PTP parts of the ETH
interrupt.
Returns a boolean indicating whether or not the interrupt was caused by a Timestamp trigger and clears the interrupt flag.
Sourcepub fn set_pps_freq(&mut self, pps_freq: u8)
pub fn set_pps_freq(&mut self, pps_freq: u8)
Configure the PPS output frequency.
The PPS output frequency becomes 2 ^ pps_freq
. pps_freq
is
clamped to [0..31]
.