Tiva Driver Lib
|
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 should be enabled, or are enabled. | |
#define | MSG_OBJ_RX_INT_ENABLE 0x00000002 |
#define | MSG_OBJ_EXTENDED_ID 0x00000004 |
#define | MSG_OBJ_USE_ID_FILTER 0x00000008 |
#define | MSG_OBJ_NEW_DATA 0x00000080 |
This indicates that new data was available in the message object. | |
#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. | |
#define | MSG_OBJ_FIFO 0x00000200 |
#define | MSG_OBJ_NO_FLAGS 0x00000000 |
This indicates that a message object has no flags set. | |
#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. | |
#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 |
#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). | |
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_BIT_VALUE | ( | seg1, | |
seg2, | |||
sjw | |||
) |
#define CAN_INT_ERROR 0x00000008 |
This flag is used to allow a CAN controller to generate error 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 will be generated by the CAN controller.
#define CAN_INT_STATUS 0x00000004 |
This flag is used to allow a CAN controller to generate status interrupts.
#define CAN_STATUS_TXOK 0x00000008 |
A message was transmitted successfully since the last read of this status.
#define MSG_OBJ_DATA_LOST 0x00000100 |
This indicates that data was lost since this message object was last read.
#define MSG_OBJ_EXTENDED_ID 0x00000004 |
This indicates that a message object will use or is using an extended identifier.
#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.
#define MSG_OBJ_RX_INT_ENABLE 0x00000002 |
This indicates that receive interrupts should be enabled, or are enabled.
#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 MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER) |
This indicates that a message object will use or is using filtering based on the direction of the transfer. If the direction filtering is used, then ID filtering must also be enabled.
#define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER) |
This indicates that a message object will use 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.
#define MSG_OBJ_USE_ID_FILTER 0x00000008 |
This indicates that a message object will use or is using filtering based on the object's message identifier.
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 will be set up via a call to the CANMessageSet() API.
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 should 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 int16_t. 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.
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.
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.
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.
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() should have been called to initialize the controller and the CAN bus clock should be configured by calling CANBitTimingSet().
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.
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.
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 should be one of the following values:
It is not necessary to use this function to clear an interrupt. This function should only be 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().
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.
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 will generate 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.
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() should be used to enable CAN interrupts on the interrupt controller.
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 should be 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.
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.
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.
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:
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.
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.
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.
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 should be 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: