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) |
#define CAN_MAX_11BIT_MSG_ID 0x7ff |
Referenced by CANMessageSet().
#define CAN_MAX_BIT_DIVISOR 19 |
Referenced by CANBitRateSet().
#define CAN_MIN_BIT_DIVISOR 4 |
Referenced by CANBitRateSet().
#define CAN_MAX_PRE_DIVISOR 1024 |
Referenced by CANBitRateSet().
#define CAN_MIN_PRE_DIVISOR 1 |
Referenced by CANBitRateSet().
#define CAN_BIT_VALUE | ( | seg1, | |
seg2, | |||
sjw | |||
) |
#define MSG_OBJ_TX_INT_ENABLE 0x00000001 |
This indicates that transmit interrupts are enabled.
Referenced by CANMessageGet(), and CANMessageSet().
#define MSG_OBJ_RX_INT_ENABLE 0x00000002 |
This indicates that receive interrupts are enabled.
Referenced by CANMessageGet(), and CANMessageSet().
#define MSG_OBJ_EXTENDED_ID 0x00000004 |
This indicates that a message object is using an extended identifier.
Referenced by CANMessageGet(), and CANMessageSet().
#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().
#define MSG_OBJ_NEW_DATA 0x00000080 |
This indicates that new data was available in the message object.
#define MSG_OBJ_DATA_LOST 0x00000100 |
This indicates that data was lost since this message object was last read.
Referenced by CANMessageGet().
#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().
#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().
#define MSG_OBJ_REMOTE_FRAME 0x00000040 |
This indicates that a message object is a remote frame.
Referenced by CANMessageGet().
#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().
#define MSG_OBJ_NO_FLAGS 0x00000000 |
This indicates that a message object has no flags set.
Referenced by CANMessageGet().
#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.
#define CAN_INT_ERROR 0x00000008 |
This flag is used to allow a CAN controller to generate error interrupts.
#define CAN_INT_STATUS 0x00000004 |
This flag is used to allow a CAN controller to generate status interrupts.
#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.
#define CAN_STATUS_BUS_OFF 0x00000080 |
CAN controller has entered a Bus Off state.
#define CAN_STATUS_EWARN 0x00000040 |
CAN controller error level has reached warning level.
#define CAN_STATUS_EPASS 0x00000020 |
CAN controller error level has reached error passive level.
#define CAN_STATUS_RXOK 0x00000010 |
A message was received successfully since the last read of this status.
#define CAN_STATUS_TXOK 0x00000008 |
A message was transmitted successfully since the last read of this status.
#define CAN_STATUS_LEC_MSK 0x00000007 |
This is the mask for the last error code field.
#define CAN_STATUS_LEC_NONE 0x00000000 |
There was no error.
#define CAN_STATUS_LEC_STUFF 0x00000001 |
A bit stuffing error has occurred.
#define CAN_STATUS_LEC_FORM 0x00000002 |
A formatting error has occurred.
#define CAN_STATUS_LEC_ACK 0x00000003 |
An acknowledge error has occurred.
#define CAN_STATUS_LEC_BIT1 0x00000004 |
The bus remained a bit level of 1 for longer than is allowed.
#define CAN_STATUS_LEC_BIT0 0x00000005 |
The bus remained a bit level of 0 for longer than is allowed.
#define CAN_STATUS_LEC_CRC 0x00000006 |
A CRC error has occurred.
#define CAN_STATUS_LEC_MASK 0x00000007 |
This is the mask for the CAN Last Error Code (LEC).
enum 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. |
enum tCANStsReg |
This data type is used to identify which of several status registers to read when calling the CANStatusGet() function.
enum tMsgObjType |
This definition is used to determine the type of message object that is set up via a call to the CANMessageSet() API.
void CANInit | ( | uint32_t | ui32Base | ) |
Initializes the CAN controller after reset.
ui32Base | is 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.
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.
void CANEnable | ( | uint32_t | ui32Base | ) |
Enables the CAN controller.
ui32Base | is 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().
References ASSERT, CAN_CTL_INIT, CAN_O_CTL, and HWREG.
void CANDisable | ( | uint32_t | ui32Base | ) |
Disables the CAN controller.
ui32Base | is 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.
References ASSERT, CAN_CTL_INIT, CAN_O_CTL, and HWREG.
void CANBitTimingGet | ( | uint32_t | ui32Base, |
tCANBitClkParms * | psClkParms | ||
) |
Reads the current settings for the CAN controller bit timing.
ui32Base | is the base address of the CAN controller. |
psClkParms | is 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.
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.
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.
ui32Base | is the base address of the CAN controller. |
ui32SourceClock | is the system clock for the device in Hz. |
ui32BitRate | is 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.
References ASSERT, CAN_MAX_BIT_DIVISOR, CAN_MAX_PRE_DIVISOR, CAN_MIN_BIT_DIVISOR, and CAN_MIN_PRE_DIVISOR.
void CANBitTimingSet | ( | uint32_t | ui32Base, |
tCANBitClkParms * | psClkParms | ||
) |
Configures the CAN controller bit timing.
ui32Base | is the base address of the CAN controller. |
psClkParms | points 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.
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.
void CANIntRegister | ( | uint32_t | ui32Base, |
void(*)(void) | pfnHandler | ||
) |
Registers an interrupt handler for the CAN controller.
ui32Base | is the base address of the CAN controller. |
pfnHandler | is 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.
References ASSERT.
void CANIntUnregister | ( | uint32_t | ui32Base | ) |
Unregisters an interrupt handler for the CAN controller.
ui32Base | is the base address of the controller. |
This function unregisters the previously registered interrupt handler and disables the interrupt in the interrupt controller.
References ASSERT.
void CANIntEnable | ( | uint32_t | ui32Base, |
uint32_t | ui32IntFlags | ||
) |
Enables individual CAN controller interrupt sources.
ui32Base | is the base address of the CAN controller. |
ui32IntFlags | is 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:
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.
References ASSERT, CAN_CTL_EIE, CAN_CTL_IE, CAN_CTL_SIE, CAN_O_CTL, and HWREG.
void CANIntDisable | ( | uint32_t | ui32Base, |
uint32_t | ui32IntFlags | ||
) |
Disables individual CAN controller interrupt sources.
ui32Base | is the base address of the CAN controller. |
ui32IntFlags | is 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.
References ASSERT, CAN_CTL_EIE, CAN_CTL_IE, CAN_CTL_SIE, CAN_O_CTL, and HWREG.
uint32_t CANIntStatus | ( | uint32_t | ui32Base, |
tCANIntStsReg | eIntStsReg | ||
) |
Returns the current CAN controller interrupt status.
ui32Base | is the base address of the CAN controller. |
eIntStsReg | indicates 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 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.
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.
void CANIntClear | ( | uint32_t | ui32Base, |
uint32_t | ui32IntClr | ||
) |
Clears a CAN interrupt source.
ui32Base | is the base address of the CAN controller. |
ui32IntClr | is 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:
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().
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.
void CANRetrySet | ( | uint32_t | ui32Base, |
bool | bAutoRetry | ||
) |
Sets the CAN controller automatic retransmission behavior.
ui32Base | is the base address of the CAN controller. |
bAutoRetry | enables 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.
References ASSERT, CAN_CTL_DAR, CAN_O_CTL, and HWREG.
bool CANRetryGet | ( | uint32_t | ui32Base | ) |
Returns the current setting for automatic retransmission.
ui32Base | is 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.
References ASSERT, CAN_CTL_DAR, CAN_O_CTL, and HWREG.
uint32_t CANStatusGet | ( | uint32_t | ui32Base, |
tCANStsReg | eStatusReg | ||
) |
Reads one of the controller status registers.
ui32Base | is the base address of the CAN controller. |
eStatusReg | is 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:
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:
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:
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.
bool CANErrCntrGet | ( | uint32_t | ui32Base, |
uint32_t * | pui32RxCount, | ||
uint32_t * | pui32TxCount | ||
) |
Reads the CAN controller error counter register.
ui32Base | is the base address of the CAN controller. |
pui32RxCount | is a pointer to storage for the receive error counter. |
pui32TxCount | is 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.
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.
void CANMessageSet | ( | uint32_t | ui32Base, |
uint32_t | ui32ObjID, | ||
tCANMsgObject * | psMsgObject, | ||
tMsgObjType | eMsgType | ||
) |
Configures a message object in the CAN controller.
ui32Base | is the base address of the CAN controller. |
ui32ObjID | is the object number to configure (1-32). |
psMsgObject | is a pointer to a structure containing message object settings. |
eMsgType | indicates 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:
The message object pointed to by psMsgObject must be populated by the caller, as follows:
Example: To send a data frame or remote frame (in response to a remote request), take the following steps:
Example: To receive a specific data frame, take the following steps:
If you specify a message object buffer that already contains a message definition, it is overwritten.
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.
void CANMessageGet | ( | uint32_t | ui32Base, |
uint32_t | ui32ObjID, | ||
tCANMsgObject * | psMsgObject, | ||
bool | bClrPendingInt | ||
) |
Reads a CAN message from one of the message object buffers.
ui32Base | is the base address of the CAN controller. |
ui32ObjID | is the object number to read (1-32). |
psMsgObject | points to a structure containing message object fields. |
bClrPendingInt | indicates 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:
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.
void CANMessageClear | ( | uint32_t | ui32Base, |
uint32_t | ui32ObjID | ||
) |
Clears a message object so that it is no longer used.
ui32Base | is the base address of the CAN controller. |
ui32ObjID | is 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.
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.