modm API documentation

Basic Extended CAN2. More...

#include <modm/platform/can/can_2.hpp>

Inheritance diagram for modm::platform::Can2:
modm::Can modm::PeripheralDriver

Public Types

enum  Mode : uint32_t { Normal = 0, ListenOnly = CAN_BTR_SILM, LoopBack = CAN_BTR_LBKM, ListenOnlyLoopBack = CAN_BTR_SILM | CAN_BTR_LBKM }
 
- Public Types inherited from modm::Can
enum  Mode : uint8_t { Mode::Normal = 0b00, Mode::ListenOnly = 0b01, Mode::LoopBack = 0b10, Mode::ListenOnlyLoopBack = 0b11 }
 Possible modes of the CAN controller. More...
 
enum  BusState : uint8_t { BusState::Connected = 0, BusState::ErrorWarning = 1, BusState::ErrorPassive = 2, Off = 3 }
 

Static Public Member Functions

template<class... Signals>
static void connect (Gpio::InputType inputType=Gpio::InputType::Floating)
 
template<class SystemClock , bitrate_t bitrate = kbps(125), percent_t tolerance = pct(1)>
static bool initialize (uint32_t interruptPriority, Mode startupMode=Mode::Normal, bool overwriteOnOverrun=true)
 
static void setMode (Mode mode)
 
static void setAutomaticRetransmission (bool retransmission)
 
static bool isMessageAvailable ()
 
static bool getMessage (can::Message &message, uint8_t *filter_id=nullptr)
 
static bool isReadyToSend ()
 
static bool sendMessage (const can::Message &message)
 
static uint8_t getReceiveErrorCounter ()
 
static uint8_t getTransmitErrorCounter ()
 
static BusState getBusState ()
 
static void enableStatusChangeInterrupt (uint32_t interruptEnable, uint32_t interruptPriority)
 
- Static Public Member Functions inherited from modm::Can
template<class... Signals>
static void connect ()
 
template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void initialize (Mode startupMode)
 
static bool isMessageAvailable ()
 Returns true if a message can be retrieved by calling getMessage.
 
static bool getMessage (can::Message &message)
 Returns true if a message was copied into the message buffer.
 
static bool isReadyToSend ()
 
static bool sendMessage (const can::Message &message)
 
static uint8_t getReceiveErrorCounter ()
 Get Receive Error Counter.
 
static uint8_t getTransmitErrorCounter ()
 Get Transmit Error Counter.
 
static BusState getBusState ()
 
- Static Public Member Functions inherited from modm::PeripheralDriver
static void initialize ()
 initializes the peripheral, must be called before use.
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
static void setParameter ()
 sets a parameter
 
static void getParameter ()
 returns a parameter
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void acknowledgeInterruptFlag ()
 
template<baudrate_t available, baudrate_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 

Static Public Attributes

static constexpr size_t RxBufferSize = 32
 
static constexpr size_t TxBufferSize = 32
 
- Static Public Attributes inherited from modm::Can
static constexpr size_t RxBufferSize = 16
 Size of the receive buffer.
 
static constexpr size_t TxBufferSize = 16
 Size of the transmit buffer.
 

Detailed Description

Basic Extended CAN2.

The Basic Extended CAN peripheral, named bxCAN, interfaces the CAN network. It supports the CAN protocols version 2.0A and B. It has been designed to manage a high number of incoming messages efficiently with a minimum CPU load.

Filter

For connectivity line devices there are 28 filter banks, i=0 .. 27, in other devices there are 14 filter banks i = 0 ..13.

The 28 filter banks for the connectivity line devices are shared between CAN1 and CAN2.

Configuration

You can set the buffer size using the tx_buffer and rx_buffer parameters.

Author
Fabian Greif fabian.greif@rwth-aachen.de

Member Function Documentation

void modm::platform::Can2::enableStatusChangeInterrupt ( uint32_t  interruptEnable,
uint32_t  interruptPriority 
)
static

Enable the error and status change interrupt.

Can be generated by the following events:

  • Error condition, for more details on error conditions please refer to the CAN Error Status register (CAN_ESR).
  • Wakeup condition, SOF monitored on the CAN Rx signal.
  • Entry into Sleep mode

You need to create you own interrupt handler for this interrupt. The interrupt handler has a fixed name:

MODM_ISR(CAN2_SCE)
{
...
// e.g. Acknowledge interrupt
CAN2->MSR = CAN_MSR_ERRI;
}
Parameters
interruptEnableUpper 24-bit of the CAN_IER register. E.g.:
  • CAN_IER_BOFIE
  • CAN_IER_EPVIE
  • ... See Reference Manual >> bxCAN >> CAN_IER Register
interruptPriorityInterrupt vector priority (0=highest to 15=lowest)
static uint8_t modm::platform::Can2::getReceiveErrorCounter ( )
inlinestatic

Get Receive Error Counter.

In case of an error during reception, this counter is incremented by 1 or by 8 depending on the error condition as defined by the CAN standard. After every successful reception the counter is decremented by 1 or reset to 120 if its value was higher than 128. When the counter value exceeds 127, the CAN controller enters the error passive state.

static uint8_t modm::platform::Can2::getTransmitErrorCounter ( )
inlinestatic

Get Transmit Error Counter.

template<class SystemClock , bitrate_t bitrate = kbps(125), percent_t tolerance = pct(1)>
static bool modm::platform::Can2::initialize ( uint32_t  interruptPriority,
Mode  startupMode = Mode::Normal,
bool  overwriteOnOverrun = true 
)
nodiscardinlinestatic

Enables the clock for the CAN controller and resets all settings

Parameters
bitrateCAN bitrate (defined in driver/connectivity/can/message.hpp)
interruptPriorityInterrupt vector priority (0=highest to 15=lowest)
overwriteOnOverrunOnce a receive FIFO is full the next incoming message will overwrite the previous one if true otherwise the incoming message will be discarded
Warning
Has to called after connect(), but before any other function from this class!
void modm::platform::Can2::setMode ( Mode  mode)
static

The the operating mode.

Default after initialization is the normal mode.


The documentation for this class was generated from the following files: