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