1 |
610 |
jeremybenn |
//*****************************************************************************
|
2 |
|
|
//
|
3 |
|
|
// can.h - Defines and Macros for the CAN controller.
|
4 |
|
|
//
|
5 |
|
|
// Copyright (c) 2006-2008 Luminary Micro, Inc. All rights reserved.
|
6 |
|
|
//
|
7 |
|
|
// Software License Agreement
|
8 |
|
|
//
|
9 |
|
|
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
|
10 |
|
|
// exclusively on LMI's microcontroller products.
|
11 |
|
|
//
|
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.
|
18 |
|
|
//
|
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.
|
24 |
|
|
//
|
25 |
|
|
// This is part of revision 2523 of the Stellaris Peripheral Driver Library.
|
26 |
|
|
//
|
27 |
|
|
//*****************************************************************************
|
28 |
|
|
|
29 |
|
|
#ifndef __CAN_H__
|
30 |
|
|
#define __CAN_H__
|
31 |
|
|
|
32 |
|
|
//*****************************************************************************
|
33 |
|
|
//
|
34 |
|
|
//! \addtogroup can_api
|
35 |
|
|
//! @{
|
36 |
|
|
//
|
37 |
|
|
//*****************************************************************************
|
38 |
|
|
|
39 |
|
|
//*****************************************************************************
|
40 |
|
|
//
|
41 |
|
|
// If building with a C++ compiler, make all of the definitions in this header
|
42 |
|
|
// have a C binding.
|
43 |
|
|
//
|
44 |
|
|
//*****************************************************************************
|
45 |
|
|
#ifdef __cplusplus
|
46 |
|
|
extern "C"
|
47 |
|
|
{
|
48 |
|
|
#endif
|
49 |
|
|
|
50 |
|
|
//*****************************************************************************
|
51 |
|
|
//
|
52 |
|
|
// Miscellaneous defines for Message ID Types
|
53 |
|
|
//
|
54 |
|
|
//*****************************************************************************
|
55 |
|
|
|
56 |
|
|
//*****************************************************************************
|
57 |
|
|
//
|
58 |
|
|
//! These are the flags used by the tCANMsgObject variable when calling the
|
59 |
|
|
//! CANMessageSet() and CANMessageGet() functions.
|
60 |
|
|
//
|
61 |
|
|
//*****************************************************************************
|
62 |
|
|
typedef enum
|
63 |
|
|
{
|
64 |
|
|
//
|
65 |
|
|
//! This indicates that transmit interrupts should be enabled, or are
|
66 |
|
|
//! enabled.
|
67 |
|
|
//
|
68 |
|
|
MSG_OBJ_TX_INT_ENABLE = 0x00000001,
|
69 |
|
|
|
70 |
|
|
//
|
71 |
|
|
//! This indicates that receive interrupts should be enabled, or are
|
72 |
|
|
//! enabled.
|
73 |
|
|
//
|
74 |
|
|
MSG_OBJ_RX_INT_ENABLE = 0x00000002,
|
75 |
|
|
|
76 |
|
|
//
|
77 |
|
|
//! This indicates that a message object will use or is using an extended
|
78 |
|
|
//! identifier.
|
79 |
|
|
//
|
80 |
|
|
MSG_OBJ_EXTENDED_ID = 0x00000004,
|
81 |
|
|
|
82 |
|
|
//
|
83 |
|
|
//! This indicates that a message object will use or is using filtering
|
84 |
|
|
//! based on the object's message identifier.
|
85 |
|
|
//
|
86 |
|
|
MSG_OBJ_USE_ID_FILTER = 0x00000008,
|
87 |
|
|
|
88 |
|
|
//
|
89 |
|
|
//! This indicates that new data was available in the message object.
|
90 |
|
|
//
|
91 |
|
|
MSG_OBJ_NEW_DATA = 0x00000080,
|
92 |
|
|
|
93 |
|
|
//
|
94 |
|
|
//! This indicates that data was lost since this message object was last
|
95 |
|
|
//! read.
|
96 |
|
|
//
|
97 |
|
|
MSG_OBJ_DATA_LOST = 0x00000100,
|
98 |
|
|
|
99 |
|
|
//
|
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.
|
103 |
|
|
//
|
104 |
|
|
MSG_OBJ_USE_DIR_FILTER = (0x00000010 | MSG_OBJ_USE_ID_FILTER),
|
105 |
|
|
|
106 |
|
|
//
|
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.
|
110 |
|
|
//
|
111 |
|
|
MSG_OBJ_USE_EXT_FILTER = (0x00000020 | MSG_OBJ_USE_ID_FILTER),
|
112 |
|
|
|
113 |
|
|
//
|
114 |
|
|
//! This indicates that a message object is a remote frame.
|
115 |
|
|
//
|
116 |
|
|
MSG_OBJ_REMOTE_FRAME = 0x00000040,
|
117 |
|
|
|
118 |
|
|
//
|
119 |
|
|
//! This indicates that a message object has no flags set.
|
120 |
|
|
//
|
121 |
|
|
MSG_OBJ_NO_FLAGS = 0x00000000
|
122 |
|
|
}
|
123 |
|
|
tCANObjFlags;
|
124 |
|
|
|
125 |
|
|
//*****************************************************************************
|
126 |
|
|
//
|
127 |
|
|
//! This define is used with the #tCANObjFlags enumerated values to allow
|
128 |
|
|
//! checking only status flags and not configuration flags.
|
129 |
|
|
//
|
130 |
|
|
//*****************************************************************************
|
131 |
|
|
#define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
|
132 |
|
|
|
133 |
|
|
//*****************************************************************************
|
134 |
|
|
//
|
135 |
|
|
//! The structure used for encapsulating all the items associated with a CAN
|
136 |
|
|
//! message object in the CAN controller.
|
137 |
|
|
//
|
138 |
|
|
//*****************************************************************************
|
139 |
|
|
typedef struct
|
140 |
|
|
{
|
141 |
|
|
//
|
142 |
|
|
//! The CAN message identifier used for 11 or 29 bit identifiers.
|
143 |
|
|
//
|
144 |
|
|
unsigned long ulMsgID;
|
145 |
|
|
|
146 |
|
|
//
|
147 |
|
|
//! The message identifier mask used when identifier filtering is enabled.
|
148 |
|
|
//
|
149 |
|
|
unsigned long ulMsgIDMask;
|
150 |
|
|
|
151 |
|
|
//
|
152 |
|
|
//! This value holds various status flags and settings specified by
|
153 |
|
|
//! tCANObjFlags.
|
154 |
|
|
//
|
155 |
|
|
unsigned long ulFlags;
|
156 |
|
|
|
157 |
|
|
//
|
158 |
|
|
//! This value is the number of bytes of data in the message object.
|
159 |
|
|
//
|
160 |
|
|
unsigned long ulMsgLen;
|
161 |
|
|
|
162 |
|
|
//
|
163 |
|
|
//! This is a pointer to the message object's data.
|
164 |
|
|
//
|
165 |
|
|
unsigned char *pucMsgData;
|
166 |
|
|
}
|
167 |
|
|
tCANMsgObject;
|
168 |
|
|
|
169 |
|
|
//*****************************************************************************
|
170 |
|
|
//
|
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.
|
174 |
|
|
//
|
175 |
|
|
//*****************************************************************************
|
176 |
|
|
typedef struct
|
177 |
|
|
{
|
178 |
|
|
//
|
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.
|
182 |
|
|
//
|
183 |
|
|
unsigned int uSyncPropPhase1Seg;
|
184 |
|
|
|
185 |
|
|
//
|
186 |
|
|
//! This value holds the Phase Buffer 2 segment in time quanta. The valid
|
187 |
|
|
//! values for this setting range from 1 to 8.
|
188 |
|
|
//
|
189 |
|
|
unsigned int uPhase2Seg;
|
190 |
|
|
|
191 |
|
|
//
|
192 |
|
|
//! This value holds the Resynchronization Jump Width in time quanta. The
|
193 |
|
|
//! valid values for this setting range from 1 to 4.
|
194 |
|
|
//
|
195 |
|
|
unsigned int uSJW;
|
196 |
|
|
|
197 |
|
|
//
|
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.
|
200 |
|
|
//
|
201 |
|
|
unsigned int uQuantumPrescaler;
|
202 |
|
|
|
203 |
|
|
}
|
204 |
|
|
tCANBitClkParms;
|
205 |
|
|
|
206 |
|
|
//*****************************************************************************
|
207 |
|
|
//
|
208 |
|
|
//! This data type is used to identify the interrupt status register. This is
|
209 |
|
|
//! used when calling the CANIntStatus() function.
|
210 |
|
|
//
|
211 |
|
|
//*****************************************************************************
|
212 |
|
|
typedef enum
|
213 |
|
|
{
|
214 |
|
|
//
|
215 |
|
|
//! Read the CAN interrupt status information.
|
216 |
|
|
//
|
217 |
|
|
CAN_INT_STS_CAUSE,
|
218 |
|
|
|
219 |
|
|
//
|
220 |
|
|
//! Read a message object's interrupt status.
|
221 |
|
|
//
|
222 |
|
|
CAN_INT_STS_OBJECT
|
223 |
|
|
}
|
224 |
|
|
tCANIntStsReg;
|
225 |
|
|
|
226 |
|
|
//*****************************************************************************
|
227 |
|
|
//
|
228 |
|
|
//! This data type is used to identify which of several status registers to
|
229 |
|
|
//! read when calling the CANStatusGet() function.
|
230 |
|
|
//
|
231 |
|
|
//*****************************************************************************
|
232 |
|
|
typedef enum
|
233 |
|
|
{
|
234 |
|
|
//
|
235 |
|
|
//! Read the full CAN controller status.
|
236 |
|
|
//
|
237 |
|
|
CAN_STS_CONTROL,
|
238 |
|
|
|
239 |
|
|
//
|
240 |
|
|
//! Read the full 32-bit mask of message objects with a transmit request
|
241 |
|
|
//! set.
|
242 |
|
|
//
|
243 |
|
|
CAN_STS_TXREQUEST,
|
244 |
|
|
|
245 |
|
|
//
|
246 |
|
|
//! Read the full 32-bit mask of message objects with new data available.
|
247 |
|
|
//
|
248 |
|
|
CAN_STS_NEWDAT,
|
249 |
|
|
|
250 |
|
|
//
|
251 |
|
|
//! Read the full 32-bit mask of message objects that are enabled.
|
252 |
|
|
//
|
253 |
|
|
CAN_STS_MSGVAL
|
254 |
|
|
}
|
255 |
|
|
tCANStsReg;
|
256 |
|
|
|
257 |
|
|
//*****************************************************************************
|
258 |
|
|
//
|
259 |
|
|
//! These definitions are used to specify interrupt sources to CANIntEnable()
|
260 |
|
|
//! and CANIntDisable().
|
261 |
|
|
//
|
262 |
|
|
//*****************************************************************************
|
263 |
|
|
typedef enum
|
264 |
|
|
{
|
265 |
|
|
//
|
266 |
|
|
//! This flag is used to allow a CAN controller to generate error
|
267 |
|
|
//! interrupts.
|
268 |
|
|
//
|
269 |
|
|
CAN_INT_ERROR = 0x00000008,
|
270 |
|
|
|
271 |
|
|
//
|
272 |
|
|
//! This flag is used to allow a CAN controller to generate status
|
273 |
|
|
//! interrupts.
|
274 |
|
|
//
|
275 |
|
|
CAN_INT_STATUS = 0x00000004,
|
276 |
|
|
|
277 |
|
|
//
|
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.
|
281 |
|
|
//
|
282 |
|
|
CAN_INT_MASTER = 0x00000002
|
283 |
|
|
}
|
284 |
|
|
tCANIntFlags;
|
285 |
|
|
|
286 |
|
|
//*****************************************************************************
|
287 |
|
|
//
|
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.
|
290 |
|
|
//
|
291 |
|
|
//*****************************************************************************
|
292 |
|
|
typedef enum
|
293 |
|
|
{
|
294 |
|
|
//
|
295 |
|
|
//! Transmit message object.
|
296 |
|
|
//
|
297 |
|
|
MSG_OBJ_TYPE_TX,
|
298 |
|
|
|
299 |
|
|
//
|
300 |
|
|
//! Transmit remote request message object
|
301 |
|
|
//
|
302 |
|
|
MSG_OBJ_TYPE_TX_REMOTE,
|
303 |
|
|
|
304 |
|
|
//
|
305 |
|
|
//! Receive message object.
|
306 |
|
|
//
|
307 |
|
|
MSG_OBJ_TYPE_RX,
|
308 |
|
|
|
309 |
|
|
//
|
310 |
|
|
//! Receive remote request message object.
|
311 |
|
|
//
|
312 |
|
|
MSG_OBJ_TYPE_RX_REMOTE,
|
313 |
|
|
|
314 |
|
|
//
|
315 |
|
|
//! Remote frame receive remote, with auto-transmit message object.
|
316 |
|
|
//
|
317 |
|
|
MSG_OBJ_TYPE_RXTX_REMOTE
|
318 |
|
|
}
|
319 |
|
|
tMsgObjType;
|
320 |
|
|
|
321 |
|
|
//*****************************************************************************
|
322 |
|
|
//
|
323 |
|
|
//! The following enumeration contains all error or status indicators that can
|
324 |
|
|
//! be returned when calling the CANStatusGet() function.
|
325 |
|
|
//
|
326 |
|
|
//*****************************************************************************
|
327 |
|
|
typedef enum
|
328 |
|
|
{
|
329 |
|
|
//
|
330 |
|
|
//! CAN controller has entered a Bus Off state.
|
331 |
|
|
//
|
332 |
|
|
CAN_STATUS_BUS_OFF = 0x00000080,
|
333 |
|
|
|
334 |
|
|
//
|
335 |
|
|
//! CAN controller error level has reached warning level.
|
336 |
|
|
//
|
337 |
|
|
CAN_STATUS_EWARN = 0x00000040,
|
338 |
|
|
|
339 |
|
|
//
|
340 |
|
|
//! CAN controller error level has reached error passive level.
|
341 |
|
|
//
|
342 |
|
|
CAN_STATUS_EPASS = 0x00000020,
|
343 |
|
|
|
344 |
|
|
//
|
345 |
|
|
//! A message was received successfully since the last read of this status.
|
346 |
|
|
//
|
347 |
|
|
CAN_STATUS_RXOK = 0x00000010,
|
348 |
|
|
|
349 |
|
|
//
|
350 |
|
|
//! A message was transmitted successfully since the last read of this
|
351 |
|
|
//! status.
|
352 |
|
|
//
|
353 |
|
|
CAN_STATUS_TXOK = 0x00000008,
|
354 |
|
|
|
355 |
|
|
//
|
356 |
|
|
//! This is the mask for the last error code field.
|
357 |
|
|
//
|
358 |
|
|
CAN_STATUS_LEC_MSK = 0x00000007,
|
359 |
|
|
|
360 |
|
|
//
|
361 |
|
|
//! There was no error.
|
362 |
|
|
//
|
363 |
|
|
CAN_STATUS_LEC_NONE = 0x00000000,
|
364 |
|
|
|
365 |
|
|
//
|
366 |
|
|
//! A bit stuffing error has occurred.
|
367 |
|
|
//
|
368 |
|
|
CAN_STATUS_LEC_STUFF = 0x00000001,
|
369 |
|
|
|
370 |
|
|
//
|
371 |
|
|
//! A formatting error has occurred.
|
372 |
|
|
//
|
373 |
|
|
CAN_STATUS_LEC_FORM = 0x00000002,
|
374 |
|
|
|
375 |
|
|
//
|
376 |
|
|
//! An acknowledge error has occurred.
|
377 |
|
|
//
|
378 |
|
|
CAN_STATUS_LEC_ACK = 0x00000003,
|
379 |
|
|
|
380 |
|
|
//
|
381 |
|
|
//! The bus remained a bit level of 1 for longer than is allowed.
|
382 |
|
|
//
|
383 |
|
|
CAN_STATUS_LEC_BIT1 = 0x00000004,
|
384 |
|
|
|
385 |
|
|
//
|
386 |
|
|
//! The bus remained a bit level of 0 for longer than is allowed.
|
387 |
|
|
//
|
388 |
|
|
CAN_STATUS_LEC_BIT0 = 0x00000005,
|
389 |
|
|
|
390 |
|
|
//
|
391 |
|
|
//! A CRC error has occurred.
|
392 |
|
|
//
|
393 |
|
|
CAN_STATUS_LEC_CRC = 0x00000006,
|
394 |
|
|
|
395 |
|
|
//
|
396 |
|
|
//! This is the mask for the CAN Last Error Code (LEC).
|
397 |
|
|
//
|
398 |
|
|
CAN_STATUS_LEC_MASK = 0x00000007
|
399 |
|
|
}
|
400 |
|
|
tCANStatusCtrl;
|
401 |
|
|
|
402 |
|
|
//*****************************************************************************
|
403 |
|
|
//
|
404 |
|
|
// API Function prototypes
|
405 |
|
|
//
|
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,
|
433 |
|
|
int iSize);
|
434 |
|
|
extern void CANWriteDataReg(unsigned char *pucData, unsigned long *pulRegister,
|
435 |
|
|
int iSize);
|
436 |
|
|
|
437 |
|
|
//*****************************************************************************
|
438 |
|
|
//
|
439 |
|
|
// Mark the end of the C bindings section for C++ compilers.
|
440 |
|
|
//
|
441 |
|
|
//*****************************************************************************
|
442 |
|
|
#ifdef __cplusplus
|
443 |
|
|
}
|
444 |
|
|
#endif
|
445 |
|
|
|
446 |
|
|
//*****************************************************************************
|
447 |
|
|
//
|
448 |
|
|
// Close the Doxygen group.
|
449 |
|
|
//! @}
|
450 |
|
|
//
|
451 |
|
|
//*****************************************************************************
|
452 |
|
|
|
453 |
|
|
#endif // __CAN_H__
|