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