123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- //*****************************************************************************
- //
- // can.h - Defines and Macros for the CAN controller.
- //
- // Copyright (c) 2006-2011 Texas Instruments Incorporated. All rights reserved.
- // Software License Agreement
- //
- // Texas Instruments (TI) is supplying this software for use solely and
- // exclusively on TI's microcontroller products. The software is owned by
- // TI and/or its suppliers, and is protected under applicable copyright
- // laws. You may not combine this software with "viral" open-source
- // software in order to form a larger program.
- //
- // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
- // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
- // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
- // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
- // DAMAGES, FOR ANY REASON WHATSOEVER.
- //
- // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
- //
- //*****************************************************************************
- #ifndef __CAN_H__
- #define __CAN_H__
- //*****************************************************************************
- //
- //! \addtogroup can_api
- //! @{
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // If building with a C++ compiler, make all of the definitions in this header
- // have a C binding.
- //
- //*****************************************************************************
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- //*****************************************************************************
- //
- // Miscellaneous defines for Message ID Types
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // These are the flags used by the tCANMsgObject.ulFlags value when calling the
- // CANMessageSet() and CANMessageGet() functions.
- //
- //*****************************************************************************
- //
- //! This definition is used with the tCANMsgObject ulFlags value and indicates
- //! that transmit interrupts should be enabled, or are enabled.
- //
- #define MSG_OBJ_TX_INT_ENABLE 0x00000001
- //
- //! This indicates that receive interrupts should be enabled, or are
- //! enabled.
- //
- #define MSG_OBJ_RX_INT_ENABLE 0x00000002
- //
- //! This indicates that a message object will use or is using an extended
- //! identifier.
- //
- #define MSG_OBJ_EXTENDED_ID 0x00000004
- //
- //! This indicates that a message object will use or is using filtering
- //! based on the object's message identifier.
- //
- #define MSG_OBJ_USE_ID_FILTER 0x00000008
- //
- //! This indicates that new data was available in the message object.
- //
- #define MSG_OBJ_NEW_DATA 0x00000080
- //
- //! This indicates that data was lost since this message object was last
- //! read.
- //
- #define MSG_OBJ_DATA_LOST 0x00000100
- //
- //! 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_DIR_FILTER (0x00000010 | 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_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER)
- //
- //! This indicates that a message object is a remote frame.
- //
- #define MSG_OBJ_REMOTE_FRAME 0x00000040
- //
- //! This indicates that this message object is part of a FIFO structure and
- //! not the final message object in a FIFO.
- //
- #define MSG_OBJ_FIFO 0x00000200
- //
- //! This indicates that a message object has no flags set.
- //
- #define MSG_OBJ_NO_FLAGS 0x00000000
- //*****************************************************************************
- //
- //! This define is used with the flag values to allow checking only status
- //! flags and not configuration flags.
- //
- //*****************************************************************************
- #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
- //*****************************************************************************
- //
- //! The structure used for encapsulating all the items associated with a CAN
- //! message object in the CAN controller.
- //
- //*****************************************************************************
- typedef struct
- {
- //
- //! The CAN message identifier used for 11 or 29 bit identifiers.
- //
- unsigned long ulMsgID;
- //
- //! The message identifier mask used when identifier filtering is enabled.
- //
- unsigned long ulMsgIDMask;
- //
- //! This value holds various status flags and settings specified by
- //! tCANObjFlags.
- //
- unsigned long ulFlags;
- //
- //! This value is the number of bytes of data in the message object.
- //
- unsigned long ulMsgLen;
- //
- //! This is a pointer to the message object's data.
- //
- unsigned char *pucMsgData;
- }
- tCANMsgObject;
- //*****************************************************************************
- //
- //! This structure is used for encapsulating the values associated with setting
- //! up the bit timing for a CAN controller. The structure is used when calling
- //! the CANGetBitTiming and CANSetBitTiming functions.
- //
- //*****************************************************************************
- typedef struct
- {
- //
- //! This value holds the sum of the Synchronization, Propagation, and Phase
- //! Buffer 1 segments, measured in time quanta. The valid values for this
- //! setting range from 2 to 16.
- //
- unsigned long ulSyncPropPhase1Seg;
- //
- //! This value holds the Phase Buffer 2 segment in time quanta. The valid
- //! values for this setting range from 1 to 8.
- //
- unsigned long ulPhase2Seg;
- //
- //! This value holds the Resynchronization Jump Width in time quanta. The
- //! valid values for this setting range from 1 to 4.
- //
- unsigned long ulSJW;
- //
- //! This value holds the CAN_CLK divider used to determine time quanta.
- //! The valid values for this setting range from 1 to 1023.
- //
- unsigned long ulQuantumPrescaler;
- }
- tCANBitClkParms;
- //*****************************************************************************
- //
- //! This data type is used to identify the interrupt status register. This is
- //! used when calling the CANIntStatus() function.
- //
- //*****************************************************************************
- typedef enum
- {
- //
- //! Read the CAN interrupt status information.
- //
- CAN_INT_STS_CAUSE,
- //
- //! Read a message object's interrupt status.
- //
- CAN_INT_STS_OBJECT
- }
- tCANIntStsReg;
- //*****************************************************************************
- //
- //! This data type is used to identify which of several status registers to
- //! read when calling the CANStatusGet() function.
- //
- //*****************************************************************************
- typedef enum
- {
- //
- //! Read the full CAN controller status.
- //
- CAN_STS_CONTROL,
- //
- //! Read the full 32-bit mask of message objects with a transmit request
- //! set.
- //
- CAN_STS_TXREQUEST,
- //
- //! Read the full 32-bit mask of message objects with new data available.
- //
- CAN_STS_NEWDAT,
- //
- //! Read the full 32-bit mask of message objects that are enabled.
- //
- CAN_STS_MSGVAL
- }
- tCANStsReg;
- //*****************************************************************************
- //
- // These definitions are used to specify interrupt sources to CANIntEnable()
- // and CANIntDisable().
- //
- //*****************************************************************************
- //
- //! This flag is used to allow a CAN controller to generate error
- //! interrupts.
- //
- #define CAN_INT_ERROR 0x00000008
- //
- //! This flag is used to allow a CAN controller to generate status
- //! interrupts.
- //
- #define CAN_INT_STATUS 0x00000004
- //
- //! 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_MASTER 0x00000002
- //*****************************************************************************
- //
- //! This definition is used to determine the type of message object that will
- //! be set up via a call to the CANMessageSet() API.
- //
- //*****************************************************************************
- typedef enum
- {
- //
- //! Transmit message object.
- //
- MSG_OBJ_TYPE_TX,
- //
- //! Transmit remote request message object
- //
- MSG_OBJ_TYPE_TX_REMOTE,
- //
- //! Receive message object.
- //
- MSG_OBJ_TYPE_RX,
- //
- //! Receive remote request message object.
- //
- MSG_OBJ_TYPE_RX_REMOTE,
- //
- //! Remote frame receive remote, with auto-transmit message object.
- //
- MSG_OBJ_TYPE_RXTX_REMOTE
- }
- tMsgObjType;
- //*****************************************************************************
- //
- // The following enumeration contains all error or status indicators that can
- // be returned when calling the CANStatusGet() function.
- //
- //*****************************************************************************
- //
- //! CAN controller has entered a Bus Off state.
- //
- #define CAN_STATUS_BUS_OFF 0x00000080
- //
- //! CAN controller error level has reached warning level.
- //
- #define CAN_STATUS_EWARN 0x00000040
- //
- //! CAN controller error level has reached error passive level.
- //
- #define CAN_STATUS_EPASS 0x00000020
- //
- //! A message was received successfully since the last read of this status.
- //
- #define CAN_STATUS_RXOK 0x00000010
- //
- //! A message was transmitted successfully since the last read of this
- //! status.
- //
- #define CAN_STATUS_TXOK 0x00000008
- //
- //! This is the mask for the last error code field.
- //
- #define CAN_STATUS_LEC_MSK 0x00000007
- //
- //! There was no error.
- //
- #define CAN_STATUS_LEC_NONE 0x00000000
- //
- //! A bit stuffing error has occurred.
- //
- #define CAN_STATUS_LEC_STUFF 0x00000001
- //
- //! A formatting error has occurred.
- //
- #define CAN_STATUS_LEC_FORM 0x00000002
- //
- //! An acknowledge error has occurred.
- //
- #define CAN_STATUS_LEC_ACK 0x00000003
- //
- //! The bus remained a bit level of 1 for longer than is allowed.
- //
- #define CAN_STATUS_LEC_BIT1 0x00000004
- //
- //! The bus remained a bit level of 0 for longer than is allowed.
- //
- #define CAN_STATUS_LEC_BIT0 0x00000005
- //
- //! A CRC error has occurred.
- //
- #define CAN_STATUS_LEC_CRC 0x00000006
- //
- //! This is the mask for the CAN Last Error Code (LEC).
- //
- #define CAN_STATUS_LEC_MASK 0x00000007
- //*****************************************************************************
- //
- // API Function prototypes
- //
- //*****************************************************************************
- extern void CANBitTimingGet(unsigned long ulBase, tCANBitClkParms *pClkParms);
- extern void CANBitTimingSet(unsigned long ulBase, tCANBitClkParms *pClkParms);
- extern unsigned long CANBitRateSet(unsigned long ulBase,
- unsigned long ulSourceClock,
- unsigned long ulBitRate);
- extern void CANDisable(unsigned long ulBase);
- extern void CANEnable(unsigned long ulBase);
- extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount,
- unsigned long *pulTxCount);
- extern void CANInit(unsigned long ulBase);
- extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr);
- extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
- extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
- extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
- extern unsigned long CANIntStatus(unsigned long ulBase,
- tCANIntStsReg eIntStsReg);
- extern void CANIntUnregister(unsigned long ulBase);
- extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID);
- extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID,
- tCANMsgObject *pMsgObject, tBoolean bClrPendingInt);
- extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID,
- tCANMsgObject *pMsgObject, tMsgObjType eMsgType);
- extern tBoolean CANRetryGet(unsigned long ulBase);
- extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry);
- extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg);
- //*****************************************************************************
- //
- // Several CAN APIs have been renamed, with the original function name being
- // deprecated. These defines provide backward compatibility.
- //
- //*****************************************************************************
- #ifndef DEPRECATED
- #define CANSetBitTiming(a, b) CANBitTimingSet(a, b)
- #define CANGetBitTiming(a, b) CANBitTimingGet(a, b)
- #endif
- //*****************************************************************************
- //
- // Mark the end of the C bindings section for C++ compilers.
- //
- //*****************************************************************************
- #ifdef __cplusplus
- }
- #endif
- //*****************************************************************************
- //
- // Close the Doxygen group.
- //! @}
- //
- //*****************************************************************************
- #endif // __CAN_H__
|