CANEMLIB

Detailed Description

Controller Area Network API.

The Controller Area Network Interface Bus (CAN) implements a multi-master serial bus for connecting microcontrollers and devices, also known as nodes, to communicate with each other in applications without a host computer. CAN is a message-based protocol, designed originally for automotive applications, but meanwhile used also in many other surroundings. The complexity of the node can range from a simple I/O device up to an embedded computer with a CAN interface and sophisticated software. The node may also be a gateway allowing a standard computer to communicate over a USB or Ethernet port to the devices on a CAN network. Devices are connected to the bus through a host processor, a CAN controller, and a CAN transceiver.

#include " em_can.h "
#include " em_cmu.h "
#include " em_gpio.h "
void CAN_sendExample( void )
{
CAN_Reset (CAN_DEVICE);
CAN_Mode_TypeDef mode = canModeInit;
CAN_SetMode (CAN_DEVICE, mode);
GPIO_PinModeSet ($gpioPortX, $X_bit, gpioModeInput , 0);
GPIO_PinModeSet ($gpioPortY, $Y_bit, gpioModePushPull , 0);
CAN_SetRoute (CAN_DEVICE, true , $x, $y);
CAN_SetBitTiming (CAN_DEVICE, 100000, 1, 4, 4, 1);
CAN_SetMode (CAN_DEVICE, mode);
message. msgNum = 1;
message. extended = false ;
message. id = 19;
message. dlc = 8;
uint32_t i;
for (i = 0; i < message. dlc ; ++i) {
message. data [i] = i;
}
CAN_ConfigureMessageObject (CAN_DEVICE, 0, message. msgNum , true , true , false , true );
CAN_SendMessage (CAN_DEVICE, 0, &message, true );
}

Data Structures

struct CAN_Init_TypeDef
struct CAN_MessageObject_TypeDef

Macros

#define CAN_INIT_DEFAULT

Enumerations

enum CAN_ErrorCode_TypeDef {
canErrorNoError = CAN_STATUS_LEC_NONE,
canErrorStuff = CAN_STATUS_LEC_STUFF,
canErrorForm = CAN_STATUS_LEC_FORM,
canErrorAck = CAN_STATUS_LEC_ACK,
canErrorBit1 = CAN_STATUS_LEC_BIT1,
canErrorBit0 = CAN_STATUS_LEC_BIT0,
canErrorCrc = CAN_STATUS_LEC_CRC,
canErrorUnused = CAN_STATUS_LEC_UNUSED
}
enum CAN_Mode_TypeDef {
canModeNormal ,
canModeBasic ,
canModeLoopBack ,
canModeSilentLoopBack ,
canModeSilent
}

Functions

