aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/can/enums.rs
blob: c5900cadcffad14b79f9e133afae17637dc7ce08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Enums shared between CAN controller types.

/// Bus error
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BusError {
    /// Bit stuffing error - more than 5 equal bits
    Stuff,
    /// Form error - A fixed format part of a received message has wrong format
    Form,
    /// The message transmitted by the FDCAN was not acknowledged by another node.
    Acknowledge,
    /// Bit0Error: During the transmission of a message the device wanted to send a dominant level
    /// but the monitored bus value was recessive.
    BitRecessive,
    /// Bit1Error: During the transmission of a message the device wanted to send a recessive level
    /// but the monitored bus value was dominant.
    BitDominant,
    /// The CRC check sum of a received message was incorrect. The CRC of an
    /// incoming message does not match with the CRC calculated from the received data.
    Crc,
    /// A software error occured
    Software,
    ///  The FDCAN is in Bus_Off state.
    BusOff,
    ///  The FDCAN is in the Error_Passive state.
    BusPassive,
    ///  At least one of error counter has reached the Error_Warning limit of 96.
    BusWarning,
}

/// Bus error modes.
///
/// Contrary to the `BusError` enum which also includes last-seen acute protocol
/// errors, this enum includes only the mutually exclusive bus error modes.
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BusErrorMode {
    /// Error active mode (default). Controller will transmit an active error
    /// frame upon protocol error.
    ErrorActive,
    /// Error passive mode. An error counter exceeded 127. Controller will
    /// transmit a passive error frame upon protocol error.
    ErrorPassive,
    /// Bus off mode. The transmit error counter exceeded 255. Controller is not
    /// participating in bus traffic.
    BusOff,
}

/// Frame Create Errors
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FrameCreateError {
    /// Data in header does not match supplied.
    NotEnoughData,
    /// Invalid data length not 0-8 for Classic packet or valid for FD.
    InvalidDataLength,
    /// Invalid ID.
    InvalidCanId,
}

/// Error returned by `try_read`
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TryReadError {
    /// Bus error
    BusError(BusError),
    /// Receive buffer is empty
    Empty,
}

/// Internal Operation
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum RefCountOp {
    /// Notify receiver created
    NotifyReceiverCreated,
    /// Notify receiver destroyed
    NotifyReceiverDestroyed,
    /// Notify sender created
    NotifySenderCreated,
    /// Notify sender destroyed
    NotifySenderDestroyed,
}

/// Error returned when calculating the can timing fails
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TimingCalcError {
    /// Bitrate is lower than 1000
    BitrateTooLow {
        /// The set bitrate
        bitrate: u32,
    },
    /// No solution possible
    NoSolution {
        /// The sum of BS1 and BS2
        bs1_bs2_sum: u8,
    },
    /// Prescaler is not 1 < prescaler < 1024
    InvalidPrescaler {
        /// The calculated prescaler value
        prescaler: u32,
    },
    /// BS1 or BS2 are not in the range 0 < BSx < BSx_MAX
    BSNotInRange {
        /// The value of BS1
        bs1: u8,
        /// The value of BS2
        bs2: u8,
    },
    /// Final bitrate doesn't match the requested bitrate
    NoMatch {
        /// The requested bitrate
        requested: u32,
        /// The calculated bitrate
        final_calculated: u32,
    },
    /// core::num::NonZeroUxx::new error
    CoreNumNew,
}