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