NetBurner 3.5.7
PDF Version
mcanMODM7AE70::mcan_module Class Reference

MCAN Module Class. More...

#include <mcan.h>

Public Member Functions

 mcan_module (Mcan *phw, uint32_t baud)
 Create a MCAN module instance.
 
void init (Mcan *phw, struct mcan_config *config, uint32_t baud)
 Initialize a MCAN module.
 
void send_message (uint32_t id_value, uint8_t *data, uint32_t data_length, OS_SEM *pSem=0)
 Send a MCAN message.
 
bool blocking_send_message (uint32_t id_value, uint8_t *data, uint32_t data_length, uint32_t TimeOut)
 Send a MCAN message and block until sent.
 
int RegisterRxFifo (uint32_t composite_id, OS_FIFO *pFifo, int channel=-1)
 Register a FIFO to receive CAN messages.
 
int RegisterRxFifoMask (uint32_t composite_id, uint32_t mask, OS_FIFO *pFifo, int channel=-1)
 Register a FIFO to receive messages as specified by the address bit mask. A value of 1 = match, a value of 0 = does not match.
 
int RegisterRxFifoRange (uint32_t composite_id_low, uint32_t composite_id_hi, OS_FIFO *pFifo, int channel=-1)
 Register a FIFO to receive messages in the specified numeric range of addresses from low to high.
 
int UnRegisterFifo (int channel)
 Unregister the FIFO for the specified CAN channel.
 
int MultiCanSetRTRMessage (uint32_t id, uint8_t *data, uint8_t len, int channel=-1)
 Enable an auto-reply to a CAN RTR message for the specified CAN ID. The reply message is specified by the data parameter.
 
int MultiCanReplaceRTRMessage (int channel, uint8_t *data, uint8_t len)
 Modifies/updates the response for the RTR message registered wotj MultiCanSetRTRMessage().
 
int MultiCanStopRTRMessage (int channel)
 Unregister the RTR message for the specified channel.
 
uint32_t read_error_count ()
 Read the raw value of the MCAN Error Count Register (MCAN_ECR).
 
uint32_t read_protocol_status ()
 Read the raw value of the MCAN Protocol Status Register (MCAN_PSR).
 
void start ()
 Take the MCAN controller out of initialization mode and place it on the bus.
 
void stop ()
 Halt the MCAN controller and place it in initialization mode.
 

Detailed Description

MCAN Module Class.

Class to control a MCAN modules (peripherals) on the MODM7AE70

Constructor & Destructor Documentation

◆ mcan_module()

mcanMODM7AE70::mcan_module::mcan_module ( Mcan * phw,
uint32_t baud )

Create a MCAN module instance.

Parameters
phwMCAN hardware peripheral, MCAN0 or MCAN 1
baudMCAN baud rate. For example, 500000

Member Function Documentation

◆ blocking_send_message()

bool mcanMODM7AE70::mcan_module::blocking_send_message ( uint32_t id_value,
uint8_t * data,
uint32_t data_length,
uint32_t TimeOut )

Send a MCAN message and block until sent.

Parameters
id_valueCAN ID, 11-bit standard or 29-bit extended
dataPointer to message data
data_lengthLength of data in bytes
TimeOutTime out value in system time ticks. For example, TICKS_PER_SECOND * 1

◆ init()

void mcanMODM7AE70::mcan_module::init ( Mcan * phw,
struct mcan_config * config,
uint32_t baud )

Initialize a MCAN module.

Parameters
phwMCAN hardware peripheral, MCAN0 or MCAN 1
configPointer to a mcan_config object, initialized with appropriate values.
baudMCAN baud rate. For example, 500000

◆ MultiCanReplaceRTRMessage()

int mcanMODM7AE70::mcan_module::MultiCanReplaceRTRMessage ( int channel,
uint8_t * data,
uint8_t len )

Modifies/updates the response for the RTR message registered wotj MultiCanSetRTRMessage().

Returns
The channel number registered for the RTR message.
See also
MultiCanSetRTRMessage(), MultiCanStopRTRMessage()

◆ MultiCanSetRTRMessage()

int mcanMODM7AE70::mcan_module::MultiCanSetRTRMessage ( uint32_t id,
uint8_t * data,
uint8_t len,
int channel = -1 )

Enable an auto-reply to a CAN RTR message for the specified CAN ID. The reply message is specified by the data parameter.

The response message can be modified with MultiCanReplaceRTRMessage().

Parameters
idCAN ID, 11-bit standard or 29-bit extended
dataPointer to message data
lenLength of message
channelOptional CAN channel
Returns
The channel number corresponding to the ID and RTR message.
See also
MultiCanReplaceRTRMessage(), MultiCanStopRTRMessage()

◆ MultiCanStopRTRMessage()

