MSP432E4 DriverLib API Guide  1.11.00.03
Data Structures | Macros | Enumerations | Functions
Can_api

Data Structures

struct  tCANMsgObject
 
struct  tCANBitClkParms
 

Macros

#define CAN_MAX_11BIT_MSG_ID   0x7ff
 
#define CAN_MAX_BIT_DIVISOR   19
 
#define CAN_MIN_BIT_DIVISOR   4
 
#define CAN_MAX_PRE_DIVISOR   1024
 
#define CAN_MIN_PRE_DIVISOR   1
 
#define CAN_BIT_VALUE(seg1, seg2, sjw)
 
#define MSG_OBJ_TX_INT_ENABLE   0x00000001
 This indicates that transmit interrupts are enabled. More...
 
#define MSG_OBJ_RX_INT_ENABLE   0x00000002
 This indicates that receive interrupts are enabled. More...
 
#define MSG_OBJ_EXTENDED_ID   0x00000004
 This indicates that a message object is using an extended identifier. More...
 
#define MSG_OBJ_USE_ID_FILTER   0x00000008
 
#define MSG_OBJ_NEW_DATA   0x00000080
 This indicates that new data was available in the message object. More...
 
#define MSG_OBJ_DATA_LOST   0x00000100
 
#define MSG_OBJ_USE_DIR_FILTER   (0x00000010 | MSG_OBJ_USE_ID_FILTER)
 
#define MSG_OBJ_USE_EXT_FILTER   (0x00000020 | MSG_OBJ_USE_ID_FILTER)
 
#define MSG_OBJ_REMOTE_FRAME   0x00000040
 This indicates that a message object is a remote frame. More...
 
#define MSG_OBJ_FIFO   0x00000200
 
#define MSG_OBJ_NO_FLAGS   0x00000000
 This indicates that a message object has no flags set. More...
 
#define MSG_OBJ_STATUS_MASK   (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
 
#define CAN_INT_ERROR   0x00000008
 
#define CAN_INT_STATUS   0x00000004
 
#define CAN_INT_MASTER   0x00000002
 
#define CAN_STATUS_BUS_OFF   0x00000080
 CAN controller has entered a Bus Off state. More...
 
#define CAN_STATUS_EWARN   0x00000040
 CAN controller error level has reached warning level. More...
 
#define CAN_STATUS_EPASS   0x00000020
 CAN controller error level has reached error passive level. More...
 
#define CAN_STATUS_RXOK   0x00000010
 A message was received successfully since the last read of this status. More...
 
#define CAN_STATUS_TXOK   0x00000008
 
#define CAN_STATUS_LEC_MSK   0x00000007
 This is the mask for the last error code field. More...
 
#define CAN_STATUS_LEC_NONE   0x00000000
 There was no error. More...
 
#define CAN_STATUS_LEC_STUFF   0x00000001
 A bit stuffing error has occurred. More...
 
#define CAN_STATUS_LEC_FORM   0x00000002
 A formatting error has occurred. More...
 
#define CAN_STATUS_LEC_ACK   0x00000003
 An acknowledge error has occurred. More...
 
#define CAN_STATUS_LEC_BIT1   0x00000004
 The bus remained a bit level of 1 for longer than is allowed. More...
 
#define CAN_STATUS_LEC_BIT0   0x00000005
 The bus remained a bit level of 0 for longer than is allowed. More...
 
#define CAN_STATUS_LEC_CRC   0x00000006
 A CRC error has occurred. More...
 
#define CAN_STATUS_LEC_MASK   0x00000007
 This is the mask for the CAN Last Error Code (LEC). More...
 

Enumerations

enum  tCANIntStsReg { CAN_INT_STS_CAUSE, CAN_INT_STS_OBJECT }
 
enum  tCANStsReg { CAN_STS_CONTROL, CAN_STS_TXREQUEST, CAN_STS_NEWDAT, CAN_STS_MSGVAL }
 
enum  tMsgObjType {
  MSG_OBJ_TYPE_TX, MSG_OBJ_TYPE_TX_REMOTE, MSG_OBJ_TYPE_RX, MSG_OBJ_TYPE_RX_REMOTE,
  MSG_OBJ_TYPE_RXTX_REMOTE
}
 

Functions

void CANInit (uint32_t ui32Base)
 
void CANEnable (uint32_t ui32Base)
 
void CANDisable (uint32_t ui32Base)
 
void CANBitTimingGet (uint32_t ui32Base, tCANBitClkParms *psClkParms)
 
uint32_t CANBitRateSet (uint32_t ui32Base, uint32_t ui32SourceClock, uint32_t ui32BitRate)
 
void CANBitTimingSet (uint32_t ui32Base, tCANBitClkParms *psClkParms)
 
void CANIntRegister (uint32_t ui32Base, void(*pfnHandler)(void))
 
void CANIntUnregister (uint32_t ui32Base)
 
void CANIntEnable (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void CANIntDisable (uint32_t ui32Base, uint32_t ui32IntFlags)
 
uint32_t CANIntStatus (uint32_t ui32Base, tCANIntStsReg eIntStsReg)
 
void CANIntClear (uint32_t ui32Base, uint32_t ui32IntClr)
 
void CANRetrySet (uint32_t ui32Base, bool bAutoRetry)
 
bool CANRetryGet (uint32_t ui32Base)
 
uint32_t CANStatusGet (uint32_t ui32Base, tCANStsReg eStatusReg)
 
bool CANErrCntrGet (uint32_t ui32Base, uint32_t *pui32RxCount, uint32_t *pui32TxCount)
 
void CANMessageSet (uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, tMsgObjType eMsgType)
 
void CANMessageGet (uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, bool bClrPendingInt)
 
void CANMessageClear (uint32_t ui32Base, uint32_t ui32ObjID)
 

Detailed Description

Introduction

The Controller Area Network (CAN) APIs provide a set of functions for accessing the MSP432E4 CAN modules. Functions are provided to configure the CAN controllers, configure message objects, and manage CAN interrupts.

The MSP432E4 CAN module provides hardware processing of the CAN data link layer. It can be configured with message filters and preloaded message data so that it can autonomously send and receive messages on the bus and notify the application accordingly. It automatically handles generation and checking of CRCs, error processing, and retransmission of CAN messages.

The message objects are stored in the CAN controller and provide the main interface for the CAN module on the CAN bus. There are 32 message objects that can each be programmed to handle a separate message ID, or can be chained together for a sequence of frames with the same ID. The message identifier filters provide masking that can be programmed to match any or all of the message ID bits, and frame types.

API Functions

The CAN APIs provide all of the functions needed by the application to implement an interrupt-driven CAN stack. These functions may be used to control any of the available CAN ports on a MSP432E4 microcontroller, and can be used with one port without causing conflicts with the other port.

The CAN module is disabled by default, so the CANInit() function must be called before any other CAN functions are called. This call initializes the message objects to a safe state prior to enabling the controller on the CAN bus. Also, the bit timing values must be programmed prior to enabling the CAN controller. The CANSetBitTiming() function should be called with the appropriate bit timing values for the CAN bus. Once these two functions have been called, a CAN controller can be enabled using CANEnable() and later disabled using CANDisable() if needed. Calling CANDisable() does not reinitialize a CAN controller, so it can be used to temporarily remove a CAN controller from the bus.

The CAN controller is highly configurable and can be programmed to automatically transmit and receive CAN messages under certain conditions. Message objects allow the application to perform some actions automatically without interaction from the microcontroller. Some examples of these actions are the following:

To configure message objects to perform any of these actions, the application must first set up one of the 32 message objects using CANMessageSet(). This function must be used to configure a message object to send data, or to configure a message object to receive data. Each message object can be configured to generate interrupts on transmission or reception of CAN messages.

When data is received from the CAN bus, the application can use the CANMessageGet() function to read the received message. This function can also be used to read a message object that is already configured in order to populate a message structure prior to making changes to the configuration of a message object. Reading the message object using this function also clears any pending interrupt on the message object.

Once a message object has been configured using CANMessageSet(), the message object has been allocated and continues to perform its programmed function unless it is released by a call to CANMessageClear(). The application is not required to clear out a message object before setting it with a new configuration, because each time CANMessageSet() is called, it overwrites any previously programmed configuration.

The 32 message objects are identical except for priority. The lowest numbered message objects have the highest priority. Priority affects operation in two ways. First, if multiple actions are ready at the same time, the one with the highest priority message object occurs first. And second, when multiple message objects have interrupts pending, the highest priority is presented first when reading the interrupt status. It is up to the application to manage the 32 message objects as a resource, and determine the best method for allocating and releasing them.

The CAN controller can generate interrupts on several conditions:

An interrupt handler must be installed in order to process CAN interrupts. If dynamic interrupt configuration is desired, the CANIntRegister() can be used to register the interrupt handler. This function places the vector in a RAM-based vector table. However, if the application uses a pre-loaded vector table in flash, then the CAN controller handler should be entered in the appropriate slot in the vector table. In this case, CANIntRegister() is not needed, but the interrupt must be enabled on the host processor master interrupt controller using the IntEnable() function. The CAN module interrupts are enabled using the CANIntEnable() function. They can be disabled by using the CANIntDisable() function.

Once CAN interrupts are enabled, the handler is invoked whenever a CAN interrupt is triggered. The handler can determine which condition caused the interrupt by using the CANIntStatus() function. Multiple conditions can be pending when an interrupt occurs, so the handler must be designed to process all pending interrupt conditions before exiting. Each interrupt condition must be cleared before exiting the handler. There are two ways to do this. The CANIntClear() function clears a specific interrupt condition without further action required by the handler. However, the handler can also clear the condition by performing certain actions. If the interrupt is a status interrupt, the interrupt can be cleared by reading the status register with CANStatusGet(). If the interrupt is caused by one of the message objects, then it can be cleared by reading the message object using CANMessageGet().

There are several status registers that can be used to help the application manage the controller. The status registers are read using the CANStatusGet() function. There is a controller status register that provides general status information such as error or warning conditions. There are also several status registers that provide information about all of the message objects at once using a 32-bit bit map of the status, with one bit representing each message object. These status registers can be used to determine:

Bus error conditions when using CAN require special handling by the application, especially in cases where the CAN controller has gone into a bus-off condition. The CAN specification requires that a controller that has seen its error counters go above 256 transmit errors removes itself from the bus and enters a bus-off state. This state is indicated when the CANStatusGet() function returns the value CAN_STATUS_BUS_OFF. There are other warning levels (CAN_STATUS_EWARN and CAN_STATUS_EPASS) that occur before a bus-off condition that indicate something is wrong on the CAN bus. After entering the bus-off condition, the CAN controller automatically disables itself just as if the application had called CANDisable(). To exit the bus-off condition, the application must call CANEnable() and then wait for the CAN_STATUS_BUS_OFF condition to clear. If the bus-off condition does not clear, then there is likely some physical condition or bit timing issue causing the controller to be unable to function properly. There is no way to shorten this sequence as this is the method for recovering from a bus-off condition specified in the CAN 2.0 specification.

Example:

{
//
// Enable the controller again to allow it to start decrementing the
// error counter allowing the bus off condition to clear.
//
//
// Wait for the bus off condition to clear. This condition can be
// polled elsewhere depending on the application. But no CAN messages
// can be sent until this condition clears.
//
while(CANStatusGet(CAN0_BASE) & CAN_STATUS_BUS_OFF)
{
}
}

CAN Message Objects

This section explains how to configure the CAN message objects in various modes using the CANMessageSet() and CANMessageGet() APIs. The configuration of a message object is determined by two parameters that are passed into the CANMessageSet() API. These are the tCANMsgObject structure and the tMsgObjType type field. It is important to note that the ulObjID parameter is the index of one of the 32 message objects that are available and is not the message object's identifier.

Message objects can be defined as one of five types based on the needs of the application. They are defined in the tMsgObjType enumeration and can only be one of those values. The simplest of the message object types are MSG_OBJ_TYPE_TX and MSG_OBJ_TYPE_RX which are used to send or receive messages for a given message identifier or a range of identifiers. The message type MSG_OBJ_TYPE_TX_REMOTE is used to transmit a remote request for data from another CAN node on the network. These message objects do not transmit any data but once they send the request, they automatically turn into receive message object and wait for data from a remote CAN device. The message type MSG_OBJ_TYPE_RX_REMOTE is the receiving end of a remote request, and receives remote requests for data and generates an interrupt to let the application know when to supply and transmit data back to the CAN controller that issued the remote request for data. The message type MSG_OBJ_TYPE_RXTX_REMOTE is similar to the MSG_OBJ_TYPE_RX_REMOTE except that it automatically responds with data that the application placed in the message object.

The remaining information used to configure a CAN message object is contained in the tCANMsgObject structure which is used when calling CANMessageSet() or is filled by data read from the message object when calling CANMessageGet(). The CAN message identifier is simply stored into the ulMsgID member of the tCANMsgObject structure and is the 11- or 20-bit CAN identifier for this message object. The ulMsgIDMask is the mask that is used in combination with the ulMsgID value to determine a match when the MSG_OBJ_USE_ID_FILTER flag is set for a message object. The ulMsgIDMask is ignored if MSG_OBJ_USE_ID_FILTER flag is not set. The last of the configuration parameters are specified in the ulFlags which are defined as a combination of the MSG_OBJ_* values. The MSG_OBJ_TX_INT_ENABLE and MSG_OBJ_RX_INT_ENABLE flags enable transmit complete or receive data interrupts. If the CAN network is only using extended (20-bit) identifiers, then the MSG_OBJ_EXTENDED_ID flag should be specified. The CANMessageSet() function forces this flag to be set if the length of the identifier is greater than an 11-bit identifier can hold. The MSG_OBJ_USE_ID_FILTER is used to enable filtering based on the message identifiers as message are seen by the CAN controller. The combination of ulMsgID and ulMsgIDMask determines if a message is accepted for a given message object. In some cases it may be necessary to add a filter based on the direction of the message, so in these cases, the MSG_OBJ_USE_DIR_FILTER is used to only accept the direction specified in the message type. Another additional filter flag is MSG_OBJ_USE_EXT_FILTER which filters on only extended identifiers. In a mixed 11-bit and 20-bit identifier system, this parameter prevents an 11-bit identifier from being confused with a 20-bit identifier of the same value. It is not necessary to specify this parameter if there are only extended identifiers being used in the system. To determine if the incoming message identifier matches a given message object, the incoming message identifier is ANDed with ulMsgIDMask and compared with ulMsgID. The "C" logic would be the following:

if((IncomingID & ulMsgIDMask) == ulMsgID)
{
// Accept the message.
}
else
{
// Ignore the message.
}

The last of the flags to affect CANMessageSet() is the MSG_OBJ_FIFO flag. This flag is used when combining multiple message objects in a FIFO. This flag is useful when an application must receive more than the 8 bytes of data that can be received by a single CAN message object. It can also be used to reduce the likelihood of causing an overrun of data on a single message object that may be receiving data faster than the application can handle when using a single message object. If multiple message objects are going to be used in a FIFO, they must be read in sequential order based on the message object number and have the exact same message identifiers and filtering values. All but the last of the message objects in a FIFO should have the MSG_OBJ_FIFO flag set and the last message object in the FIFO should not have the MSG_OBJ_FIFO flag set, indicating that it is the last entry in the FIFO. See the CAN FIFO configuration example in the Programming Examples section of this document.

The remaining flags are all used when calling CANMessageGet() when reading data or checking the status of a message object. If the MSG_OBJ_NEW_DATA flag is set in the tCANMsgObject ulFlags variable then the data returned was new and not stale data from a previous call to CANMessageGet(). If the MSG_OBJ_DATA_LOST flag is set, then data was lost since this message object was last read with CANMessageGet(). The MSG_OBJ_REMOTE_FRAME flag is set if the message object was configured as a remote message object and a remote request was received.

When sending or receiving data, the last two variables define the size and a pointer to the data used by CANMessageGet() and CANMessageSet(). The ulMsgLen variable in tCANMsgObject specifies the number of bytes to send when calling CANMessageSet() and the number of bytes to read when calling CANMessageGet(). The pucMsgData variable in tCANMsgObject is the pointer to the data to send ulMsgLen bytes, or the pointer to the buffer to read ulMsgLen bytes into.

Programming Examples

This example code sends out data from CAN controller 0 to be received by CAN controller 1. In order to actually receive the data, an external cable must be connected between the two ports. In this example, both controllers are configured for 1 Mbit operation.

tCANBitClkParms CANBitClk;
tCANMsgObject sMsgObjectRx;
tCANMsgObject sMsgObjectTx;
uint8_t pui8BufferIn[8];
uint8_t pui8BufferOut[8];
//
// Enable the CAN0 module.
//
//
// Wait for the CAN0 module to be ready.
//
{
}
//
// Enable the CAN1 module.
//
//
// Wait for the CAN1 module to be ready.
//
{
}
//
// Reset the state of all the message objects and the state of the CAN
// module to a known state.
//
CANInit(CAN0_BASE);
CANInit(CAN1_BASE);
//
// Configure the controller for 1 Mbit operation.
//
CANSetBitTiming(CAN1_BASE, &CANBitClk);
//
// Take the CAN0 device out of INIT state.
//
CANEnable(CAN0_BASE);
CANEnable(CAN1_BASE);
//
// Configure a receive object.
//
sMsgObjectRx.ulMsgID = (0x400);
sMsgObjectRx.ulMsgIDMask = 0x7f8;
sMsgObjectRx.ulFlags = MSG_OBJ_USE_ID_FILTER | MSG_OBJ_FIFO;
//
// The first three message objects have the MSG_OBJ_FIFO set to indicate
// that they are part of a FIFO.
//
CANMessageSet(CAN0_BASE, 1, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
CANMessageSet(CAN0_BASE, 2, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
CANMessageSet(CAN0_BASE, 3, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
//
// Last message object does not have the MSG_OBJ_FIFO set to indicate that
// this is the last message.
//
sMsgObjectRx.ulFlags = MSG_OBJ_USE_ID_FILTER;
CANMessageSet(CAN0_BASE, 4, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
//
// Configure and start transmit of message object.
//
sMsgObjectTx.ulMsgID = 0x400;
sMsgObjectTx.ulFlags = 0;
sMsgObjectTx.ulMsgLen = 8;
sMsgObjectTx.pucMsgData = pui8BufferOut;
CANMessageSet(CAN0_BASE, 2, &sMsgObjectTx, MSG_OBJ_TYPE_TX);
//
// Wait for new data to become available.
//
while((CANStatusGet(CAN1_BASE, CAN_STS_NEWDAT) & 1) == 0)
{
//
// Read the message out of the message object.
//
CANMessageGet(CAN1_BASE, 1, &sMsgObjectRx, true);
}
//
// Process new data in sMsgObjectRx.pucMsgData.
//
...

This example code configures a set of CAN message objects in FIFO mode using CAN controller 0.

tCANBitClkParms CANBitClk;
tCANMsgObject sMsgObjectRx;
uint8_t pui8BufferIn[8];
uint8_t pui8BufferOut[8];
//
// Enable the CAN0 module.
//
//
// Wait for the CAN0 module to be ready.
//
{
}
//
// Reset the state of all the message objects and the state of the CAN
// module to a known state.
//
CANInit(CAN0_BASE);
//
// Configure the controller for 1 Mbit operation.
//
CANBitRateSet(CAN0_BASE, 8000000, 1000000);
//
// Take the CAN0 device out of INIT state.
//
CANEnable(CAN0_BASE);
//
// Configure a receive object as a CAN FIFO to receive message objects with
// message ID 0x400-0x407.
//
sMsgObjectRx.ulMsgID = (0x400);
sMsgObjectRx.ulMsgIDMask = 0x7f8;
sMsgObjectRx.ulFlags = MSG_OBJ_USE_ID_FILTER | MSG_OBJ_FIFO;
//
// The first three message objects have the MSG_OBJ_FIFO set to indicate
// that they are part of a FIFO.
//
CANMessageSet(CAN0_BASE, 1, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
CANMessageSet(CAN0_BASE, 2, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
CANMessageSet(CAN0_BASE, 3, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
//
// Last message object does not have the MSG_OBJ_FIFO set to indicate that
// this is the last message.
//
sMsgObjectRx.ulFlags = MSG_OBJ_USE_ID_FILTER;
CANMessageSet(CAN0_BASE, 4, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
...

Macro Definition Documentation

§ CAN_MAX_11BIT_MSG_ID

#define CAN_MAX_11BIT_MSG_ID   0x7ff

Referenced by CANMessageSet().

§ CAN_MAX_BIT_DIVISOR

#define CAN_MAX_BIT_DIVISOR   19

Referenced by CANBitRateSet().

§ CAN_MIN_BIT_DIVISOR

#define CAN_MIN_BIT_DIVISOR   4

Referenced by CANBitRateSet().

§ CAN_MAX_PRE_DIVISOR

#define CAN_MAX_PRE_DIVISOR   1024

Referenced by CANBitRateSet().

§ CAN_MIN_PRE_DIVISOR

#define CAN_MIN_PRE_DIVISOR   1

Referenced by CANBitRateSet().

§ CAN_BIT_VALUE

#define CAN_BIT_VALUE (   seg1,
  seg2,
  sjw 
)
Value:
((((seg1 - 1) << CAN_BIT_TSEG1_S) & \
CAN_BIT_TSEG1_M) | \
(((seg2 - 1) << CAN_BIT_TSEG2_S) & \
(((sjw - 1) << CAN_BIT_SJW_S) & \
CAN_BIT_SJW_M))
#define CAN_BIT_SJW_S
Definition: hw_can.h:141
#define CAN_BIT_TSEG2_S
Definition: hw_can.h:139
#define CAN_BIT_TSEG1_S
Definition: hw_can.h:140
#define CAN_BIT_TSEG2_M
Definition: hw_can.h:135

§ MSG_OBJ_TX_INT_ENABLE

#define MSG_OBJ_TX_INT_ENABLE   0x00000001

This indicates that transmit interrupts are enabled.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_RX_INT_ENABLE

#define MSG_OBJ_RX_INT_ENABLE   0x00000002

This indicates that receive interrupts are enabled.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_EXTENDED_ID

#define MSG_OBJ_EXTENDED_ID   0x00000004

This indicates that a message object is using an extended identifier.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_USE_ID_FILTER

#define MSG_OBJ_USE_ID_FILTER   0x00000008

This indicates that a message object is using filtering based on the object's message identifier.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_NEW_DATA

#define MSG_OBJ_NEW_DATA   0x00000080

This indicates that new data was available in the message object.

§ MSG_OBJ_DATA_LOST

#define MSG_OBJ_DATA_LOST   0x00000100

This indicates that data was lost since this message object was last read.

Referenced by CANMessageGet().

§ MSG_OBJ_USE_DIR_FILTER

#define MSG_OBJ_USE_DIR_FILTER   (0x00000010 | MSG_OBJ_USE_ID_FILTER)

This indicates that a message object uses or is using filtering based on the direction of the transfer. If the direction filtering is used, then ID filtering must also be enabled.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_USE_EXT_FILTER

#define MSG_OBJ_USE_EXT_FILTER   (0x00000020 | MSG_OBJ_USE_ID_FILTER)

This indicates that a message object uses or is using message identifier filtering based on the extended identifier. If the extended identifier filtering is used, then ID filtering must also be enabled.

Referenced by CANMessageGet(), and CANMessageSet().

§ MSG_OBJ_REMOTE_FRAME

#define MSG_OBJ_REMOTE_FRAME   0x00000040

This indicates that a message object is a remote frame.

Referenced by CANMessageGet().

§ MSG_OBJ_FIFO

#define MSG_OBJ_FIFO   0x00000200

This indicates that this message object is part of a FIFO structure and not the final message object in a FIFO.

Referenced by CANMessageSet().

§ MSG_OBJ_NO_FLAGS

#define MSG_OBJ_NO_FLAGS   0x00000000

This indicates that a message object has no flags set.

Referenced by CANMessageGet().

§ MSG_OBJ_STATUS_MASK

#define MSG_OBJ_STATUS_MASK   (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)

This define is used with the flag values to allow checking only status flags and not configuration flags.

§ CAN_INT_ERROR

#define CAN_INT_ERROR   0x00000008

This flag is used to allow a CAN controller to generate error interrupts.

§ CAN_INT_STATUS

#define CAN_INT_STATUS   0x00000004

This flag is used to allow a CAN controller to generate status interrupts.

§ CAN_INT_MASTER

#define CAN_INT_MASTER   0x00000002

This flag is used to allow a CAN controller to generate any CAN interrupts. If this is not set, then no interrupts are generated by the CAN controller.

§ CAN_STATUS_BUS_OFF

#define CAN_STATUS_BUS_OFF   0x00000080

CAN controller has entered a Bus Off state.

§ CAN_STATUS_EWARN

#define CAN_STATUS_EWARN   0x00000040

CAN controller error level has reached warning level.

§ CAN_STATUS_EPASS

#define CAN_STATUS_EPASS   0x00000020

CAN controller error level has reached error passive level.

§ CAN_STATUS_RXOK

#define CAN_STATUS_RXOK   0x00000010

A message was received successfully since the last read of this status.

§ CAN_STATUS_TXOK

#define CAN_STATUS_TXOK   0x00000008

A message was transmitted successfully since the last read of this status.

§ CAN_STATUS_LEC_MSK

#define CAN_STATUS_LEC_MSK   0x00000007

This is the mask for the last error code field.

§ CAN_STATUS_LEC_NONE

#define CAN_STATUS_LEC_NONE   0x00000000

There was no error.

§ CAN_STATUS_LEC_STUFF

#define CAN_STATUS_LEC_STUFF   0x00000001

A bit stuffing error has occurred.

§ CAN_STATUS_LEC_FORM

#define CAN_STATUS_LEC_FORM   0x00000002

A formatting error has occurred.

§ CAN_STATUS_LEC_ACK

#define CAN_STATUS_LEC_ACK   0x00000003

An acknowledge error has occurred.

§ CAN_STATUS_LEC_BIT1

#define CAN_STATUS_LEC_BIT1   0x00000004

The bus remained a bit level of 1 for longer than is allowed.

§ CAN_STATUS_LEC_BIT0

#define CAN_STATUS_LEC_BIT0   0x00000005

The bus remained a bit level of 0 for longer than is allowed.

§ CAN_STATUS_LEC_CRC

#define CAN_STATUS_LEC_CRC   0x00000006

A CRC error has occurred.

§ CAN_STATUS_LEC_MASK

#define CAN_STATUS_LEC_MASK   0x00000007

This is the mask for the CAN Last Error Code (LEC).

Enumeration Type Documentation

§ tCANIntStsReg

This data type is used to identify the interrupt status register. This is used when calling the CANIntStatus() function.

Enumerator
CAN_INT_STS_CAUSE 

Read the CAN interrupt status information.

CAN_INT_STS_OBJECT 

Read a message object's interrupt status.

§ tCANStsReg

enum tCANStsReg

This data type is used to identify which of several status registers to read when calling the CANStatusGet() function.

Enumerator
CAN_STS_CONTROL 

Read the full CAN controller status.

CAN_STS_TXREQUEST 

Read the full 32-bit mask of message objects with a transmit request set.

CAN_STS_NEWDAT 

Read the full 32-bit mask of message objects with new data available.

CAN_STS_MSGVAL 

Read the full 32-bit mask of message objects that are enabled.

§ tMsgObjType

This definition is used to determine the type of message object that is set up via a call to the CANMessageSet() API.

Enumerator
MSG_OBJ_TYPE_TX 

Transmit message object.

MSG_OBJ_TYPE_TX_REMOTE 

Transmit remote request message object.

MSG_OBJ_TYPE_RX 

Receive message object.

MSG_OBJ_TYPE_RX_REMOTE 

Receive remote request message object.

MSG_OBJ_TYPE_RXTX_REMOTE 

Remote frame receive remote, with auto-transmit message object.

Function Documentation

§ CANInit()

void CANInit ( uint32_t  ui32Base)

Initializes the CAN controller after reset.

Parameters
ui32Baseis the base address of the CAN controller.

After reset, the CAN controller is left in the disabled state. However, the memory used for message objects contains undefined values and must be cleared prior to enabling the CAN controller the first time. This prevents unwanted transmission or reception of data before the message objects are configured. This function must be called before enabling the controller the first time.

Returns
None.

References ASSERT, CAN_CTL_INIT, CAN_IF1CMSK_ARB, CAN_IF1CMSK_CLRINTPND, CAN_IF1CMSK_CONTROL, CAN_IF1CMSK_NEWDAT, CAN_IF1CMSK_WRNRD, CAN_IF1CRQ_BUSY, CAN_O_CTL, CAN_O_IF1ARB2, CAN_O_IF1CMSK, CAN_O_IF1CRQ, CAN_O_IF1MCTL, CAN_O_STS, and HWREG.

§ CANEnable()

void CANEnable ( uint32_t  ui32Base)

Enables the CAN controller.

Parameters
ui32Baseis the base address of the CAN controller to enable.

Enables the CAN controller for message processing. Once enabled, the controller automatically transmits any pending frames, and processes any received frames. The controller can be stopped by calling CANDisable(). Prior to calling CANEnable(), CANInit() must have been called to initialize the controller and the CAN bus clock must be configured by calling CANBitTimingSet().

Returns
None.

References ASSERT, CAN_CTL_INIT, CAN_O_CTL, and HWREG.

§ CANDisable()

void CANDisable ( uint32_t  ui32Base)

Disables the CAN controller.

Parameters
ui32Baseis the base address of the CAN controller to disable.

Disables the CAN controller for message processing. When disabled, the controller no longer automatically processes data on the CAN bus. The controller can be restarted by calling CANEnable(). The state of the CAN controller and the message objects in the controller are left as they were before this call was made.

Returns
None.

References ASSERT, CAN_CTL_INIT, CAN_O_CTL, and HWREG.

§ CANBitTimingGet()

void CANBitTimingGet ( uint32_t  ui32Base,
tCANBitClkParms psClkParms 
)

Reads the current settings for the CAN controller bit timing.

Parameters
ui32Baseis the base address of the CAN controller.
psClkParmsis a pointer to a structure to hold the timing parameters.

This function reads the current configuration of the CAN controller bit clock timing and stores the resulting information in the structure supplied by the caller. Refer to CANBitTimingSet() for the meaning of the values that are returned in the structure pointed to by psClkParms.

Returns
None.

References ASSERT, CAN_BIT_BRP_M, CAN_BIT_SJW_M, CAN_BIT_SJW_S, CAN_BIT_TSEG1_M, CAN_BIT_TSEG1_S, CAN_BIT_TSEG2_M, CAN_BIT_TSEG2_S, CAN_BRPE_BRPE_M, CAN_O_BIT, CAN_O_BRPE, HWREG, tCANBitClkParms::ui32Phase2Seg, tCANBitClkParms::ui32QuantumPrescaler, tCANBitClkParms::ui32SJW, and tCANBitClkParms::ui32SyncPropPhase1Seg.

§ CANBitRateSet()

uint32_t CANBitRateSet ( uint32_t  ui32Base,
uint32_t  ui32SourceClock,
uint32_t  ui32BitRate 
)

Sets the CAN bit timing values to a nominal setting based on a desired bit rate.

Parameters
ui32Baseis the base address of the CAN controller.
ui32SourceClockis the system clock for the device in Hz.
ui32BitRateis the desired bit rate.

This function sets the CAN bit timing for the bit rate passed in the ui32BitRate parameter based on the ui32SourceClock parameter. Because the CAN clock is based off of the system clock, the calling function must pass in the source clock rate either by retrieving it from SysCtlClockGet() or using a specific value in Hz. The CAN bit timing is calculated assuming a minimal amount of propagation delay, which works for most cases where the network length is short. If tighter timing requirements or longer network lengths are needed, then the CANBitTimingSet() function is available for full customization of all of the CAN bit timing values. Because not all bit rates can be matched exactly, the bit rate is set to the value closest to the desired bit rate without being higher than the ui32BitRate value.

Returns
This function returns the bit rate that the CAN controller was configured to use or it returns 0 to indicate that the bit rate was not changed because the requested bit rate was not valid.

References ASSERT, CAN_MAX_BIT_DIVISOR, CAN_MAX_PRE_DIVISOR, CAN_MIN_BIT_DIVISOR, and CAN_MIN_PRE_DIVISOR.

§ CANBitTimingSet()

void CANBitTimingSet ( uint32_t  ui32Base,
tCANBitClkParms psClkParms 
)

Configures the CAN controller bit timing.

Parameters
ui32Baseis the base address of the CAN controller.
psClkParmspoints to the structure with the clock parameters.

Configures the various timing parameters for the CAN bus bit timing: Propagation segment, Phase Buffer 1 segment, Phase Buffer 2 segment, and the Synchronization Jump Width. The values for Propagation and Phase Buffer 1 segments are derived from the combination psClkParms->ui32SyncPropPhase1Seg parameter. Phase Buffer 2 is determined from the psClkParms->ui32Phase2Seg parameter. These two parameters, along with psClkParms->ui32SJW are based in units of bit time quanta. The actual quantum time is determined by the psClkParms->ui32QuantumPrescaler value, which specifies the divisor for the CAN module clock.

The total bit time, in quanta, is the sum of the two Seg parameters, as follows:

bit_time_q = ui32SyncPropPhase1Seg + ui32Phase2Seg + 1

Note that the Sync_Seg is always one quantum in duration, and is added to derive the correct duration of Prop_Seg and Phase1_Seg.

The equation to determine the actual bit rate is as follows:

CAN Clock / ((ui32SyncPropPhase1Seg + ui32Phase2Seg + 1) * (ui32QuantumPrescaler))

Thus with ui32SyncPropPhase1Seg = 4, ui32Phase2Seg = 1, ui32QuantumPrescaler = 2 and an 8 MHz CAN clock, the bit rate is (8 MHz) / ((5 + 2 + 1) * 2) or 500 Kbit/sec.

Returns
None.

References ASSERT, CAN_BIT_BRP_M, CAN_BIT_SJW_M, CAN_BIT_SJW_S, CAN_BIT_TSEG1_M, CAN_BIT_TSEG1_S, CAN_BIT_TSEG2_M, CAN_BIT_TSEG2_S, CAN_BRPE_BRPE_M, CAN_CTL_CCE, CAN_CTL_INIT, CAN_O_BIT, CAN_O_BRPE, CAN_O_CTL, HWREG, tCANBitClkParms::ui32Phase2Seg, tCANBitClkParms::ui32QuantumPrescaler, tCANBitClkParms::ui32SJW, and tCANBitClkParms::ui32SyncPropPhase1Seg.

§ CANIntRegister()

void CANIntRegister ( uint32_t  ui32Base,
void(*)(void)  pfnHandler 
)

Registers an interrupt handler for the CAN controller.

Parameters
ui32Baseis the base address of the CAN controller.
pfnHandleris a pointer to the function to be called when the enabled CAN interrupts occur.

This function registers the interrupt handler in the interrupt vector table, and enables CAN interrupts on the interrupt controller; specific CAN interrupt sources must be enabled using CANIntEnable(). The interrupt handler being registered must clear the source of the interrupt using CANIntClear().

If the application is using a static interrupt vector table stored in flash, then it is not necessary to register the interrupt handler this way. Instead, IntEnable() is used to enable CAN interrupts on the interrupt controller.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

References ASSERT.

§ CANIntUnregister()

void CANIntUnregister ( uint32_t  ui32Base)

Unregisters an interrupt handler for the CAN controller.

Parameters
ui32Baseis the base address of the controller.

This function unregisters the previously registered interrupt handler and disables the interrupt in the interrupt controller.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

References ASSERT.

§ CANIntEnable()

void CANIntEnable ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Enables individual CAN controller interrupt sources.

Parameters
ui32Baseis the base address of the CAN controller.
ui32IntFlagsis the bit mask of the interrupt sources to be enabled.

This function enables specific interrupt sources of the CAN controller. Only enabled sources cause a processor interrupt.

The ui32IntFlags parameter is the logical OR of any of the following:

  • CAN_INT_ERROR - a controller error condition has occurred
  • CAN_INT_STATUS - a message transfer has completed, or a bus error has been detected
  • CAN_INT_MASTER - allow CAN controller to generate interrupts

In order to generate any interrupts, CAN_INT_MASTER must be enabled. Further, for any particular transaction from a message object to generate an interrupt, that message object must have interrupts enabled (see CANMessageSet()). CAN_INT_ERROR generates an interrupt if the controller enters the ``bus off'' condition, or if the error counters reach a limit. CAN_INT_STATUS generates an interrupt under quite a few status conditions and may provide more interrupts than the application needs to handle. When an interrupt occurs, use CANIntStatus() to determine the cause.

Returns
None.

References ASSERT, CAN_CTL_EIE, CAN_CTL_IE, CAN_CTL_SIE, CAN_O_CTL, and HWREG.

§ CANIntDisable()

void CANIntDisable ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Disables individual CAN controller interrupt sources.

Parameters
ui32Baseis the base address of the CAN controller.
ui32IntFlagsis the bit mask of the interrupt sources to be disabled.

Disables the specified CAN controller interrupt sources. Only enabled interrupt sources can cause a processor interrupt.

The ui32IntFlags parameter has the same definition as in the CANIntEnable() function.

Returns
None.

References ASSERT, CAN_CTL_EIE, CAN_CTL_IE, CAN_CTL_SIE, CAN_O_CTL, and HWREG.

§ CANIntStatus()

uint32_t CANIntStatus ( uint32_t  ui32Base,
tCANIntStsReg  eIntStsReg 
)

Returns the current CAN controller interrupt status.

Parameters
ui32Baseis the base address of the CAN controller.
eIntStsRegindicates which interrupt status register to read

This function returns the value of one of two interrupt status registers. The interrupt status register read is determined by the eIntStsReg parameter, which can have one of the following values:

  • CAN_INT_STS_CAUSE - indicates the cause of the interrupt
  • CAN_INT_STS_OBJECT - indicates pending interrupts of all message objects

CAN_INT_STS_CAUSE returns the value of the controller interrupt register and indicates the cause of the interrupt. The value returned is CAN_INT_INTID_STATUS if the cause is a status interrupt. In this case, the status register is read with the CANStatusGet() function. Calling this function to read the status also clears the status interrupt. If the value of the interrupt register is in the range 1-32, then this indicates the number of the highest priority message object that has an interrupt pending. The message object interrupt can be cleared by using the CANIntClear() function, or by reading the message using CANMessageGet() in the case of a received message. The interrupt handler can read the interrupt status again to make sure all pending interrupts are cleared before returning from the interrupt.

CAN_INT_STS_OBJECT returns a bit mask indicating which message objects have pending interrupts. This value can be used to discover all of the pending interrupts at once, as opposed to repeatedly reading the interrupt register by using CAN_INT_STS_CAUSE.

Returns
Returns the value of one of the interrupt status registers.

References ASSERT, CAN_INT_STS_CAUSE, CAN_INT_STS_OBJECT, CAN_MSG1INT_INTPND_M, CAN_O_INT, CAN_O_MSG1INT, CAN_O_MSG2INT, and HWREG.

§ CANIntClear()

void CANIntClear ( uint32_t  ui32Base,
uint32_t  ui32IntClr 
)

Clears a CAN interrupt source.

Parameters
ui32Baseis the base address of the CAN controller.
ui32IntClris a value indicating which interrupt source to clear.

This function can be used to clear a specific interrupt source. The ui32IntClr parameter must be one of the following values:

  • CAN_INT_INTID_STATUS - Clears a status interrupt.
  • 1-32 - Clears the specified message object interrupt

It is not necessary to use this function to clear an interrupt. This function is only used if the application wants to clear an interrupt source without taking the normal interrupt action.

Normally, the status interrupt is cleared by reading the controller status using CANStatusGet(). A specific message object interrupt is normally cleared by reading the message object using CANMessageGet().

Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler (as opposed to the very last action) to avoid returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
Returns
None.

References ASSERT, CAN_IF1CMSK_CLRINTPND, CAN_IF1CRQ_BUSY, CAN_IF1CRQ_MNUM_M, CAN_INT_INTID_STATUS, CAN_O_IF1CMSK, CAN_O_IF1CRQ, CAN_O_STS, and HWREG.

§ CANRetrySet()

void CANRetrySet ( uint32_t  ui32Base,
bool  bAutoRetry 
)

Sets the CAN controller automatic retransmission behavior.

Parameters
ui32Baseis the base address of the CAN controller.
bAutoRetryenables automatic retransmission.

This function enables or disables automatic retransmission of messages with detected errors. If bAutoRetry is true, then automatic retransmission is enabled, otherwise it is disabled.

Returns
None.

References ASSERT, CAN_CTL_DAR, CAN_O_CTL, and HWREG.

§ CANRetryGet()

bool CANRetryGet ( uint32_t  ui32Base)

Returns the current setting for automatic retransmission.

Parameters
ui32Baseis the base address of the CAN controller.

This function reads the current setting for automatic retransmission in the CAN controller and returns it to the caller.

Returns
Returns true if automatic retransmission is enabled, false otherwise.

References ASSERT, CAN_CTL_DAR, CAN_O_CTL, and HWREG.

§ CANStatusGet()

uint32_t CANStatusGet ( uint32_t  ui32Base,
tCANStsReg  eStatusReg 
)

Reads one of the controller status registers.

Parameters
ui32Baseis the base address of the CAN controller.
eStatusRegis the status register to read.

This function reads a status register of the CAN controller and returns it to the caller. The different status registers are:

  • CAN_STS_CONTROL - the main controller status
  • CAN_STS_TXREQUEST - bit mask of objects pending transmission
  • CAN_STS_NEWDAT - bit mask of objects with new data
  • CAN_STS_MSGVAL - bit mask of objects with valid configuration

When reading the main controller status register, a pending status interrupt is cleared. This parameter is used in the interrupt handler for the CAN controller if the cause is a status interrupt. The controller status register fields are as follows:

  • CAN_STATUS_BUS_OFF - controller is in bus-off condition
  • CAN_STATUS_EWARN - an error counter has reached a limit of at least 96
  • CAN_STATUS_EPASS - CAN controller is in the error passive state
  • CAN_STATUS_RXOK - a message was received successfully (independent of any message filtering).
  • CAN_STATUS_TXOK - a message was successfully transmitted
  • CAN_STATUS_LEC_MSK - mask of last error code bits (3 bits)
  • CAN_STATUS_LEC_NONE - no error
  • CAN_STATUS_LEC_STUFF - stuffing error detected
  • CAN_STATUS_LEC_FORM - a format error occurred in the fixed format part of a message
  • CAN_STATUS_LEC_ACK - a transmitted message was not acknowledged
  • CAN_STATUS_LEC_BIT1 - dominant level detected when trying to send in recessive mode
  • CAN_STATUS_LEC_BIT0 - recessive level detected when trying to send in dominant mode
  • CAN_STATUS_LEC_CRC - CRC error in received message

The remaining status registers consist of 32-bit-wide bit maps to the message objects. They can be used to quickly obtain information about the status of all the message objects without needing to query each one. They contain the following information:

  • CAN_STS_TXREQUEST - if a message object's TXRQST bit is set, a transmission is pending on that object. The application can use this information to determine which objects are still waiting to send a message.
  • CAN_STS_NEWDAT - if a message object's NEWDAT bit is set, a new message has been received in that object, and has not yet been picked up by the host application
  • CAN_STS_MSGVAL - if a message object's MSGVAL bit is set, the object has a valid configuration programmed. The host application can use this information to determine which message objects are empty/unused.
Returns
Returns the value of the status register.

References ASSERT, CAN_O_MSG1VAL, CAN_O_MSG2VAL, CAN_O_NWDA1, CAN_O_NWDA2, CAN_O_STS, CAN_O_TXRQ1, CAN_O_TXRQ2, CAN_STS_CONTROL, CAN_STS_LEC_M, CAN_STS_MSGVAL, CAN_STS_NEWDAT, CAN_STS_RXOK, CAN_STS_TXOK, CAN_STS_TXREQUEST, and HWREG.

§ CANErrCntrGet()

bool CANErrCntrGet ( uint32_t  ui32Base,
uint32_t *  pui32RxCount,
uint32_t *  pui32TxCount 
)

Reads the CAN controller error counter register.

Parameters
ui32Baseis the base address of the CAN controller.
pui32RxCountis a pointer to storage for the receive error counter.
pui32TxCountis a pointer to storage for the transmit error counter.

This function reads the error counter register and returns the transmit and receive error counts to the caller along with a flag indicating if the controller receive counter has reached the error passive limit. The values of the receive and transmit error counters are returned through the pointers provided as parameters.

After this call, *pui32RxCount holds the current receive error count and *pui32TxCount holds the current transmit error count.

Returns
Returns true if the receive error count has reached the error passive limit, and false if the error count is below the error passive limit.

References ASSERT, CAN_ERR_REC_M, CAN_ERR_REC_S, CAN_ERR_RP, CAN_ERR_TEC_M, CAN_ERR_TEC_S, CAN_O_ERR, and HWREG.

§ CANMessageSet()

void CANMessageSet ( uint32_t  ui32Base,
uint32_t  ui32ObjID,
tCANMsgObject psMsgObject,
tMsgObjType  eMsgType 
)

Configures a message object in the CAN controller.

Parameters
ui32Baseis the base address of the CAN controller.
ui32ObjIDis the object number to configure (1-32).
psMsgObjectis a pointer to a structure containing message object settings.
eMsgTypeindicates the type of message for this object.

This function is used to configure any one of the 32 message objects in the CAN controller. A message object can be configured to be any type of CAN message object as well as to use automatic transmission and reception. This call also allows the message object to be configured to generate interrupts on completion of message receipt or transmission. The message object can also be configured with a filter/mask so that actions are only taken when a message that meets certain parameters is seen on the CAN bus.

The eMsgType parameter must be one of the following values:

  • MSG_OBJ_TYPE_TX - CAN transmit message object.
  • MSG_OBJ_TYPE_TX_REMOTE - CAN transmit remote request message object.
  • MSG_OBJ_TYPE_RX - CAN receive message object.
  • MSG_OBJ_TYPE_RX_REMOTE - CAN receive remote request message object.
  • MSG_OBJ_TYPE_RXTX_REMOTE - CAN remote frame receive remote, then transmit message object.

The message object pointed to by psMsgObject must be populated by the caller, as follows:

  • ui32MsgID - contains the message ID, either 11 or 29 bits.
  • ui32MsgIDMask - mask of bits from ui32MsgID that must match if identifier filtering is enabled.
  • ui32Flags
    • Set MSG_OBJ_TX_INT_ENABLE flag to enable interrupt on transmission.
    • Set MSG_OBJ_RX_INT_ENABLE flag to enable interrupt on receipt.
    • Set MSG_OBJ_USE_ID_FILTER flag to enable filtering based on the identifier mask specified by ui32MsgIDMask.
  • ui32MsgLen - the number of bytes in the message data. This parameter must be non-zero even for a remote frame; it must match the expected bytes of data in the responding data frame.
  • pui8MsgData - points to a buffer containing up to 8 bytes of data for a data frame.

Example: To send a data frame or remote frame (in response to a remote request), take the following steps:

  1. Set eMsgType to MSG_OBJ_TYPE_TX.
  2. Set psMsgObject->ui32MsgID to the message ID.
  3. Set psMsgObject->ui32Flags. Make sure to set MSG_OBJ_TX_INT_ENABLE to allow an interrupt to be generated when the message is sent.
  4. Set psMsgObject->ui32MsgLen to the number of bytes in the data frame.
  5. Set psMsgObject->pui8MsgData to point to an array containing the bytes to send in the message.
  6. Call this function with ui32ObjID set to one of the 32 object buffers.

Example: To receive a specific data frame, take the following steps:

  1. Set eMsgObjType to MSG_OBJ_TYPE_RX.
  2. Set psMsgObject->ui32MsgID to the full message ID, or a partial mask to use partial ID matching.
  3. Set psMsgObject->ui32MsgIDMask bits that are used for masking during comparison.
  4. Set psMsgObject->ui32Flags as follows:
    • Set MSG_OBJ_RX_INT_ENABLE flag to be interrupted when the data frame is received.
    • Set MSG_OBJ_USE_ID_FILTER flag to enable identifier-based filtering.
  5. Set psMsgObject->ui32MsgLen to the number of bytes in the expected data frame.
  6. The buffer pointed to by psMsgObject->pui8MsgData is not used by this call as no data is present at the time of the call.
  7. Call this function with ui32ObjID set to one of the 32 object buffers.

If you specify a message object buffer that already contains a message definition, it is overwritten.

Returns
None.

References ASSERT, CAN_IF1ARB1_ID_M, CAN_IF1ARB2_DIR, CAN_IF1ARB2_ID_M, CAN_IF1ARB2_MSGVAL, CAN_IF1ARB2_XTD, CAN_IF1CMSK_ARB, CAN_IF1CMSK_CONTROL, CAN_IF1CMSK_DATAA, CAN_IF1CMSK_DATAB, CAN_IF1CMSK_MASK, CAN_IF1CMSK_WRNRD, CAN_IF1CRQ_BUSY, CAN_IF1MCTL_DLC_M, CAN_IF1MCTL_EOB, CAN_IF1MCTL_RMTEN, CAN_IF1MCTL_RXIE, CAN_IF1MCTL_TXIE, CAN_IF1MCTL_TXRQST, CAN_IF1MCTL_UMASK, CAN_IF1MSK1_IDMSK_M, CAN_IF1MSK2_IDMSK_M, CAN_IF1MSK2_MDIR, CAN_IF1MSK2_MXTD, CAN_MAX_11BIT_MSG_ID, CAN_O_IF1CRQ, HWREG, MSG_OBJ_EXTENDED_ID, MSG_OBJ_FIFO, MSG_OBJ_RX_INT_ENABLE, MSG_OBJ_TX_INT_ENABLE, MSG_OBJ_TYPE_RX, MSG_OBJ_TYPE_RX_REMOTE, MSG_OBJ_TYPE_RXTX_REMOTE, MSG_OBJ_TYPE_TX, MSG_OBJ_TYPE_TX_REMOTE, MSG_OBJ_USE_DIR_FILTER, MSG_OBJ_USE_EXT_FILTER, MSG_OBJ_USE_ID_FILTER, tCANMsgObject::ui32Flags, tCANMsgObject::ui32MsgID, tCANMsgObject::ui32MsgIDMask, and tCANMsgObject::ui32MsgLen.

§ CANMessageGet()

void CANMessageGet ( uint32_t  ui32Base,
uint32_t  ui32ObjID,
tCANMsgObject psMsgObject,
bool  bClrPendingInt 
)

Reads a CAN message from one of the message object buffers.

Parameters
ui32Baseis the base address of the CAN controller.
ui32ObjIDis the object number to read (1-32).
psMsgObjectpoints to a structure containing message object fields.
bClrPendingIntindicates whether an associated interrupt should be cleared.

This function is used to read the contents of one of the 32 message objects in the CAN controller and return it to the caller. The data returned is stored in the fields of the caller-supplied structure pointed to by psMsgObject. The data consists of all of the parts of a CAN message, plus some control and status information.

Normally, this function is used to read a message object that has received and stored a CAN message with a certain identifier. However, this function could also be used to read the contents of a message object in order to load the fields of the structure in case only part of the structure must be changed from a previous setting.

When using CANMessageGet(), all of the same fields of the structure are populated in the same way as when the CANMessageSet() function is used, with the following exceptions:

psMsgObject->ui32Flags:

  • MSG_OBJ_NEW_DATA indicates if this data is new since the last time it was read
  • MSG_OBJ_DATA_LOST indicates that at least one message was received on this message object and not read by the host before being overwritten.
Returns
None.

References ASSERT, CAN_IF1ARB2_DIR, CAN_IF1ARB2_ID_M, CAN_IF1ARB2_XTD, CAN_IF1CMSK_ARB, CAN_IF1CMSK_CLRINTPND, CAN_IF1CMSK_CONTROL, CAN_IF1CMSK_DATAA, CAN_IF1CMSK_DATAB, CAN_IF1CMSK_MASK, CAN_IF1CRQ_BUSY, CAN_IF1CRQ_MNUM_M, CAN_IF1MCTL_DLC_M, CAN_IF1MCTL_MSGLST, CAN_IF1MCTL_NEWDAT, CAN_IF1MCTL_RXIE, CAN_IF1MCTL_TXIE, CAN_IF1MCTL_TXRQST, CAN_IF1MCTL_UMASK, CAN_IF1MSK2_IDMSK_M, CAN_IF1MSK2_MDIR, CAN_IF1MSK2_MXTD, CAN_O_IF2ARB1, CAN_O_IF2ARB2, CAN_O_IF2CMSK, CAN_O_IF2CRQ, CAN_O_IF2MCTL, CAN_O_IF2MSK1, CAN_O_IF2MSK2, HWREG, MSG_OBJ_DATA_LOST, MSG_OBJ_EXTENDED_ID, MSG_OBJ_NO_FLAGS, MSG_OBJ_REMOTE_FRAME, MSG_OBJ_RX_INT_ENABLE, MSG_OBJ_TX_INT_ENABLE, MSG_OBJ_USE_DIR_FILTER, MSG_OBJ_USE_EXT_FILTER, MSG_OBJ_USE_ID_FILTER, tCANMsgObject::ui32Flags, tCANMsgObject::ui32MsgID, tCANMsgObject::ui32MsgIDMask, and tCANMsgObject::ui32MsgLen.

§ CANMessageClear()

void CANMessageClear ( uint32_t  ui32Base,
uint32_t  ui32ObjID 
)

Clears a message object so that it is no longer used.

Parameters
ui32Baseis the base address of the CAN controller.
ui32ObjIDis the message object number to disable (1-32).

This function frees the specified message object from use. Once a message object has been ``cleared,'' it no longer automatically sends or receives messages, nor does it generate interrupts.

Returns
None.

References ASSERT, CAN_IF1CMSK_ARB, CAN_IF1CMSK_WRNRD, CAN_IF1CRQ_BUSY, CAN_IF1CRQ_MNUM_M, CAN_O_IF1ARB1, CAN_O_IF1ARB2, CAN_O_IF1CMSK, CAN_O_IF1CRQ, and HWREG.

© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale