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: u32The achieved bit rate in bit/s.
sample_point: f64Sample point as a fraction of the bit time, 0.0..=1.0.
prescaler: u32The prescaler (BRP) applied to the input clock.
segments: BitSegmentsThe segment values, in time quanta.
Implementations§
Source§impl BitTiming
impl BitTiming
Sourcepub fn calculate(baudrate: u32, clock_hz: u32) -> Result<Self, CanError>
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.
Sourcepub fn calculate_with(
params: BitTimingParams,
baudrate: u32,
) -> Result<Self, CanError>
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.
Sourcepub fn actual_baudrate(&self, clock_hz: u32) -> Result<u32, CanError>
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.
Sourcepub fn btr(&self) -> Option<u16>
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.