void CAN_AbortSendMessage ( CAN_TypeDef *can, uint8_t interface, uint8_t msgNum, bool wait)
Abort the sending of a message.
void CAN_ConfigureMessageObject ( CAN_TypeDef *can, uint8_t interface, uint8_t msgNum, bool valid, bool tx, bool remoteTransfer, bool endOfBuffer, bool wait)
Configure valid, tx/rx, remoteTransfer for a specific Message Object.
__STATIC_INLINE void CAN_Enable ( CAN_TypeDef *can, bool enable)
Enable the Host Controller to send messages.
uint32_t CAN_GetClockFrequency ( CAN_TypeDef *can)
Get the CAN module frequency.
__STATIC_INLINE uint32_t CAN_GetErrorCount ( CAN_TypeDef *can)
Get the error count.
__STATIC_INLINE CAN_ErrorCode_TypeDef CAN_GetLastErrorCode ( CAN_TypeDef *can)
Get the last error code and clear its register.
__STATIC_INLINE uint32_t CAN_HasNewdata ( CAN_TypeDef *can)
Indicates which messages objects have received new data.
void CAN_Init ( CAN_TypeDef *can, const CAN_Init_TypeDef *init)
Initialize CAN.
__STATIC_INLINE bool CAN_IsEnabled ( CAN_TypeDef *can)
Gives the communication capabilities state.
__STATIC_INLINE void CAN_MessageIntClear ( CAN_TypeDef *can, uint32_t flags)
Clear one or more pending CAN message interrupts.
__STATIC_INLINE void CAN_MessageIntDisable ( CAN_TypeDef *can, uint32_t flags)
Disable CAN message interrupts.
__STATIC_INLINE void CAN_MessageIntEnable ( CAN_TypeDef *can, uint32_t flags)
Enable CAN message interrupts.
__STATIC_INLINE uint32_t CAN_MessageIntGet ( CAN_TypeDef *can)
Get pending CAN message interrupt flags.
__STATIC_INLINE uint32_t CAN_MessageIntGetEnabled ( CAN_TypeDef *can)
Get CAN message interrupt flags that are pending and enabled.
__STATIC_INLINE void CAN_MessageIntSet ( CAN_TypeDef *can, uint32_t flags)
Set one or more CAN message interrupts.
bool CAN_MessageLost ( CAN_TypeDef *can, uint8_t interface, uint8_t msgNum)
Read a Message Object to find if a message was lost ; reset the 'Message Lost' flag.
void CAN_ReadMessage ( CAN_TypeDef *can, uint8_t interface, CAN_MessageObject_TypeDef *message)
Read the data from a Message Object in the RAM and store it in message.
__STATIC_INLINE void CAN_ReadyWait ( CAN_TypeDef *can, uint8_t interface)
Waiting function.
void CAN_Reset ( CAN_TypeDef *can)
Set all the CAN registers to RESETVALUE. Leave the CAN Device disabled.
void CAN_ResetMessages ( CAN_TypeDef *can, uint8_t interface)
Reset all the Message Objects and set their data to 0.
void CAN_SendMessage ( CAN_TypeDef *can, uint8_t interface, const CAN_MessageObject_TypeDef *message, bool wait)
Send the data from the Message Object message.
void CAN_SendRequest ( CAN_TypeDef *can, uint8_t interface, uint8_t msgNum, bool wait)
Send request for writing or reading the RAM of Message Object msgNum.
void CAN_SetBitTiming ( CAN_TypeDef *can, uint32_t bitrate, uint16_t propagationTimeSegment, uint16_t phaseBufferSegment1, uint16_t phaseBufferSegment2, uint16_t synchronisationJumpWidth)
Set the bitrate and its parameters.
void CAN_SetIdAndFilter ( CAN_TypeDef *can, uint8_t interface, bool useMask, const CAN_MessageObject_TypeDef *message, bool wait)
Set the Id and the filter for a specific Message Object.
void CAN_SetMode ( CAN_TypeDef *can, CAN_Mode_TypeDef mode)
Set the CAN operation mode.
void CAN_SetRoute ( CAN_TypeDef *can, bool active, uint16_t pinRxLoc, uint16_t pinTxLoc)
Set the ROUTE registers.
__STATIC_INLINE void CAN_StatusClear ( CAN_TypeDef *can, uint32_t flags)
Clear CAN status.
__STATIC_INLINE uint32_t CAN_StatusGet ( CAN_TypeDef *can)
Get CAN status.
__STATIC_INLINE void CAN_StatusIntClear ( CAN_TypeDef *can, uint32_t flags)
Clear one or more pending CAN status interrupts.
__STATIC_INLINE void CAN_StatusIntDisable ( CAN_TypeDef *can, uint32_t flags)
Disable CAN status interrupts.
__STATIC_INLINE void CAN_StatusIntEnable ( CAN_TypeDef *can, uint32_t flags)
Enable CAN status interrupts.
__STATIC_INLINE uint32_t CAN_StatusIntGet ( CAN_TypeDef *can)
Get pending CAN status interrupt flags.
__STATIC_INLINE uint32_t CAN_StatusIntGetEnabled ( CAN_TypeDef *can)
Get pending and enabled CAN status interrupt flags.
__STATIC_INLINE void CAN_StatusIntSet ( CAN_TypeDef *can, uint32_t flags)
Set one or more CAN status interrupts.
void CAN_WriteData ( CAN_TypeDef *can, uint8_t interface, const CAN_MessageObject_TypeDef *message)
Write the data from message to the MIRx registers.

Macro Definition Documentation

#define CAN_INIT_DEFAULT
Value:
{ \
true, \
true, \
100000, \
1, \
4, \
4, \
1 \
}

Default initialization of CAN_Init_TypeDef . The total duration of a bit with these default parameters is 10 tq (time quantum : tq = brp/fsys, brp being the baudrate prescaler and being set according to the wanted bitrate, fsys beeing the CAN Device frequency).

Definition at line 185 of file em_can.h .

Enumeration Type Documentation

CAN Status codes

Enumerator
canErrorNoError

No error occurred during last CAN bus event.

canErrorStuff

More than 5 equal bits in a sequence have occurred in a part of a received message where this is not allowed.

canErrorForm

A fixed format part of a received frame has the wrong format.

canErrorAck

The message this CAN Core transmitted was not acknowledged by another node.

canErrorBit1

Wrong monitored bus value : dominant when the module wanted to send a recessive.

canErrorBit0

Wrong monitored bus value : recessive when the module intended to send a dominant.

canErrorCrc

CRC check sum incorrect.

canErrorUnused

Unused. No new error since the cpu wrote this value

Definition at line 65 of file em_can.h .

CAN peripheral mode

Enumerator
canModeNormal

CAN peripheral in Normal mode : ready to send and receive messages

canModeBasic

CAN peripheral in Basic mode : no use of the RAM

canModeLoopBack

CAN peripheral in Loopback mode : input from the CAN bus is disregarded and comes from TX instead

canModeSilentLoopBack

CAN peripheral in SilentLoopback mode : input from the CAN bus is disregarded and comes from TX instead ; no output on the CAN bus

canModeSilent

CAN peripheral in Silent mode : no output on the CAN bus. If required to send a dominant bit, it's rerouted internally so that the CAN module monitors it but the CAN bus stays recessive.

Definition at line 95 of file em_can.h .

Function Documentation

void CAN_AbortSendMessage ( CAN_TypeDef * can,
uint8_t interface,
uint8_t msgNum,
bool wait
)

Abort the sending of a message.

Set the TXRQST of the CTRL register to 0. Doesn't touch the data ot the others parameters. The user can reuse CAN_SendMessage() to send the object after using CAN_AbortSendMessage() .

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] msgNum Message number of this Message Object, [1 - 32].
[in] wait If true, wait for the end of the transfer between the MIRx registers and the RAM to exit. If false, exit immediately, the transfer can still be in progress.

Definition at line 733 of file em_can.c .

References _CAN_MIR_CTRL_TXRQST_MASK , CAN_MIR_TypeDef::ARB , CAN_MIR_CMDMASK_ARBACC , CAN_MIR_CMDMASK_WRRD , CAN_ReadyWait() , CAN_SendRequest() , CAN_MIR_TypeDef::CMDMASK , and CAN_TypeDef::MIR .

void CAN_ConfigureMessageObject ( CAN_TypeDef * can,
uint8_t interface,
uint8_t msgNum,
bool valid,
bool tx,
bool remoteTransfer,
bool endOfBuffer,
bool wait
)

Configure valid, tx/rx, remoteTransfer for a specific Message Object.

The Init bit have to be 0 to use this function.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] msgNum Message number of this Message Object, [1 - 32].
[in] valid true if Message Object is valid, false otherwise.
[in] tx true if Message Object is used for transmission, false if used for reception.
[in] remoteTransfer true if Message Object is used for remote transmission, false otherwise.
[in] endOfBuffer true if it is for a single Message Object or the end of a fifo buffer, false if the Message Object is part of a fifo buffer and not the last.
[in] wait If true, wait for the end of the transfer between the MIRx registers and the RAM to exit. If false, exit immediately, the transfer can still be in progress.

Definition at line 505 of file em_can.c .

References _CAN_MIR_ARB_DIR_MASK , _CAN_MIR_ARB_DIR_SHIFT , _CAN_MIR_ARB_MSGVAL_MASK , _CAN_MIR_ARB_MSGVAL_SHIFT , _CAN_MIR_CTRL_EOB_SHIFT , _CAN_MIR_CTRL_RMTEN_SHIFT , _CAN_MIR_CTRL_RXIE_MASK , _CAN_MIR_CTRL_TXIE_MASK , CAN_MIR_TypeDef::ARB , CAN_MIR_CMDMASK_ARBACC , CAN_MIR_CMDMASK_CONTROL , CAN_MIR_CMDMASK_WRRD , CAN_MIR_CMDMASK_WRRD_READ , CAN_ReadyWait() , CAN_SendRequest() , CAN_MIR_TypeDef::CMDMASK , CAN_MIR_TypeDef::CTRL , and CAN_TypeDef::MIR .

__STATIC_INLINE void CAN_Enable ( CAN_TypeDef * can,
bool enable
)

Enable the Host Controller to send messages.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] enable true to enable CAN device, false to disable it. If the CAN device is enabled, it goes in normal mode (the default working mode).

Definition at line 273 of file em_can.h .

References _CAN_CTRL_INIT_SHIFT , BUS_RegBitWrite() , and CAN_TypeDef::CTRL .

Referenced by CAN_Init() , and CAN_Reset() .

uint32_t CAN_GetClockFrequency ( CAN_TypeDef * can )

Get the CAN module frequency.

There is an internal prescaler of 2 inside the CAN module.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
Clock value

Definition at line 133 of file em_can.c .

References CAN0 , CAN1 , CMU_ClockFreqGet() , cmuClock_CAN0 , and cmuClock_CAN1 .

Referenced by CAN_SetBitTiming() .

__STATIC_INLINE uint32_t CAN_GetErrorCount ( CAN_TypeDef * can )

Get the error count.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
Error count.

Definition at line 484 of file em_can.h .

References CAN_TypeDef::ERRCNT .

__STATIC_INLINE CAN_ErrorCode_TypeDef CAN_GetLastErrorCode ( CAN_TypeDef * can )

Get the last error code and clear its register.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
return Last error code.

Definition at line 321 of file em_can.h .

References _CAN_STATUS_LEC_MASK , and CAN_TypeDef::STATUS .

__STATIC_INLINE uint32_t CAN_HasNewdata ( CAN_TypeDef * can )

Indicates which messages objects have received new data.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
State of MESSAGEDATA register indicating which messages objects have received new data.

Definition at line 340 of file em_can.h .

References CAN_TypeDef::MESSAGEDATA .

__STATIC_INLINE bool CAN_IsEnabled ( CAN_TypeDef * can )

Gives the communication capabilities state.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
true if the Host Controller can send messages, false otherwise.

Definition at line 288 of file em_can.h .

References _CAN_CTRL_INIT_MASK , and CAN_TypeDef::CTRL .

Referenced by CAN_SetBitTiming() .

__STATIC_INLINE void CAN_MessageIntClear ( CAN_TypeDef * can,
uint32_t flags
)

Clear one or more pending CAN message interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags Pending CAN message interrupt source(s) to clear.

Definition at line 499 of file em_can.h .

References CAN_TypeDef::IF0IFC .

__STATIC_INLINE void CAN_MessageIntDisable ( CAN_TypeDef * can,
uint32_t flags
)

Disable CAN message interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN message interrupt source(s) to disable.

Definition at line 514 of file em_can.h .

References CAN_TypeDef::IF0IEN .

__STATIC_INLINE void CAN_MessageIntEnable ( CAN_TypeDef * can,
uint32_t flags
)

