1 //*****************************************************************************
3 // can.h - Defines and Macros for the CAN controller.
5 // Copyright (c) 2006-2008 Luminary Micro, Inc. All rights reserved.
7 // Software License Agreement
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10 // exclusively on LMI's microcontroller products.
12 // The software is owned by LMI and/or its suppliers, and is protected under
13 // applicable copyright laws. All rights are reserved. You may not combine
14 // this software with "viral" open-source software in order to form a larger
15 // program. Any use in violation of the foregoing restrictions may subject
16 // the user to criminal sanctions under applicable laws, as well as to civil
17 // liability for the breach of the terms and conditions of this license.
19 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
20 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
22 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
23 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
25 // This is part of revision 2523 of the Stellaris Peripheral Driver Library.
27 //*****************************************************************************
32 //*****************************************************************************
34 //! \addtogroup can_api
37 //*****************************************************************************
39 //*****************************************************************************
41 // If building with a C++ compiler, make all of the definitions in this header
44 //*****************************************************************************
50 //*****************************************************************************
52 // Miscellaneous defines for Message ID Types
54 //*****************************************************************************
56 //*****************************************************************************
58 //! These are the flags used by the tCANMsgObject variable when calling the
59 //! CANMessageSet() and CANMessageGet() functions.
61 //*****************************************************************************
65 //! This indicates that transmit interrupts should be enabled, or are
68 MSG_OBJ_TX_INT_ENABLE = 0x00000001,
71 //! This indicates that receive interrupts should be enabled, or are
74 MSG_OBJ_RX_INT_ENABLE = 0x00000002,
77 //! This indicates that a message object will use or is using an extended
80 MSG_OBJ_EXTENDED_ID = 0x00000004,
83 //! This indicates that a message object will use or is using filtering
84 //! based on the object's message identifier.
86 MSG_OBJ_USE_ID_FILTER = 0x00000008,
89 //! This indicates that new data was available in the message object.
91 MSG_OBJ_NEW_DATA = 0x00000080,
94 //! This indicates that data was lost since this message object was last
97 MSG_OBJ_DATA_LOST = 0x00000100,
100 //! This indicates that a message object will use or is using filtering
101 //! based on the direction of the transfer. If the direction filtering is
102 //! used, then ID filtering must also be enabled.
104 MSG_OBJ_USE_DIR_FILTER = (0x00000010 | MSG_OBJ_USE_ID_FILTER),
107 //! This indicates that a message object will use or is using message
108 //! identifier filtering based on the extended identifier. If the extended
109 //! identifier filtering is used, then ID filtering must also be enabled.
111 MSG_OBJ_USE_EXT_FILTER = (0x00000020 | MSG_OBJ_USE_ID_FILTER),
114 //! This indicates that a message object is a remote frame.
116 MSG_OBJ_REMOTE_FRAME = 0x00000040,
119 //! This indicates that a message object has no flags set.
121 MSG_OBJ_NO_FLAGS = 0x00000000
125 //*****************************************************************************
127 //! This define is used with the #tCANObjFlags enumerated values to allow
128 //! checking only status flags and not configuration flags.
130 //*****************************************************************************
131 #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
133 //*****************************************************************************
135 //! The structure used for encapsulating all the items associated with a CAN
136 //! message object in the CAN controller.
138 //*****************************************************************************
142 //! The CAN message identifier used for 11 or 29 bit identifiers.
144 unsigned long ulMsgID;
147 //! The message identifier mask used when identifier filtering is enabled.
149 unsigned long ulMsgIDMask;
152 //! This value holds various status flags and settings specified by
155 unsigned long ulFlags;
158 //! This value is the number of bytes of data in the message object.
160 unsigned long ulMsgLen;
163 //! This is a pointer to the message object's data.
165 unsigned char *pucMsgData;
169 //*****************************************************************************
171 //! This structure is used for encapsulating the values associated with setting
172 //! up the bit timing for a CAN controller. The structure is used when calling
173 //! the CANGetBitTiming and CANSetBitTiming functions.
175 //*****************************************************************************
179 //! This value holds the sum of the Synchronization, Propagation, and Phase
180 //! Buffer 1 segments, measured in time quanta. The valid values for this
181 //! setting range from 2 to 16.
183 unsigned int uSyncPropPhase1Seg;
186 //! This value holds the Phase Buffer 2 segment in time quanta. The valid
187 //! values for this setting range from 1 to 8.
189 unsigned int uPhase2Seg;
192 //! This value holds the Resynchronization Jump Width in time quanta. The
193 //! valid values for this setting range from 1 to 4.
198 //! This value holds the CAN_CLK divider used to determine time quanta.
199 //! The valid values for this setting range from 1 to 1023.
201 unsigned int uQuantumPrescaler;
206 //*****************************************************************************
208 //! This data type is used to identify the interrupt status register. This is
209 //! used when calling the CANIntStatus() function.
211 //*****************************************************************************
215 //! Read the CAN interrupt status information.
220 //! Read a message object's interrupt status.
226 //*****************************************************************************
228 //! This data type is used to identify which of several status registers to
229 //! read when calling the CANStatusGet() function.
231 //*****************************************************************************
235 //! Read the full CAN controller status.
240 //! Read the full 32-bit mask of message objects with a transmit request
246 //! Read the full 32-bit mask of message objects with new data available.
251 //! Read the full 32-bit mask of message objects that are enabled.
257 //*****************************************************************************
259 //! These definitions are used to specify interrupt sources to CANIntEnable()
260 //! and CANIntDisable().
262 //*****************************************************************************
266 //! This flag is used to allow a CAN controller to generate error
269 CAN_INT_ERROR = 0x00000008,
272 //! This flag is used to allow a CAN controller to generate status
275 CAN_INT_STATUS = 0x00000004,
278 //! This flag is used to allow a CAN controller to generate any CAN
279 //! interrupts. If this is not set, then no interrupts will be generated
280 //! by the CAN controller.
282 CAN_INT_MASTER = 0x00000002
286 //*****************************************************************************
288 //! This definition is used to determine the type of message object that will
289 //! be set up via a call to the CANMessageSet() API.
291 //*****************************************************************************
295 //! Transmit message object.
300 //! Transmit remote request message object
302 MSG_OBJ_TYPE_TX_REMOTE,
305 //! Receive message object.
310 //! Receive remote request message object.
312 MSG_OBJ_TYPE_RX_REMOTE,
315 //! Remote frame receive remote, with auto-transmit message object.
317 MSG_OBJ_TYPE_RXTX_REMOTE
321 //*****************************************************************************
323 //! The following enumeration contains all error or status indicators that can
324 //! be returned when calling the CANStatusGet() function.
326 //*****************************************************************************
330 //! CAN controller has entered a Bus Off state.
332 CAN_STATUS_BUS_OFF = 0x00000080,
335 //! CAN controller error level has reached warning level.
337 CAN_STATUS_EWARN = 0x00000040,
340 //! CAN controller error level has reached error passive level.
342 CAN_STATUS_EPASS = 0x00000020,
345 //! A message was received successfully since the last read of this status.
347 CAN_STATUS_RXOK = 0x00000010,
350 //! A message was transmitted successfully since the last read of this
353 CAN_STATUS_TXOK = 0x00000008,
356 //! This is the mask for the last error code field.
358 CAN_STATUS_LEC_MSK = 0x00000007,
361 //! There was no error.
363 CAN_STATUS_LEC_NONE = 0x00000000,
366 //! A bit stuffing error has occurred.
368 CAN_STATUS_LEC_STUFF = 0x00000001,
371 //! A formatting error has occurred.
373 CAN_STATUS_LEC_FORM = 0x00000002,
376 //! An acknowledge error has occurred.
378 CAN_STATUS_LEC_ACK = 0x00000003,
381 //! The bus remained a bit level of 1 for longer than is allowed.
383 CAN_STATUS_LEC_BIT1 = 0x00000004,
386 //! The bus remained a bit level of 0 for longer than is allowed.
388 CAN_STATUS_LEC_BIT0 = 0x00000005,
391 //! A CRC error has occurred.
393 CAN_STATUS_LEC_CRC = 0x00000006,
396 //! This is the mask for the CAN Last Error Code (LEC).
398 CAN_STATUS_LEC_MASK = 0x00000007
402 //*****************************************************************************
404 // API Function prototypes
406 //*****************************************************************************
407 extern void CANInit(unsigned long ulBase);
408 extern void CANEnable(unsigned long ulBase);
409 extern void CANDisable(unsigned long ulBase);
410 extern void CANSetBitTiming(unsigned long ulBase, tCANBitClkParms *pClkParms);
411 extern void CANGetBitTiming(unsigned long ulBase, tCANBitClkParms *pClkParms);
412 extern unsigned long CANReadReg(unsigned long ulRegAddress);
413 extern void CANWriteReg(unsigned long ulRegAddress, unsigned long ulRegValue);
414 extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID,
415 tCANMsgObject *pMsgObject, tMsgObjType eMsgType);
416 extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID,
417 tCANMsgObject *pMsgObject, tBoolean bClrPendingInt);
418 extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg);
419 extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID);
420 extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
421 extern void CANIntUnregister(unsigned long ulBase);
422 extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
423 extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
424 extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr);
425 extern unsigned long CANIntStatus(unsigned long ulBase,
426 tCANIntStsReg eIntStsReg);
427 extern tBoolean CANRetryGet(unsigned long ulBase);
428 extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry);
429 extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount,
430 unsigned long *pulTxCount);
431 extern long CANGetIntNumber(unsigned long ulBase);
432 extern void CANReadDataReg(unsigned char *pucData, unsigned long *pulRegister,
434 extern void CANWriteDataReg(unsigned char *pucData, unsigned long *pulRegister,
437 //*****************************************************************************
439 // Mark the end of the C bindings section for C++ compilers.
441 //*****************************************************************************
446 //*****************************************************************************
448 // Close the Doxygen group.
451 //*****************************************************************************