| M480 BSP V3.05.001 The Board Support Package for M480 Series

Macros | Functions
CAN Exported Functions
Standard Driver » CAN Driver

## Macros
#define | CAN_GET_INT_STATUS(can)
| Get interrupt status. More...
#define | CAN_GET_INT_PENDING_STATUS(can)
| Get specified interrupt pending status. More...
#define | CAN_DISABLE_WAKEUP(can)
| Disable wake-up function. More...
#define | CAN_ENABLE_WAKEUP(can)
| Enable wake-up function. More...
#define | CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum)
| Get specified Message Object new data into bit value. More...

## Functions
uint32_t | CAN_SetBaudRate (CAN_T *tCAN, uint32_t u32BaudRate)
| Set bus baud-rate. More...
uint32_t | CAN_Open (CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode)
| Set CAN operation mode and target baud-rate. More...
void | CAN_Close (CAN_T *tCAN)
| The function is used to disable all CAN interrupt. More...
void | CAN_CLR_INT_PENDING_BIT (CAN_T *tCAN, uint8_t u32MsgNum)
| Clear interrupt pending bit. More...
void | CAN_EnableInt (CAN_T *tCAN, uint32_t u32Mask)
| Enable CAN interrupt. More...
void | CAN_DisableInt (CAN_T *tCAN, uint32_t u32Mask)
| Disable CAN interrupt. More...
int32_t | CAN_Transmit (CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
| Send CAN message. More...
int32_t | CAN_Receive (CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
| Gets the message, if received. More...
int32_t | CAN_SetMultiRxMsg (CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID)
| The function is used to configure several receive message objects. More...
int32_t | CAN_SetRxMsg (CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID)
| The function is used to configure a receive message object. More...
int32_t | CAN_SetRxMsgAndMsk (CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID, uint32_t u32IDMask)
| The function is used to configure a receive message object. More...
int32_t | CAN_SetTxMsg (CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
| The function is used to configure a transmit object. More...
int32_t | CAN_TriggerTxMsg (CAN_T *tCAN, uint32_t u32MsgNum)
| Set transmit request bit. More...
int32_t | CAN_BasicSendMsg (CAN_T *tCAN, STR_CANMSG_T *pCanMsg)
| Send CAN message in BASIC mode of test mode. More...
int32_t | CAN_BasicReceiveMsg (CAN_T *tCAN, STR_CANMSG_T *pCanMsg)
| Get a message information in BASIC mode. More...
void | CAN_EnterInitMode (CAN_T *tCAN, uint8_t u8Mask)
| Enter initialization mode. More...
void | CAN_EnterTestMode (CAN_T *tCAN, uint8_t u8TestMask)
| Switch the CAN into test mode. More...
void | CAN_LeaveTestMode (CAN_T *tCAN)
| Leave the test mode. More...
uint32_t | CAN_GetCANBitRate (CAN_T *tCAN)
| Get current bit rate. More...
uint32_t | CAN_IsNewDataReceived (CAN_T *tCAN, uint8_t u8MsgObj)
| Get the waiting status of a received message. More...
void | CAN_LeaveInitMode (CAN_T *tCAN)
| Leave initialization mode. More...
int32_t | CAN_SetRxMsgObjAndMsk (CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint32_t u32idmask, uint8_t u8singleOrFifoLast)
| Set Rx message object, include ID mask. More...
int32_t | CAN_SetRxMsgObj (CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast)
| Set Rx message object. More...
void | CAN_WaitMsg (CAN_T *tCAN)
| Wait message into message buffer in basic mode. More...
int32_t | CAN_ReadMsgObj (CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8Release, STR_CANMSG_T *pCanMsg)
| Gets the message. More...

## Detailed Description

HIDDEN_SYMBOLS

## Macro Definition Documentation

## ◆ CAN_DISABLE_WAKEUP

#define CAN_DISABLE_WAKEUP | ( |  | can | ) |

Disable wake-up function.

Parameters

  [in] | can | The base address of can module.

Returns
  None

The macro is used to disable wake-up function.

Definition at line 122 of file can.h.

## ◆ CAN_ENABLE_WAKEUP

#define CAN_ENABLE_WAKEUP | ( |  | can | ) |

Enable wake-up function.

Parameters

  [in] | can | The base address of can module.

Returns
  None

User can wake-up system when there is a falling edge in the CAN_Rx pin.

Definition at line 134 of file can.h.

## ◆ CAN_GET_INT_PENDING_STATUS

#define CAN_GET_INT_PENDING_STATUS | ( |  | can | ) |

Get specified interrupt pending status.

Parameters

  [in] | can | The base address of can module.

Returns
  The source of the interrupt.

If several interrupts are pending, the CAN Interrupt Register will point to the pending interrupt with the highest priority, disregarding their chronological order.

Definition at line 110 of file can.h.

## ◆ CAN_GET_INT_STATUS

#define CAN_GET_INT_STATUS | ( |  | can | ) |

Get interrupt status.

Parameters

  [in] | can | The base address of can module.

Returns
  CAN module status register value.

Status Interrupt is generated by bits BOff (CAN_STATUS[7]), EWarn (CAN_STATUS[6]), EPass (CAN_STATUS[5]), RxOk (CAN_STATUS[4]), TxOk (CAN_STATUS[3]), and LEC (CAN_STATUS[2:0]).

Definition at line 97 of file can.h.

## ◆ CAN_GET_NEW_DATA_IN_BIT

#define CAN_GET_NEW_DATA_IN_BIT | ( |  | can,
|  |  | u32MsgNum
| ) |  |

Get specified Message Object new data into bit value.

Parameters

  [in] | can | The base address of can module.
  [in] | u32MsgNum | Specified Message Object number, valid value are from 0 to 31.

Returns
  Specified Message Object new data into bit value.

The NewDat bit (CAN_IFn_MCON[15]) of a specific Message Object can be set/reset by the software through the IFn Message Interface Registers or by the Message Handler after reception of a Data Frame or after a successful transmission.

Definition at line 148 of file can.h.

## Function Documentation

## ◆ CAN_BasicReceiveMsg()

int32_t CAN_BasicReceiveMsg | ( | CAN_T * | tCAN,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

Get a message information in BASIC mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | pCanMsg | Pointer to the message structure where received data is copied.

Returns
  FALSE No any message received. TRUE Receive a message success.

Definition at line 470 of file can.c.

## ◆ CAN_BasicSendMsg()

int32_t CAN_BasicSendMsg | ( | CAN_T * | tCAN,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

Send CAN message in BASIC mode of test mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | pCanMsg | Pointer to the message structure containing data to transmit.

Returns
  TRUE: Transmission OK FALSE: Check busy flag of interface 0 is timeout

The function is used to send CAN message in BASIC mode of test mode. Before call the API, the user should be call CAN_EnterTestMode(CAN_TEST_BASIC) and let CAN controller enter basic mode of test mode. Please notice IF1 Registers used as Tx Buffer in basic mode.

Definition at line 385 of file can.c.

## ◆ CAN_Close()

void CAN_Close | ( | CAN_T * | tCAN | ) |

The function is used to disable all CAN interrupt.

Parameters

  [in] | tCAN | The pointer to CAN module base address.

Returns
  None

No Status Change Interrupt and Error Status Interrupt will be generated.

Definition at line 880 of file can.c.

## ◆ CAN_CLR_INT_PENDING_BIT()

void CAN_CLR_INT_PENDING_BIT | ( | CAN_T * | tCAN,
|  | uint8_t | u32MsgNum
| ) |  |

Clear interrupt pending bit.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.

Returns
  None

An interrupt remains pending until the application software has cleared it.

Definition at line 1266 of file can.c.

## ◆ CAN_DisableInt()

void CAN_DisableInt | ( | CAN_T * | tCAN,
|  | uint32_t | u32Mask
| ) |  |

Disable CAN interrupt.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32Mask | Interrupt Mask. (CAN_CON_IE_Msk / CAN_CON_SIE_Msk / CAN_CON_EIE_Msk).

Returns
  None

The interrupt remains active until the Interrupt Register is back to value zero (the cause of the interrupt is reset) or until IE is reset.

Definition at line 1052 of file can.c.

## ◆ CAN_EnableInt()

void CAN_EnableInt | ( | CAN_T * | tCAN,
|  | uint32_t | u32Mask
| ) |  |

Enable CAN interrupt.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32Mask | Interrupt Mask. Valid values are: CAN_CON_IE_Msk Module interrupt enable. CAN_CON_SIE_Msk Status change interrupt enable. CAN_CON_EIE_Msk Error interrupt enable.

Returns
  None

The application software has two possibilities to follow the source of a message interrupt. First, it can follow the IntId in the Interrupt Register and second it can poll the Interrupt Pending Register.

Definition at line 1036 of file can.c.

## ◆ CAN_EnterInitMode()

void CAN_EnterInitMode | ( | CAN_T * | tCAN,
|  | uint8_t | u8Mask
| ) |  |

Enter initialization mode.

HIDDEN_SYMBOLS

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8Mask | Following values can be used. CAN_CON_DAR_Msk Disable automatic retransmission. CAN_CON_EIE_Msk Enable error interrupt. CAN_CON_SIE_Msk Enable status interrupt. CAN_CON_IE_Msk CAN interrupt.

Returns
  None

This function is used to set CAN to enter initialization mode and enable access bit timing register. After bit timing configuration ready, user must call CAN_LeaveInitMode() to leave initialization mode and lock bit timing register to let new configuration take effect.

Definition at line 248 of file can.c.

## ◆ CAN_EnterTestMode()

void CAN_EnterTestMode | ( | CAN_T * | tCAN,
|  | uint8_t | u8TestMask
| ) |  |

Switch the CAN into test mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8TestMask | Specifies the configuration in test modes CAN_TEST_BASIC_Msk Enable basic mode of test mode CAN_TEST_SILENT_Msk Enable silent mode of test mode CAN_TEST_LBACK_Msk Enable Loop Back Mode of test mode CAN_TEST_Tx_Msk Control CAN_TX pin bit field

Returns
  None

Switch the CAN into test mode. There are four test mode (BASIC/SILENT/LOOPBACK/ LOOPBACK combined SILENT/CONTROL_TX_PIN)could be selected. After setting test mode,user must call CAN_LeaveInitMode() to let the setting take effect.

Definition at line 341 of file can.c.

## ◆ CAN_GetCANBitRate()

uint32_t CAN_GetCANBitRate | ( | CAN_T * | tCAN | ) |

Get current bit rate.

Parameters

  [in] | tCAN | The pointer to CAN module base address.

Returns
  Current Bit-Rate (kilo bit per second)

Return current CAN bit rate according to the user bit-timing parameter settings

Definition at line 316 of file can.c.

## ◆ CAN_IsNewDataReceived()

uint32_t CAN_IsNewDataReceived | ( | CAN_T * | tCAN,
|  | uint8_t | u8MsgObj
| ) |  |

Get the waiting status of a received message.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8MsgObj | Specifies the Message object number, from 0 to 31.

Return values

  non-zero | The corresponding message object has a new data bit is set.
  0 | No message object has new data.

This function is used to get the waiting status of a received message.

Definition at line 369 of file can.c.

## ◆ CAN_LeaveInitMode()

void CAN_LeaveInitMode | ( | CAN_T * | tCAN | ) |

Leave initialization mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.

Returns
  None

This function is used to set CAN to leave initialization mode to let bit timing configuration take effect after configuration ready.

Definition at line 261 of file can.c.

## ◆ CAN_LeaveTestMode()

void CAN_LeaveTestMode | ( | CAN_T * | tCAN | ) |

Leave the test mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.

Returns
  None

This function is used to Leave the test mode (switch into normal mode).

Definition at line 354 of file can.c.

## ◆ CAN_Open()

uint32_t CAN_Open | ( | CAN_T * | tCAN,
|  | uint32_t | u32BaudRate,
|  | uint32_t | u32Mode
| ) |  |

Set CAN operation mode and target baud-rate.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32BaudRate | The target CAN baud-rate. The range of u32BaudRate is 1~1000KHz.
  [in] | u32Mode | The CAN operation mode. Valid values are: CAN_NORMAL_MODE Normal operation. CAN_BASIC_MODE Basic mode.

Returns
  u32CurrentBitRate Real baud-rate value.

Set bus timing parameter according current clock and target baud-rate. In Basic mode, IF1 Registers used as Tx Buffer, IF2 Registers used as Rx Buffer.

Definition at line 898 of file can.c.

## ◆ CAN_ReadMsgObj()

int32_t CAN_ReadMsgObj | ( | CAN_T * | tCAN,
|  | uint8_t | u8MsgObj,
|  | uint8_t | u8Release,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

Gets the message.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8MsgObj | Specifies the Message object number, from 0 to 31.
  [in] | u8Release | Specifies the message release indicator. This parameter can be one of the following values: TRUE: the message object is released when getting the data. FALSE:the message object is not released.
  [in] | pCanMsg | Pointer to the message structure where received data is copied.

Return values

  TRUE | Success
  FALSE | No any message received

Gets the message, if received.

Definition at line 671 of file can.c.

## ◆ CAN_Receive()

int32_t CAN_Receive | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

Gets the message, if received.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.
  [in] | pCanMsg | Pointer to the message structure where received data is copied.

Return values

  FALSE | No any message received.
  TRUE | Receive Message success.

The Interface Registers avoid conflict between the CPU accesses to the Message RAM and CAN message reception and transmission by buffering the data to be transferred.

Definition at line 1238 of file can.c.

## ◆ CAN_SetBaudRate()

uint32_t CAN_SetBaudRate | ( | CAN_T * | tCAN,
|  | uint32_t | u32BaudRate
| ) |  |

Set bus baud-rate.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32BaudRate | The target CAN baud-rate. The range of u32BaudRate is 1~1000KHz.

Returns
  u32CurrentBitRate Real baud-rate value.

The function is used to set bus timing parameter according current clock and target baud-rate.

Definition at line 748 of file can.c.

## ◆ CAN_SetMultiRxMsg()

int32_t CAN_SetMultiRxMsg | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | uint32_t | u32MsgCount,
|  | uint32_t | u32IDType,
|  | uint32_t | u32ID
| ) |  |

The function is used to configure several receive message objects.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | The starting MSG RAM number(0 ~ 31).
  [in] | u32MsgCount | the number of MSG RAM of the FIFO.
  [in] | u32IDType | Specifies the identifier type of the frames that will be transmitted. Valid values are: CAN_STD_ID The 11-bit identifier. CAN_EXT_ID The 29-bit identifier.
  [in] | u32ID | Specifies the identifier used for acceptance filtering.

Return values

  FALSE | No useful interface.
  TRUE | Configure receive message objects success.

The Interface Registers avoid conflict between the CPU accesses to the Message RAM and CAN message reception and transmission by buffering the data to be transferred.

Definition at line 1148 of file can.c.

## ◆ CAN_SetRxMsg()

int32_t CAN_SetRxMsg | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | uint32_t | u32IDType,
|  | uint32_t | u32ID
| ) |  |

The function is used to configure a receive message object.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.
  [in] | u32IDType | Specifies the identifier type of the frames that will be transmitted. Valid values are: CAN_STD_ID The 11-bit identifier. CAN_EXT_ID The 29-bit identifier.
  [in] | u32ID | Specifies the identifier used for acceptance filtering.

Return values

  FALSE | No useful interface.
  TRUE | Configure a receive message object success.

If the RxIE bit (CAN_IFn_MCON[10]) is set, the IntPnd bit (CAN_IFn_MCON[13]) will be set when a received Data Frame is accepted and stored in the Message Object.

Definition at line 1074 of file can.c.

## ◆ CAN_SetRxMsgAndMsk()

int32_t CAN_SetRxMsgAndMsk | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | uint32_t | u32IDType,
|  | uint32_t | u32ID,
|  | uint32_t | u32IDMask
| ) |  |

The function is used to configure a receive message object.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.
  [in] | u32IDType | Specifies the identifier type of the frames that will be transmitted. Valid values are: CAN_STD_ID The 11-bit identifier. CAN_EXT_ID The 29-bit identifier.
  [in] | u32ID | Specifies the identifier used for acceptance filtering.
  [in] | u32IDMask | Specifies the identifier mask used for acceptance filtering.

Return values

  FALSE | No useful interface.
  TRUE | Configure a receive message object success.

If the RxIE bit (CAN_IFn_MCON[10]) is set, the IntPnd bit (CAN_IFn_MCON[13]) will be set when a received Data Frame is accepted and stored in the Message Object.

Definition at line 1111 of file can.c.

## ◆ CAN_SetRxMsgObj()

int32_t CAN_SetRxMsgObj | ( | CAN_T * | tCAN,
|  | uint8_t | u8MsgObj,
|  | uint8_t | u8idType,
|  | uint32_t | u32id,
|  | uint8_t | u8singleOrFifoLast
| ) |  |

Set Rx message object.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8MsgObj | Specifies the Message object number, from 0 to 31.
  [in] | u8idType | Specifies the identifier type of the frames that will be transmitted This parameter can be one of the following values: CAN_STD_ID (standard ID, 11-bit) CAN_EXT_ID (extended ID, 29-bit)
  [in] | u32id | Specifies the identifier used for acceptance filtering.
  [in] | u8singleOrFifoLast | Specifies the end-of-buffer indicator. This parameter can be one of the following values: TRUE: for a single receive object or a FIFO receive object that is the last one of the FIFO. FALSE: for a FIFO receive object that is not the last one.

Return values

  TRUE | SUCCESS
  FALSE | No useful interface

The function is used to configure a receive message object.

Definition at line 608 of file can.c.

## ◆ CAN_SetRxMsgObjAndMsk()

int32_t CAN_SetRxMsgObjAndMsk | ( | CAN_T * | tCAN,
|  | uint8_t | u8MsgObj,
|  | uint8_t | u8idType,
|  | uint32_t | u32id,
|  | uint32_t | u32idmask,
|  | uint8_t | u8singleOrFifoLast
| ) |  |

Set Rx message object, include ID mask.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u8MsgObj | Specifies the Message object number, from 0 to 31.
  [in] | u8idType | Specifies the identifier type of the frames that will be transmitted This parameter can be one of the following values: CAN_STD_ID (standard ID, 11-bit) CAN_EXT_ID (extended ID, 29-bit)
  [in] | u32id | Specifies the identifier used for acceptance filtering.
  [in] | u32idmask | Specifies the identifier mask used for acceptance filtering.
  [in] | u8singleOrFifoLast | Specifies the end-of-buffer indicator. This parameter can be one of the following values: TRUE: for a single receive object or a FIFO receive object that is the last one of the FIFO. FALSE: for a FIFO receive object that is not the last one.

Return values

  TRUE | SUCCESS
  FALSE | No useful interface

The function is used to configure a receive message object.

Definition at line 538 of file can.c.

## ◆ CAN_SetTxMsg()

int32_t CAN_SetTxMsg | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

The function is used to configure a transmit object.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.
  [in] | pCanMsg | Pointer to the message structure where received data is copied.

Return values

  FALSE | No useful interface.
  TRUE | Config message object success.

The two sets of interface registers (IF1 and IF2) control the software access to the Message RAM. They buffer the data to be transferred to and from the RAM, avoiding conflicts between software accesses and message reception/transmission.

Definition at line 928 of file can.c.

## ◆ CAN_Transmit()

int32_t CAN_Transmit | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum,
|  | STR_CANMSG_T * | pCanMsg
| ) |  |

Send CAN message.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.
  [in] | pCanMsg | Pointer to the message structure where received data is copied.

Return values

  FALSE | 1. When operation in basic mode: Transmit message time out. When operation in normal mode: No useful interface.
  TRUE | Transmit Message success.

The receive/transmit priority for the Message Objects is attached to the message number. Message Object 1 has the highest priority, while Message Object 32 has the lowest priority.

Definition at line 1199 of file can.c.

## ◆ CAN_TriggerTxMsg()

int32_t CAN_TriggerTxMsg | ( | CAN_T * | tCAN,
|  | uint32_t | u32MsgNum
| ) |  |

Set transmit request bit.

Parameters

  [in] | tCAN | The pointer to CAN module base address.
  [in] | u32MsgNum | Specifies the Message object number, from 0 to 31.

Returns
  TRUE: Start transmit message.

If a transmission is requested by programming bit TxRqst/NewDat (IFn_CMASK[2]), the TxRqst (IFn_MCON[8]) will be ignored.

Definition at line 990 of file can.c.

## ◆ CAN_WaitMsg()

void CAN_WaitMsg | ( | CAN_T * | tCAN | ) |

Wait message into message buffer in basic mode.

Parameters

  [in] | tCAN | The pointer to CAN module base address.

Returns
  None

This function is used to wait message into message buffer in basic mode. Please notice the function is polling NEWDAT bit of MCON register by while loop and it is used in basic mode.

Definition at line 277 of file can.c.