Enable CAN message interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN message interrupt source(s) to enable.

Definition at line 529 of file em_can.h .

References CAN_TypeDef::IF0IEN .

__STATIC_INLINE uint32_t CAN_MessageIntGet ( CAN_TypeDef * can )

Get pending CAN message interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in] can Pointer to CAN peripheral register block.
Returns
CAN message interrupt source(s) pending.

Definition at line 547 of file em_can.h .

References CAN_TypeDef::IF0IF .

__STATIC_INLINE uint32_t CAN_MessageIntGetEnabled ( CAN_TypeDef * can )

Get CAN message interrupt flags that are pending and enabled.

Note
The event bits are not cleared by the use of this function.
Parameters
[in] can Pointer to CAN peripheral register block.
Returns
CAN message interrupt source(s) pending and enabled.

Definition at line 565 of file em_can.h .

References CAN_TypeDef::IF0IEN , and CAN_TypeDef::IF0IF .

__STATIC_INLINE void CAN_MessageIntSet ( CAN_TypeDef * can,
uint32_t flags
)

Set one or more CAN message interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN message interrupt source(s) to set to pending.

Definition at line 583 of file em_can.h .

References CAN_TypeDef::IF0IFS .

bool CAN_MessageLost ( CAN_TypeDef * can,
uint8_t interface,
uint8_t msgNum
)

Read a Message Object to find if a message was lost ; reset the 'Message Lost' flag.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] msgNum Message number of the Message Object, [1 - 32].
Returns
true if a message was lost, false otherwise.

Definition at line 167 of file em_can.c .

References _CAN_MIR_CTRL_MESSAGEOF_MASK , CAN_MIR_CMDMASK_CLRINTPND , CAN_MIR_CMDMASK_CONTROL , CAN_MIR_CMDMASK_WRRD , CAN_MIR_CMDMASK_WRRD_READ , CAN_ReadyWait() , CAN_SendRequest() , CAN_MIR_TypeDef::CMDMASK , CAN_MIR_TypeDef::CTRL , and CAN_TypeDef::MIR .

void CAN_ReadMessage ( CAN_TypeDef * can,
uint8_t interface,
CAN_MessageObject_TypeDef * message
)

Read the data from a Message Object in the RAM and store it in message.

Read all the information from the RAM on this Message Object : the data but also the configuration of the other registers.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] message Message Object

Definition at line 663 of file em_can.c .

References _CAN_MIR_CTRL_DLC_MASK , _CAN_MIR_CTRL_DLC_SHIFT , CAN_MIR_CMDMASK_ARBACC , CAN_MIR_CMDMASK_CLRINTPND , CAN_MIR_CMDMASK_CONTROL , CAN_MIR_CMDMASK_DATAA , CAN_MIR_CMDMASK_DATAB , CAN_MIR_CMDMASK_MASKACC , CAN_MIR_CMDMASK_TXRQSTNEWDAT , CAN_MIR_CMDMASK_WRRD_READ , CAN_ReadyWait() , CAN_SendRequest() , CAN_MIR_TypeDef::CMDMASK , CAN_MIR_TypeDef::CTRL , CAN_MessageObject_TypeDef::data , CAN_MIR_TypeDef::DATAH , CAN_MIR_TypeDef::DATAL , CAN_MessageObject_TypeDef::dlc , CAN_TypeDef::MIR , CAN_MessageObject_TypeDef::msgNum , and SL_MIN .

__STATIC_INLINE void CAN_ReadyWait ( CAN_TypeDef * can,
uint8_t interface
)

Waiting function.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.

Definition at line 304 of file em_can.h .

References _CAN_MIR_CMDREQ_BUSY_MASK , CAN_MIR_TypeDef::CMDREQ , and CAN_TypeDef::MIR .

Referenced by CAN_AbortSendMessage() , CAN_ConfigureMessageObject() , CAN_MessageLost() , CAN_ReadMessage() , CAN_Reset() , CAN_ResetMessages() , CAN_SendMessage() , CAN_SendRequest() , CAN_SetIdAndFilter() , and CAN_WriteData() .

