Fixes for no-time.
This commit is contained in:
parent
8d43fb4da4
commit
a9f0c8c3a9
2 changed files with 20 additions and 12 deletions
|
@ -622,17 +622,18 @@ impl Registers {
|
||||||
let id = (stid << 18) | (exid);
|
let id = (stid << 18) | (exid);
|
||||||
embedded_can::ExtendedId::new(id).unwrap().into()
|
embedded_can::ExtendedId::new(id).unwrap().into()
|
||||||
};
|
};
|
||||||
let data_len = fifo.rdtr().read().dlc();
|
let rdtr = fifo.rdtr().read();
|
||||||
|
let data_len = rdtr.dlc();
|
||||||
|
|
||||||
|
#[cfg(not(feature = "time"))]
|
||||||
|
let ts = rdtr.time();
|
||||||
|
|
||||||
let mut data: [u8; 8] = [0; 8];
|
let mut data: [u8; 8] = [0; 8];
|
||||||
data[0..4].copy_from_slice(&fifo.rdlr().read().0.to_ne_bytes());
|
data[0..4].copy_from_slice(&fifo.rdlr().read().0.to_ne_bytes());
|
||||||
data[4..8].copy_from_slice(&fifo.rdhr().read().0.to_ne_bytes());
|
data[4..8].copy_from_slice(&fifo.rdhr().read().0.to_ne_bytes());
|
||||||
|
|
||||||
let frame = Frame::new(Header::new(id, data_len, false), &data).unwrap();
|
let frame = Frame::new(Header::new(id, data_len, false), &data).unwrap();
|
||||||
let envelope = Envelope {
|
let envelope = Envelope { ts, frame };
|
||||||
#[cfg(feature = "time")]
|
|
||||||
ts,
|
|
||||||
frame,
|
|
||||||
};
|
|
||||||
|
|
||||||
rfr.modify(|v| v.set_rfom(true));
|
rfr.modify(|v| v.set_rfom(true));
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,14 @@ use bit_field::BitField;
|
||||||
|
|
||||||
use crate::can::enums::FrameCreateError;
|
use crate::can::enums::FrameCreateError;
|
||||||
|
|
||||||
|
/// Calculate proper timestamp when available.
|
||||||
|
#[cfg(feature = "time")]
|
||||||
|
pub type Timestamp = embassy_time::Instant;
|
||||||
|
|
||||||
|
/// Raw register timestamp
|
||||||
|
#[cfg(not(feature = "time"))]
|
||||||
|
pub type Timestamp = u16;
|
||||||
|
|
||||||
/// CAN Header, without meta data
|
/// CAN Header, without meta data
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
|
@ -264,15 +272,14 @@ impl CanHeader for Frame {
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct Envelope {
|
pub struct Envelope {
|
||||||
/// Reception time.
|
/// Reception time.
|
||||||
#[cfg(feature = "time")]
|
pub ts: Timestamp,
|
||||||
pub ts: embassy_time::Instant,
|
|
||||||
/// The actual CAN frame.
|
/// The actual CAN frame.
|
||||||
pub frame: Frame,
|
pub frame: Frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Envelope {
|
impl Envelope {
|
||||||
/// Convert into a tuple
|
/// Convert into a tuple
|
||||||
pub fn parts(self) -> (Frame, embassy_time::Instant) {
|
pub fn parts(self) -> (Frame, Timestamp) {
|
||||||
(self.frame, self.ts)
|
(self.frame, self.ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,15 +449,15 @@ impl CanHeader for FdFrame {
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct FdEnvelope {
|
pub struct FdEnvelope {
|
||||||
/// Reception time.
|
/// Reception time.
|
||||||
#[cfg(feature = "time")]
|
pub ts: Timestamp,
|
||||||
pub ts: embassy_time::Instant,
|
|
||||||
/// The actual CAN frame.
|
/// The actual CAN frame.
|
||||||
pub frame: FdFrame,
|
pub frame: FdFrame,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FdEnvelope {
|
impl FdEnvelope {
|
||||||
/// Convert into a tuple
|
/// Convert into a tuple
|
||||||
pub fn parts(self) -> (FdFrame, embassy_time::Instant) {
|
pub fn parts(self) -> (FdFrame, Timestamp) {
|
||||||
(self.frame, self.ts)
|
(self.frame, self.ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue