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

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 2018, Texas Instruments Incorporated