Tiva Driver Lib
can.h
1 //*****************************************************************************
2 //
3 // can.h - Defines and Macros for the CAN controller.
4 //
5 // Copyright (c) 2006-2013 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 1.1 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __DRIVERLIB_CAN_H__
41 #define __DRIVERLIB_CAN_H__
42 
43 //*****************************************************************************
44 //
47 //
48 //*****************************************************************************
49 
50 //*****************************************************************************
51 //
52 // If building with a C++ compiler, make all of the definitions in this header
53 // have a C binding.
54 //
55 //*****************************************************************************
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60 
61 //*****************************************************************************
62 //
63 // Miscellaneous defines for Message ID Types
64 //
65 //*****************************************************************************
66 
67 //*****************************************************************************
68 //
69 // These are the flags used by the tCANMsgObject.ui32Flags value when calling
70 // the CANMessageSet() and CANMessageGet() functions.
71 //
72 //*****************************************************************************
73 
74 //
76 //
77 #define MSG_OBJ_TX_INT_ENABLE 0x00000001
78 
79 //
82 //
83 #define MSG_OBJ_RX_INT_ENABLE 0x00000002
84 
85 //
88 //
89 #define MSG_OBJ_EXTENDED_ID 0x00000004
90 
91 //
94 //
95 #define MSG_OBJ_USE_ID_FILTER 0x00000008
96 
97 //
99 //
100 #define MSG_OBJ_NEW_DATA 0x00000080
101 
102 //
105 //
106 #define MSG_OBJ_DATA_LOST 0x00000100
107 
108 //
112 //
113 #define MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER)
114 
115 //
119 //
120 #define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER)
121 
122 //
124 //
125 #define MSG_OBJ_REMOTE_FRAME 0x00000040
126 
127 //
130 //
131 #define MSG_OBJ_FIFO 0x00000200
132 
133 //
135 //
136 #define MSG_OBJ_NO_FLAGS 0x00000000
137 
138 //*****************************************************************************
139 //
142 //
143 //*****************************************************************************
144 #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
145 
146 //*****************************************************************************
147 //
150 //
151 //*****************************************************************************
152 typedef struct
153 {
154  //
156  //
157  uint32_t ui32MsgID;
158 
159  //
161  //
162  uint32_t ui32MsgIDMask;
163 
164  //
167  //
168  uint32_t ui32Flags;
169 
170  //
172  //
173  uint32_t ui32MsgLen;
174 
175  //
177  //
178  uint8_t *pui8MsgData;
179 }
181 
182 //*****************************************************************************
183 //
187 //
188 //*****************************************************************************
189 typedef struct
190 {
191  //
195  //
197 
198  //
201  //
202  uint32_t ui32Phase2Seg;
203 
204  //
207  //
208  uint32_t ui32SJW;
209 
210  //
213  //
215 }
217 
218 //*****************************************************************************
219 //
222 //
223 //*****************************************************************************
224 typedef enum
225 {
226  //
228  //
230 
231  //
233  //
235 }
237 
238 //*****************************************************************************
239 //
242 //
243 //*****************************************************************************
244 typedef enum
245 {
246  //
248  //
250 
251  //
254  //
256 
257  //
259  //
261 
262  //
264  //
266 }
267 tCANStsReg;
268 
269 //*****************************************************************************
270 //
271 // These definitions are used to specify interrupt sources to CANIntEnable()
272 // and CANIntDisable().
273 //
274 //*****************************************************************************
275 //
278 //
279 #define CAN_INT_ERROR 0x00000008
280 
281 //
284 //
285 #define CAN_INT_STATUS 0x00000004
286 
287 //
291 //
292 #define CAN_INT_MASTER 0x00000002
293 
294 //*****************************************************************************
295 //
298 //
299 //*****************************************************************************
300 typedef enum
301 {
302  //
304  //
306 
307  //
309  //
311 
312  //
314  //
316 
317  //
319  //
321 
322  //
324  //
326 }
328 
329 //*****************************************************************************
330 //
331 // The following enumeration contains all error or status indicators that can
332 // be returned when calling the CANStatusGet() function.
333 //
334 //*****************************************************************************
335 //
337 //
338 #define CAN_STATUS_BUS_OFF 0x00000080
339 
340 //
342 //
343 #define CAN_STATUS_EWARN 0x00000040
344 
345 //
347 //
348 #define CAN_STATUS_EPASS 0x00000020
349 
350 //
352 //
353 #define CAN_STATUS_RXOK 0x00000010
354 
355 //
358 //
359 #define CAN_STATUS_TXOK 0x00000008
360 
361 //
363 //
364 #define CAN_STATUS_LEC_MSK 0x00000007
365 
366 //
368 //
369 #define CAN_STATUS_LEC_NONE 0x00000000
370 
371 //
373 //
374 #define CAN_STATUS_LEC_STUFF 0x00000001
375 
376 //
378 //
379 #define CAN_STATUS_LEC_FORM 0x00000002
380 
381 //
383 //
384 #define CAN_STATUS_LEC_ACK 0x00000003
385 
386 //
388 //
389 #define CAN_STATUS_LEC_BIT1 0x00000004
390 
391 //
393 //
394 #define CAN_STATUS_LEC_BIT0 0x00000005
395 
396 //
398 //
399 #define CAN_STATUS_LEC_CRC 0x00000006
400 
401 //
403 //
404 #define CAN_STATUS_LEC_MASK 0x00000007
405 
406 //*****************************************************************************
407 //
408 // Close the Doxygen group.
410 //
411 //*****************************************************************************
412 
413 //*****************************************************************************
414 //
415 // API Function prototypes
416 //
417 //*****************************************************************************
418 extern void CANBitTimingGet(uint32_t ui32Base, tCANBitClkParms *psClkParms);
419 extern void CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms *psClkParms);
420 extern uint32_t CANBitRateSet(uint32_t ui32Base, uint32_t ui32SourceClock,
421  uint32_t ui32BitRate);
422 extern void CANDisable(uint32_t ui32Base);
423 extern void CANEnable(uint32_t ui32Base);
424 extern bool CANErrCntrGet(uint32_t ui32Base, uint32_t *pui32RxCount,
425  uint32_t *pui32TxCount);
426 extern void CANInit(uint32_t ui32Base);
427 extern void CANIntClear(uint32_t ui32Base, uint32_t ui32IntClr);
428 extern void CANIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
429 extern void CANIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
430 extern void CANIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
431 extern uint32_t CANIntStatus(uint32_t ui32Base, tCANIntStsReg eIntStsReg);
432 extern void CANIntUnregister(uint32_t ui32Base);
433 extern void CANMessageClear(uint32_t ui32Base, uint32_t ui32ObjID);
434 extern void CANMessageGet(uint32_t ui32Base, uint32_t ui32ObjID,
435  tCANMsgObject *psMsgObject, bool bClrPendingInt);
436 extern void CANMessageSet(uint32_t ui32Base, uint32_t ui32ObjID,
437  tCANMsgObject *psMsgObject, tMsgObjType eMsgType);
438 extern bool CANRetryGet(uint32_t ui32Base);
439 extern void CANRetrySet(uint32_t ui32Base, bool bAutoRetry);
440 extern uint32_t CANStatusGet(uint32_t ui32Base, tCANStsReg eStatusReg);
441 
442 //*****************************************************************************
443 //
444 // Mark the end of the C bindings section for C++ compilers.
445 //
446 //*****************************************************************************
447 #ifdef __cplusplus
448 }
449 #endif
450 
451 #endif // __DRIVERLIB_CAN_H__
Definition: can.h:189
void CANEnable(uint32_t ui32Base)
Definition: can.c:413
void CANIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: can.c:933
uint32_t ui32QuantumPrescaler
Definition: can.h:214
bool CANRetryGet(uint32_t ui32Base)
Definition: can.c:1182
void CANMessageGet(uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, bool bClrPendingInt)
Definition: can.c:1827
void CANInit(uint32_t ui32Base)
Definition: can.c:314
void CANBitTimingGet(uint32_t ui32Base, tCANBitClkParms *psClkParms)
Definition: can.c:472
tCANIntStsReg
Definition: can.h:224
uint8_t * pui8MsgData
This is a pointer to the message object's data.
Definition: can.h:178
void CANIntUnregister(uint32_t ui32Base)
Definition: can.c:844
uint32_t ui32Flags
Definition: can.h:168
void CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms *psClkParms)
Definition: can.c:702
uint32_t ui32MsgLen
This value is the number of bytes of data in the message object.
Definition: can.h:173
uint32_t ui32MsgIDMask
The message identifier mask used when identifier filtering is enabled.
Definition: can.h:162
Receive message object.
Definition: can.h:315
Transmit remote request message object.
Definition: can.h:310
void CANDisable(uint32_t ui32Base)
Definition: can.c:442
bool CANErrCntrGet(uint32_t ui32Base, uint32_t *pui32RxCount, uint32_t *pui32TxCount)
Definition: can.c:1353
uint32_t ui32SyncPropPhase1Seg
Definition: can.h:196
uint32_t CANStatusGet(uint32_t ui32Base, tCANStsReg eStatusReg)
Definition: can.c:1265
Transmit message object.
Definition: can.h:305
tCANStsReg
Definition: can.h:244
void CANMessageSet(uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, tMsgObjType eMsgType)
Definition: can.c:1466
void CANIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Definition: can.c:802
uint32_t ui32MsgID
The CAN message identifier used for 11 or 29 bit identifiers.
Definition: can.h:157
uint32_t CANBitRateSet(uint32_t ui32Base, uint32_t ui32SourceClock, uint32_t ui32BitRate)
Definition: can.c:543
Definition: can.h:152
void CANIntClear(uint32_t ui32Base, uint32_t ui32IntClr)
Definition: can.c:1073
Read the full CAN controller status.
Definition: can.h:249
void CANRetrySet(uint32_t ui32Base, bool bAutoRetry)
Definition: can.c:1133
Read the CAN interrupt status information.
Definition: can.h:229
Read the full 32-bit mask of message objects that are enabled.
Definition: can.h:265
uint32_t ui32SJW
Definition: can.h:208
Read a message object's interrupt status.
Definition: can.h:234
Definition: can.h:255
uint32_t CANIntStatus(uint32_t ui32Base, tCANIntStsReg eIntStsReg)
Definition: can.c:984
Read the full 32-bit mask of message objects with new data available.
Definition: can.h:260
Receive remote request message object.
Definition: can.h:320
tMsgObjType
Definition: can.h:300
Remote frame receive remote, with auto-transmit message object.
Definition: can.h:325
void CANIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: can.c:901
void CANMessageClear(uint32_t ui32Base, uint32_t ui32ObjID)
Definition: can.c:2072
uint32_t ui32Phase2Seg
Definition: can.h:202