| 1 | //! Enums shared between CAN controller types. |
| 2 | |
| 3 | /// Bus error |
| 4 | #[derive (Debug)] |
| 5 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 6 | pub enum BusError { |
| 7 | /// Bit stuffing error - more than 5 equal bits |
| 8 | Stuff, |
| 9 | /// Form error - A fixed format part of a received message has wrong format |
| 10 | Form, |
| 11 | /// The message transmitted by the FDCAN was not acknowledged by another node. |
| 12 | Acknowledge, |
| 13 | /// Bit0Error: During the transmission of a message the device wanted to send a dominant level |
| 14 | /// but the monitored bus value was recessive. |
| 15 | BitRecessive, |
| 16 | /// Bit1Error: During the transmission of a message the device wanted to send a recessive level |
| 17 | /// but the monitored bus value was dominant. |
| 18 | BitDominant, |
| 19 | /// The CRC check sum of a received message was incorrect. The CRC of an |
| 20 | /// incoming message does not match with the CRC calculated from the received data. |
| 21 | Crc, |
| 22 | /// A software error occured |
| 23 | Software, |
| 24 | /// The FDCAN is in Bus_Off state. |
| 25 | BusOff, |
| 26 | /// The FDCAN is in the Error_Passive state. |
| 27 | BusPassive, |
| 28 | /// At least one of error counter has reached the Error_Warning limit of 96. |
| 29 | BusWarning, |
| 30 | } |
| 31 | |
| 32 | /// Bus error modes. |
| 33 | /// |
| 34 | /// Contrary to the `BusError` enum which also includes last-seen acute protocol |
| 35 | /// errors, this enum includes only the mutually exclusive bus error modes. |
| 36 | #[derive (Debug)] |
| 37 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 38 | pub enum BusErrorMode { |
| 39 | /// Error active mode (default). Controller will transmit an active error |
| 40 | /// frame upon protocol error. |
| 41 | ErrorActive, |
| 42 | /// Error passive mode. An error counter exceeded 127. Controller will |
| 43 | /// transmit a passive error frame upon protocol error. |
| 44 | ErrorPassive, |
| 45 | /// Bus off mode. The transmit error counter exceeded 255. Controller is not |
| 46 | /// participating in bus traffic. |
| 47 | BusOff, |
| 48 | } |
| 49 | |
| 50 | /// Frame Create Errors |
| 51 | #[derive (Debug)] |
| 52 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 53 | pub enum FrameCreateError { |
| 54 | /// Data in header does not match supplied. |
| 55 | NotEnoughData, |
| 56 | /// Invalid data length not 0-8 for Classic packet or valid for FD. |
| 57 | InvalidDataLength, |
| 58 | /// Invalid ID. |
| 59 | InvalidCanId, |
| 60 | } |
| 61 | |
| 62 | /// Error returned by `try_read` |
| 63 | #[derive (Debug)] |
| 64 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
| 65 | pub enum TryReadError { |
| 66 | /// Bus error |
| 67 | BusError(BusError), |
| 68 | /// Receive buffer is empty |
| 69 | Empty, |
| 70 | } |
| 71 | |