int mcanMODM7AE70::mcan_module::MultiCanStopRTRMessage ( int channel)

Unregister the RTR message for the specified channel.

Parameters
channelCAN channel number
Returns
OS_NO_ERR on success
See also
MultiCanSetRTRMessage(), MultiCanReplaceRTRMessage()

◆ read_error_count()

uint32_t mcanMODM7AE70::mcan_module::read_error_count ( )
inline

Read the raw value of the MCAN Error Count Register (MCAN_ECR).

Bit fields can be extracted with the macros from component/mcan.h:

  • MCAN_ECR_TEC_Msk / MCAN_ECR_TEC_Pos – Transmit Error Counter (bits 7:0)
  • MCAN_ECR_REC_Msk / MCAN_ECR_REC_Pos – Receive Error Counter (bits 14:8)
  • MCAN_ECR_RP – Receive Error Passive flag
  • MCAN_ECR_CEL_Msk / MCAN_ECR_CEL_Pos – CAN Error Logging counter

Note: a non-zero TEC alone does not imply a problem on a healthy bus – a single missed acknowledge will increment it. For state-level decisions, prefer read_protocol_status().

Returns
Raw 32-bit MCAN_ECR register value.
See also
read_protocol_status(), start(), stop()

◆ read_protocol_status()

uint32_t mcanMODM7AE70::mcan_module::read_protocol_status ( )
inline

Read the raw value of the MCAN Protocol Status Register (MCAN_PSR).

Bit fields can be extracted with the macros from component/mcan.h:

  • MCAN_PSR_BO – Bus_Off Status (controller cannot transmit until restarted)
  • MCAN_PSR_EP – Error Passive
  • MCAN_PSR_EW – Error Warning (TEC or REC >= 96)
  • MCAN_PSR_ACT_Msk – Node activity (idle, receiver, transmitter)
Returns
Raw 32-bit MCAN_PSR register value.
See also
read_error_count(), start(), stop()

◆ RegisterRxFifo()

int mcanMODM7AE70::mcan_module::RegisterRxFifo ( uint32_t composite_id,
OS_FIFO * pFifo,
int channel = -1 )

Register a FIFO to receive CAN messages.

Parameters
composite_idCAN ID, 11-bit standard or 29-bit extended
pFifoPointer to OS_FIFO for received data
channelOptional CAN channel
Returns
OS_NO_ERR on success

◆ RegisterRxFifoMask()

int mcanMODM7AE70::mcan_module::RegisterRxFifoMask ( uint32_t composite_id,
uint32_t mask,
OS_FIFO * pFifo,
int channel = -1 )

Register a FIFO to receive messages as specified by the address bit mask. A value of 1 = match, a value of 0 = does not match.

Parameters
composite_idCAN ID, 11-bit standard or 29-bit extended
maskId mask
pFifoPointer to OS_FIFO for received data
channelOptional CAN channel
Returns
OS_NO_ERR on success

◆ RegisterRxFifoRange()

int mcanMODM7AE70::mcan_module::RegisterRxFifoRange ( uint32_t composite_id_low,
uint32_t composite_id_hi,
OS_FIFO * pFifo,
int channel = -1 )

Register a FIFO to receive messages in the specified numeric range of addresses from low to high.

Parameters
composite_id_lowComposite ID low value
composite_id_hiComposite ID high value
pFifoPointer to OS_FIFO for received data
channelOptional CAN channel
Returns
OS_NO_ERR on success

◆ send_message()

void mcanMODM7AE70::mcan_module::send_message ( uint32_t id_value,
uint8_t * data,
uint32_t data_length,
OS_SEM * pSem = 0 )

Send a MCAN message.

Parameters
id_valueCAN ID, 11-bit standard or 29-bit extended
dataPointer to message data
data_lengthLength of data in bytes
pSemOptional pointer to semaphore to post to, default is no post

◆ start()

void mcanMODM7AE70::mcan_module::start ( )

Take the MCAN controller out of initialization mode and place it on the bus.

Clears the CCCR.INIT bit and waits for the controller to leave init mode. Used in tandem with stop() to perform a software reset of the peripheral after a bus-off event or other error condition.

See also
stop(), read_protocol_status()

◆ stop()

void mcanMODM7AE70::mcan_module::stop ( )

Halt the MCAN controller and place it in initialization mode.

Sets the CCCR.INIT bit and waits for the controller to enter init mode. While in this state the peripheral does not transmit or receive on the bus. Pair with start() to recover the controller from a bus-off condition.

See also
start(), read_protocol_status()

◆ UnRegisterFifo()

int mcanMODM7AE70::mcan_module::UnRegisterFifo ( int channel)

Unregister the FIFO for the specified CAN channel.

Parameters
channelCAN channel number
Returns
OS_NO_ERR on success

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