void CAN_ResetMessages ( CAN_TypeDef * can,
uint8_t interface
)
void CAN_SendMessage ( CAN_TypeDef * can,
uint8_t interface,
const CAN_MessageObject_TypeDef * message,
bool wait
)

Send the data from the Message Object message.

If message is configured as tx and remoteTransfer = 0, calling this function will send the data of this Message Object if its parameters are correct. If message is tx and remoteTransfer = 1, this function will set the data of message to the RAM and exit, the data will be automatically sent after reception of a remote frame. If message is rx and remoteTransfer = 1, this function will send a remote frame to the corresponding id. If message is rx and remoteTransfer = 0, the user shouldn't call this function. It will also send a remote frame.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] message Message Object
[in] wait If true, wait for the end of the transfer between the MIRx registers and the RAM to exit. If false, exit immediately, the transfer can still be in progress.

Definition at line 576 of file em_can.c .

References _CAN_MIR_ARB_DIR_MASK , _CAN_MIR_ARB_DIR_RX , _CAN_MIR_ARB_ID_MASK , _CAN_MIR_ARB_ID_SHIFT , _CAN_MIR_ARB_MSGVAL_SHIFT , _CAN_MIR_ARB_XTD_MASK , _CAN_MIR_CTRL_DLC_MASK , _CAN_MIR_CTRL_RMTEN_MASK , _CAN_STATUS_LEC_MASK , CAN_MIR_TypeDef::ARB , BUS_RegMaskedWrite() , CAN_MIR_ARB_XTD_EXT , CAN_MIR_ARB_XTD_STD , CAN_MIR_CMDMASK_ARBACC , CAN_MIR_CMDMASK_CONTROL , CAN_MIR_CMDMASK_DATAA , CAN_MIR_CMDMASK_DATAB , CAN_MIR_CMDMASK_WRRD , CAN_MIR_CMDMASK_WRRD_READ , CAN_MIR_CTRL_DATAVALID , CAN_MIR_CTRL_TXRQST , CAN_ReadyWait() , CAN_SendRequest() , CAN_WriteData() , CAN_MIR_TypeDef::CMDMASK , CAN_MIR_TypeDef::CTRL , CAN_MessageObject_TypeDef::dlc , CAN_MessageObject_TypeDef::extended , CAN_MessageObject_TypeDef::id , CAN_TypeDef::MIR , CAN_MessageObject_TypeDef::msgNum , and CAN_TypeDef::STATUS .

void CAN_SendRequest ( CAN_TypeDef * can,
uint8_t interface,
uint8_t msgNum,
bool wait
)

Send request for writing or reading the RAM of Message Object msgNum.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] msgNum Message number of the Message Object, [1 - 32].
[in] wait If true, wait for the end of the transfer between the MIRx registers and the RAM to exit. If false, exit immediately, the transfer can still be in progress.

Definition at line 888 of file em_can.c .

References _CAN_MIR_CMDREQ_MSGNUM_SHIFT , CAN_ReadyWait() , CAN_MIR_TypeDef::CMDREQ , and CAN_TypeDef::MIR .

Referenced by CAN_AbortSendMessage() , CAN_ConfigureMessageObject() , CAN_MessageLost() , CAN_ReadMessage() , CAN_ResetMessages() , CAN_SendMessage() , and CAN_SetIdAndFilter() .

void CAN_SetBitTiming ( CAN_TypeDef * can,
uint32_t bitrate,
uint16_t propagationTimeSegment,
uint16_t phaseBufferSegment1,
uint16_t phaseBufferSegment2,
uint16_t synchronisationJumpWidth
)

Set the bitrate and its parameters.

