mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-02-16 17:02:30 +00:00
Fixes for no-time.
This commit is contained in:
parent
8d43fb4da4
commit
a9f0c8c3a9
@ -622,17 +622,18 @@ impl Registers {
|
||||
let id = (stid << 18) | (exid);
|
||||
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];
|
||||
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());
|
||||
|
||||
let frame = Frame::new(Header::new(id, data_len, false), &data).unwrap();
|
||||
let envelope = Envelope {
|
||||
#[cfg(feature = "time")]
|
||||
ts,
|
||||
frame,
|
||||
};
|
||||
let envelope = Envelope { ts, frame };
|
||||
|
||||
rfr.modify(|v| v.set_rfom(true));
|
||||
|
||||
|
@ -3,6 +3,14 @@ use bit_field::BitField;
|
||||
|
||||
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
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Header {
|
||||
@ -264,15 +272,14 @@ impl CanHeader for Frame {
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct Envelope {
|
||||
/// Reception time.
|
||||
#[cfg(feature = "time")]
|
||||
pub ts: embassy_time::Instant,
|
||||
pub ts: Timestamp,
|
||||
/// The actual CAN frame.
|
||||
pub frame: Frame,
|
||||
}
|
||||
|
||||
impl Envelope {
|
||||
/// Convert into a tuple
|
||||
pub fn parts(self) -> (Frame, embassy_time::Instant) {
|
||||
pub fn parts(self) -> (Frame, Timestamp) {
|
||||
(self.frame, self.ts)
|
||||
}
|
||||
}
|
||||
@ -442,15 +449,15 @@ impl CanHeader for FdFrame {
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct FdEnvelope {
|
||||
/// Reception time.
|
||||
#[cfg(feature = "time")]
|
||||
pub ts: embassy_time::Instant,
|
||||
pub ts: Timestamp,
|
||||
|
||||
/// The actual CAN frame.
|
||||
pub frame: FdFrame,
|
||||
}
|
||||
|
||||
impl FdEnvelope {
|
||||
/// Convert into a tuple
|
||||
pub fn parts(self) -> (FdFrame, embassy_time::Instant) {
|
||||
pub fn parts(self) -> (FdFrame, Timestamp) {
|
||||
(self.frame, self.ts)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user