1 //*****************************************************************************
\r
3 // can.h - Defines and Macros for the CAN controller.
\r
5 // Copyright (c) 2006-2007 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. Any use in violation
\r
14 // of the foregoing restrictions may subject the user to criminal sanctions
\r
15 // under applicable laws, as well as to civil liability for the breach of the
\r
16 // terms and conditions of this license.
\r
18 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
\r
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
\r
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
\r
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
\r
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
\r
24 // This is part of revision 1408 of the Stellaris Peripheral Driver Library.
\r
26 //*****************************************************************************
\r
36 //*****************************************************************************
\r
38 //! \addtogroup can_api
\r
41 //*****************************************************************************
\r
43 //*****************************************************************************
\r
45 // Miscellaneous defines for Message ID Types
\r
47 //*****************************************************************************
\r
49 //*****************************************************************************
\r
51 //! These are the flags used by the tCANMsgObject variable when calling the
\r
52 //! the CANMessageSet() and CANMessageGet() APIs.
\r
54 //*****************************************************************************
\r
58 //! This indicates that transmit interrupts should be enabled, or are
\r
61 MSG_OBJ_TX_INT_ENABLE = 0x00000001,
\r
64 //! This indicates that receive interrupts should be enabled or are
\r
67 MSG_OBJ_RX_INT_ENABLE = 0x00000002,
\r
70 //! This indicates that a message object will use or is using an extended
\r
73 MSG_OBJ_EXTENDED_ID = 0x00000004,
\r
76 //! This indicates that a message object will use or is using filtering
\r
77 //! based on the object's message Identifier.
\r
79 MSG_OBJ_USE_ID_FILTER = 0x00000008,
\r
82 //! This indicates that new data was available in the message object.
\r
84 MSG_OBJ_NEW_DATA = 0x00000080,
\r
87 //! This indicates that data was lost since this message object was last
\r
90 MSG_OBJ_DATA_LOST = 0x00000100,
\r
93 //! This indicates that a message object will use or is using filtering
\r
94 //! based on the direction of the transfer. If the direction filtering is
\r
95 //! used then ID filtering must also be enabled.
\r
97 MSG_OBJ_USE_DIR_FILTER = (0x00000010 | MSG_OBJ_USE_ID_FILTER),
\r
100 //! This indicates that a message object will use or is using message
\r
101 //! identifier filtering based of the the extended identifier.
\r
102 //! If the extended identifier filtering is used then ID filtering must
\r
103 //! also be enabled.
\r
105 MSG_OBJ_USE_EXT_FILTER = (0x00000020 | MSG_OBJ_USE_ID_FILTER),
\r
108 //! This indicates that a message object is a remote frame.
\r
110 MSG_OBJ_REMOTE_FRAME = 0x00000040,
\r
113 //! This indicates that a message object has no flags set.
\r
115 MSG_OBJ_NO_FLAGS = 0x00000000
\r
119 //*****************************************************************************
\r
121 //! This define is used with the #tCANObjFlags enumerated values to allow
\r
122 //! checking only status flags and not configuration flags.
\r
124 //*****************************************************************************
\r
125 #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
\r
127 //*****************************************************************************
\r
129 //! This structure used for encapsulating all the items associated with a CAN
\r
130 //! message object in the CAN controller.
\r
132 //*****************************************************************************
\r
136 //! The CAN message identifier used for 11 or 29 bit identifiers.
\r
138 unsigned long ulMsgID;
\r
141 //! The message identifier mask used when identifier filtering is enabled.
\r
143 unsigned long ulMsgIDMask;
\r
146 //! This value holds various status flags and settings specified by
\r
149 unsigned long ulFlags;
\r
152 //! This value is the number of bytes of data in the message object.
\r
154 unsigned long ulMsgLen;
\r
157 //! This is a pointer to the message object's data.
\r
159 unsigned char *pucMsgData;
\r
163 //*****************************************************************************
\r
165 //! This structure is used for encapsulating the values associated with setting
\r
166 //! up the bit timing for a CAN controller. The structure is used when calling
\r
167 //! the CANGetBitTiming and CANSetBitTiming functions.
\r
169 //*****************************************************************************
\r
173 //! This value holds the sum of the Synchronization, Propagation, and Phase
\r
174 //! Buffer 1 segments, measured in time quanta. The valid values for this
\r
175 //! setting range from 2 to 16.
\r
177 unsigned int uSyncPropPhase1Seg;
\r
180 //! This value holds the Phase Buffer 2 segment in time quanta. The valid
\r
181 //! values for this setting range from 1 to 8.
\r
183 unsigned int uPhase2Seg;
\r
186 //! This value holds the Resynchronization Jump Width in time quanta. The
\r
187 //! valid values for this setting range from 1 to 4.
\r
192 //! This value holds the CAN_CLK divider used to determine time quanta.
\r
193 //! The valid values for this setting range from 1 to 1023.
\r
195 unsigned int uQuantumPrescaler;
\r
200 //*****************************************************************************
\r
202 //! This data type is used to identify the interrupt status register. This is
\r
203 //! used when calling the a CANIntStatus() function.
\r
205 //*****************************************************************************
\r
209 //! Read the CAN interrupt status information.
\r
214 //! Read a message object's interrupt status.
\r
220 //*****************************************************************************
\r
222 //! This data type is used to identify which of the several status registers
\r
223 //! to read when calling the CANStatusGet() function.
\r
225 //*****************************************************************************
\r
229 //! Read the full CAN controller status.
\r
234 //! Read the full 32 bit mask of message objects with a transmit request
\r
240 //! Read the full 32 bit mask of message objects with a new data available.
\r
245 //! Read the full 32 bit mask of message objects that are enabled.
\r
251 //*****************************************************************************
\r
253 //! These definitions are used to specify interrupt sources to CANIntEnable()
\r
254 //! and CANIntDisable().
\r
256 //*****************************************************************************
\r
260 //! This flag is used to allow a CAN controller to generate error
\r
263 CAN_INT_ERROR = 0x00000008,
\r
266 //! This flag is used to allow a CAN controller to generate status
\r
269 CAN_INT_STATUS = 0x00000004,
\r
272 //! This flag is used to allow a CAN controller to generate any CAN
\r
273 //! interrupts. If this is not set then no interrupts will be generated by
\r
274 //! the CAN controller.
\r
276 CAN_INT_MASTER = 0x00000002
\r
280 //*****************************************************************************
\r
282 //! This definition is used to determine the type of message object that will
\r
283 //! be set up via a call to the CANMessageSet() API.
\r
285 //*****************************************************************************
\r
289 //! Transmit message object.
\r
294 //! Transmit remote request message object
\r
296 MSG_OBJ_TYPE_TX_REMOTE,
\r
299 //! Receive message object.
\r
304 //! Receive remote request message object.
\r
306 MSG_OBJ_TYPE_RX_REMOTE,
\r
309 //! Remote frame receive remote, with auto-transmit message object.
\r
311 MSG_OBJ_TYPE_RXTX_REMOTE
\r
315 //*****************************************************************************
\r
317 //! The following enumeration contains all error or status indicators that
\r
318 //! can be returned when calling the CANStatusGet() API.
\r
320 //*****************************************************************************
\r
324 //! CAN controller has entered a Bus Off state.
\r
326 CAN_STATUS_BUS_OFF = 0x00000080,
\r
329 //! CAN controller error level has reached warning level.
\r
331 CAN_STATUS_EWARN = 0x00000040,
\r
334 //! CAN controller error level has reached error passive level.
\r
336 CAN_STATUS_EPASS = 0x00000020,
\r
339 //! A message was received successfully since the last read of this status.
\r
341 CAN_STATUS_RXOK = 0x00000010,
\r
344 //! A message was transmitted successfully since the last read of this
\r
347 CAN_STATUS_TXOK = 0x00000008,
\r
350 //! This is the mask for the last error code field.
\r
352 CAN_STATUS_LEC_MSK = 0x00000007,
\r
355 //! There was no error.
\r
357 CAN_STATUS_LEC_NONE = 0x00000000,
\r
360 //! A bit stuffing error has occurred.
\r
362 CAN_STATUS_LEC_STUFF = 0x00000001,
\r
365 //! A formatting error has occurred.
\r
367 CAN_STATUS_LEC_FORM = 0x00000002,
\r
370 //! An acknowledge error has occurred.
\r
372 CAN_STATUS_LEC_ACK = 0x00000003,
\r
375 //! The bus remained a bit level of 1 for longer than is allowed.
\r
377 CAN_STATUS_LEC_BIT1 = 0x00000004,
\r
380 //! The bus remained a bit level of 0 for longer than is allowed.
\r
382 CAN_STATUS_LEC_BIT0 = 0x00000005,
\r
385 //! A CRC error has occurred.
\r
387 CAN_STATUS_LEC_CRC = 0x00000006,
\r
390 //! This is the mask for the CAN Last Error Code (LEC).
\r
392 CAN_STATUS_LEC_MASK = 0x00000007
\r
396 //*****************************************************************************
\r
398 // API Function prototypes
\r
400 //*****************************************************************************
\r
401 extern void CANInit(unsigned long ulBase);
\r
402 extern void CANEnable(unsigned long ulBase);
\r
403 extern void CANDisable(unsigned long ulBase);
\r
404 extern void CANSetBitTiming(unsigned long ulBase, tCANBitClkParms *pClkParms);
\r
405 extern void CANGetBitTiming(unsigned long ulBase, tCANBitClkParms *pClkParms);
\r
406 extern unsigned long CANReadReg(unsigned long ulRegAddress);
\r
407 extern void CANWriteReg(unsigned long ulRegAddress, unsigned long ulRegValue);
\r
408 extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID,
\r
409 tCANMsgObject *pMsgObject, tMsgObjType eMsgType);
\r
410 extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID,
\r
411 tCANMsgObject *pMsgObject, tBoolean bClrPendingInt);
\r
412 extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg);
\r
413 extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID);
\r
414 extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
\r
415 extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
\r
416 extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
\r
417 extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr);
\r
418 extern unsigned long CANIntStatus(unsigned long ulBase,
\r
419 tCANIntStsReg eIntStsReg);
\r
420 extern tBoolean CANRetryGet(unsigned long ulBase);
\r
421 extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry);
\r
422 extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount,
\r
423 unsigned long *pulTxCount);
\r
424 extern long CANGetIntNumber(unsigned long ulBase);
\r
425 extern void CANReadDataReg(unsigned char *pucData, unsigned long *pulRegister,
\r
427 extern void CANWriteDataReg(unsigned char *pucData, unsigned long *pulRegister,
\r
430 //*****************************************************************************
\r
432 // Close the Doxygen group.
\r
435 //*****************************************************************************
\r
441 #endif // __CAN_H__
\r