25#include <interfaces-impl/arch_registers_impl.h>
47 static constexpr unsigned int RX_BUF_SIZE = 10;
48 static constexpr unsigned int TX_STATUS_BUF_SIZE = 10;
51 static constexpr float BR_ERR_WEIGHT = 10;
52 static constexpr float SP_ERR_WEIGHT = 1;
53 static constexpr float N_ERR_WEIGHT = 1 / 50;
55 static constexpr uint8_t NUM_FILTER_BANKS = 28;
205 static BitTiming calcBitTiming(AutoBitTiming config);
208 IRQCircularBuffer<CanRXPacket, RX_BUF_SIZE> bufRxPackets;
211 IRQCircularBuffer<CanTXResult, TX_STATUS_BUF_SIZE> bufTxResult;
216 uint32_t txMailboxSeq[3] = {0};
218 uint8_t isInit =
false;
219 uint8_t filterIndex = 0;
220 Thread* waiting =
nullptr;
Low level CanBus driver, with support for both peripherals (CAN1 and CAN2) on stm32f4 microcontroller...
uint32_t send(CanPacket packet)
Sends a packet on the bus. This function blocks until the message has been successfully put into a TX...
CanbusDriver(CAN_TypeDef *can, CanbusConfig config, AutoBitTiming bitTiming)
Construct a new Canbus object, automatically calculating timing register values from high level requi...
void handleRXInterrupt(int fifo)
Handles an incoming RX interrupt. ONLY to be called from the Canbus RX interrupt handler routine.
IRQCircularBuffer< CanTXResult, TX_STATUS_BUF_SIZE > & getTXResultBuffer()
Returns a reference to the buffer containing transfer results and statistics.
IRQCircularBuffer< CanRXPacket, RX_BUF_SIZE > & getRXBuffer()
Returns a reference to the buffer containing received packets.
bool addFilter(FilterBank filter)
Adds a new filter to the bus, or returns false if there are no more filter banks available.
~CanbusDriver()
Disables the peripheral clock.
void init()
Exits initialization mode and starts CanBus operation.
uint32_t getTXMailboxSequence(uint8_t i)
Gets the sequence number of the message in the ith tx mailbox.
void wakeTXThread()
Wakes the transmission thread. ONLY to be called from the Canbus TX interrupt handler routine.
CAN_TypeDef * getCAN()
Returns the CanBus peripheral assigned to this instance.
This file includes all the types the logdecoder script will decode.
Struct defining high level bit timing requirements. Register values will then be calculated automatic...
uint32_t baudRate
Canbus baud rate in bps (BITS PER SECOND). CANOpen standard values are preferred but not mandatory: 1...
float samplePoint
Sample point in percentage of the bit length. Eg: 0.875.
Struct specifying exact bit timing registers values.
Configuration struct for basic CanBus operation.
Base class for a Canbus filter bank.