Struct EthernetPTP

Source
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:

To ensure that global_time advances at the correct rate, the system performs the following steps:

  1. On every clock of HCLK, addend is added to accumulator.
  2. If accumulator overflows during step 1, add subsecond_increment to global_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

Source

pub fn subsecond_increment(&self) -> Subseconds

Get the configured subsecond increment.

Source

pub fn addend(&self) -> u32

Get the currently configured PTP clock addend.

Source

pub fn set_addend(&mut self, rate: u32)

Set the PTP clock addend.

Source

pub fn set_time(&mut self, time: Timestamp)

Set the current time.

Source

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.

Source

pub fn now() -> Timestamp

Get the current time

Source

pub fn get_time() -> Timestamp

Get the current time.

Source

pub fn enable_pps<P>(&mut self, pin: P) -> P::Output
where 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.

Source

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.

Source

pub async fn wait_until(&mut self, timestamp: Timestamp)

Wait until the specified time.

Source

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.

Source

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].

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.