There are multiple parameters which need to be properly configured. Please refer to the reference manual for a detailed description. Careful : the BRP (Baud Rate Prescaler) is calculated by: 'brp = freq / (period * bitrate);'. freq is the frequency of the CAN device, period the time of transmission of a bit. The result is an uint32_t hence it's truncated, causing an approximation error. This error is non negligeable when period is high, bitrate is high and freq is low.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] bitrate Wanted bitrate on the CAN bus.
[in] propagationTimeSegment Value for the Propagation Time Segment.
[in] phaseBufferSegment1 Value for the Phase Buffer Segment 1.
[in] phaseBufferSegment2 Value for the Phase Buffer Segment 2.
[in] synchronisationJumpWidth Value for the Synchronisation Jump Width.

Definition at line 264 of file em_can.c .

References _CAN_BITTIMING_BRP_SHIFT , _CAN_BITTIMING_SJW_SHIFT , _CAN_BITTIMING_TSEG1_SHIFT , _CAN_BITTIMING_TSEG2_SHIFT , _CAN_CTRL_CCE_MASK , _CAN_CTRL_INIT_MASK , CAN_TypeDef::BITTIMING , CAN_TypeDef::BRPE , CAN_CTRL_CCE , CAN_CTRL_INIT , CAN_GetClockFrequency() , CAN_IsEnabled() , and CAN_TypeDef::CTRL .

Referenced by CAN_Init() .

void CAN_SetIdAndFilter ( CAN_TypeDef * can,
uint8_t interface,
bool useMask,
const CAN_MessageObject_TypeDef * message,
bool wait
)

Set the Id and the filter for a specific Message Object.

The Init bit have to be 0 to use this function.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] useMask Boolean to choose whether or not to use the masks.
[in] message Message Object
[in] wait If true, wait for the end of the transfer between the MIRx registers and the RAM to exit. If false, exit immediately, the transfer can still be in progress.

Definition at line 410 of file em_can.c .

References _CAN_MIR_ARB_ID_MASK , _CAN_MIR_ARB_ID_SHIFT , _CAN_MIR_ARB_MSGVAL_SHIFT , _CAN_MIR_CTRL_UMASK_SHIFT , _CAN_MIR_MASK_MASK_SHIFT , _CAN_MIR_MASK_MDIR_SHIFT , _CAN_MIR_MASK_MXTD_SHIFT , CAN_MIR_TypeDef::ARB , BUS_RegBitWrite() , CAN_MIR_ARB_XTD_EXT , CAN_MIR_ARB_XTD_STD , CAN_MIR_CMDMASK_ARBACC , CAN_MIR_CMDMASK_CONTROL , CAN_MIR_CMDMASK_MASKACC , CAN_MIR_CMDMASK_WRRD , CAN_MIR_CMDMASK_WRRD_READ , CAN_ReadyWait() , CAN_SendRequest() , CAN_MIR_TypeDef::CMDMASK , CAN_MIR_TypeDef::CTRL , CAN_MessageObject_TypeDef::directionMask , CAN_MessageObject_TypeDef::extended , CAN_MessageObject_TypeDef::extendedMask , CAN_MessageObject_TypeDef::id , CAN_MIR_TypeDef::MASK , CAN_MessageObject_TypeDef::mask , CAN_TypeDef::MIR , and CAN_MessageObject_TypeDef::msgNum .

void CAN_SetMode ( CAN_TypeDef * can,
CAN_Mode_TypeDef mode
)

Set the CAN operation mode.

In Init mode, the CAN module is deactivated. Reset of the Messages in all the other modes to be sure that there are no leftover data and that they need to be configured before being of use.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] mode Mode of operation : Init, Normal, Loopback, SilentLoopback, Silent, Basic.

Definition at line 336 of file em_can.c .

References _CAN_CTRL_EIE_MASK , _CAN_CTRL_IE_MASK , _CAN_CTRL_SIE_MASK , _CAN_CTRL_TEST_MASK , _CAN_TEST_RESETVALUE , CAN_CTRL_TEST , CAN_TEST_BASIC , CAN_TEST_LBACK , CAN_TEST_SILENT , canModeBasic , canModeLoopBack , canModeNormal , canModeSilent , canModeSilentLoopBack , CAN_TypeDef::CTRL , and CAN_TypeDef::TEST .

