Skip to main content

BitTiming

Struct BitTiming 

Source
pub struct BitTiming {
    pub baudrate: u32,
    pub sample_point: f64,
    pub prescaler: u32,
    pub segments: BitSegments,
}
Expand description

A solved bit-timing configuration for one baudrate/clock pair.

Fields§

§baudrate: u32

The achieved bit rate in bit/s.

§sample_point: f64

Sample point as a fraction of the bit time, 0.0..=1.0.

§prescaler: u32

The prescaler (BRP) applied to the input clock.

§segments: BitSegments

The segment values, in time quanta.

Implementations§

Source§

impl BitTiming

Source

pub fn calculate(baudrate: u32, clock_hz: u32) -> Result<Self, CanError>

Solves the standard bit-timing algorithm for baudrate driven by clock_hz, using the CiA default sample point.

§Errors

CanError::InvalidTiming for a zero baudrate/clock or when no configuration under the Bosch segment limits can achieve the baudrate.

Source

pub fn calculate_with( params: BitTimingParams, baudrate: u32, ) -> Result<Self, CanError>

Solves the bit-timing algorithm with explicit parameters.

§Errors

CanError::InvalidTiming for a zero baudrate/clock, a sample point outside (0, 1), or no achievable configuration.

Source

pub fn actual_baudrate(&self, clock_hz: u32) -> Result<u32, CanError>

The achieved bit rate implied by the configuration — sanity check that prescaler × baudrate divides the clock exactly.

§Errors

CanError::InvalidTiming when the clock passed here cannot produce an integer number of Tq for this configuration.

Source

pub fn btr(&self) -> Option<u16>

The SJA1000-style BTR register pair, BTR0 << 8 | BTR1: BTR0 = (SJW−1) << 6 | (BRP−1), BTR1 = (PHASE_SEG2−1) | ((PROP_SEG+PHASE_SEG1−1) << 4) with SAM = 0.

None when the prescaler exceeds the 6-bit BTR0 field (BRP > 64) — the segment fields can never overflow under the Bosch limits.

Trait Implementations§

Source§

impl Clone for BitTiming

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BitTiming

Source§

impl Debug for BitTiming

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for BitTiming

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BitTiming

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.