Struct stm32_eth::ptp::EthernetPTP
source · pub struct EthernetPTP { /* private fields */ }
Expand description
Access to the IEEE 1508v2 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
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 fn interrupt_handler(&mut self) -> bool
pub fn interrupt_handler(&mut self) -> bool
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]
.