void CAN_SetRoute ( CAN_TypeDef * can,
bool active,
uint16_t pinRxLoc,
uint16_t pinTxLoc
)

Set the ROUTE registers.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] active Boolean to activate or not the ROUTE registers.
[in] pinRxLoc Location of the rx pin.
[in] pinTxLoc Location of the tx pin.

Definition at line 217 of file em_can.c .

References _CAN_ROUTE_RXLOC_SHIFT , _CAN_ROUTE_TXLOC_SHIFT , CAN_ROUTE_TXPEN , and CAN_TypeDef::ROUTE .

__STATIC_INLINE void CAN_StatusClear ( CAN_TypeDef * can,
uint32_t flags
)

Clear CAN status.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN status bits to clear.

Definition at line 469 of file em_can.h .

References CAN_TypeDef::STATUS .

__STATIC_INLINE uint32_t CAN_StatusGet ( CAN_TypeDef * can )

Get CAN status.

Parameters
[in] can Pointer to CAN peripheral register block.
Returns
Value of CAN register STATUS.

Definition at line 454 of file em_can.h .

References _CAN_STATUS_LEC_MASK , and CAN_TypeDef::STATUS .

__STATIC_INLINE void CAN_StatusIntClear ( CAN_TypeDef * can,
uint32_t flags
)

Clear one or more pending CAN status interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags Pending CAN status interrupt source(s) to clear.

Definition at line 355 of file em_can.h .

References CAN_TypeDef::IF1IFC .

__STATIC_INLINE void CAN_StatusIntDisable ( CAN_TypeDef * can,
uint32_t flags
)

Disable CAN status interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN status interrupt source(s) to disable.

Definition at line 370 of file em_can.h .

References CAN_TypeDef::IF1IEN .

__STATIC_INLINE void CAN_StatusIntEnable ( CAN_TypeDef * can,
uint32_t flags
)

Enable CAN status interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN status interrupt source(s) to enable.

Definition at line 385 of file em_can.h .

References CAN_TypeDef::IF1IEN .

__STATIC_INLINE uint32_t CAN_StatusIntGet ( CAN_TypeDef * can )

Get pending CAN status interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in] can Pointer to CAN peripheral register block.
Returns
CAN interrupt source(s) pending.

Definition at line 403 of file em_can.h .

References CAN_TypeDef::IF1IF .

__STATIC_INLINE uint32_t CAN_StatusIntGetEnabled ( CAN_TypeDef * can )

Get pending and enabled CAN status interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in] can Pointer to CAN peripheral register block.
Returns
CAN interrupt source(s) pending and enabled.

Definition at line 421 of file em_can.h .

References CAN_TypeDef::IF1IEN , and CAN_TypeDef::IF1IF .

__STATIC_INLINE void CAN_StatusIntSet ( CAN_TypeDef * can,
uint32_t flags
)

Set one or more CAN status interrupts.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] flags CAN status interrupt source(s) to set to pending.

Definition at line 439 of file em_can.h .

References CAN_TypeDef::IF1IFS .

void CAN_WriteData ( CAN_TypeDef * can,
uint8_t interface,
const CAN_MessageObject_TypeDef * message
)

Write the data from message to the MIRx registers.

Parameters
[in] can Pointer to CAN peripheral register block.
[in] interface Indicate which Message Interface Register to use.
[in] message Message Object

Definition at line 847 of file em_can.c .

References CAN_ReadyWait() , CAN_MessageObject_TypeDef::data , CAN_MIR_TypeDef::DATAH , CAN_MIR_TypeDef::DATAL , CAN_MessageObject_TypeDef::dlc , CAN_TypeDef::MIR , and SL_MIN .

Referenced by CAN_SendMessage() .