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 }
 
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 void acknowledgeInterruptFlag ()
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
template<class... Signals>
static void connect ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static bool getMessage (can::Message &message)
 Returns true if a message was copied into the message buffer.
 
static void getParameter ()
 returns a parameter
 
template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void initialize (Mode startupMode)
 
static void initialize ()
 initializes the peripheral, must be called before use.
 
static void setParameter ()
 sets a parameter
 

Static Public Attributes

static constexpr size_t RxBufferSize = 32
 
static constexpr size_t TxBufferSize = 32
 

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 Enumeration Documentation

enum modm::Can::BusState : uint8_t
inheritedstrong
Enum ValuesDocumentation
Connected 

This bit is set by hardware when the warning limit has been reached (Receive Error Counter or Transmit Error Counter ≥ 96).

ErrorWarning 

This bit is set by hardware when the Error Passive limit has been reached (Receive Error Counter or Transmit Error Counter > 127).

ErrorPassive 

This bit is set by hardware when it enters the bus-off state. The bus-off state is entered on TEC overflow, greater than 255

Member Function Documentation

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

template<class... Signals>
static void modm::Can::connect ( )
inheritedstatic

Configures the Tx and Rx signals and connects them.

Template Parameters
SignalsOne Tx and one Rx signal are required and can be passed out-of-order.
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 = 125_kbps, percent_t tolerance = 1_pct>
static void modm::Can::initialize ( Mode  startupMode)
inheritedstatic

Initializes the hardware and sets the baudrate.

Template Parameters
SystemClockthe currently active system clock
bitratethe desired bitrate in Hz
tolerancethe allowed relative tolerance for the resulting baudrate
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: