can.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // can.h - Defines and Macros for the CAN controller.
4 //
5 // Copyright (c) 2006-2017 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 //*****************************************************************************
37 
38 #ifndef __DRIVERLIB_CAN_H__
39 #define __DRIVERLIB_CAN_H__
40 
41 #include <stdint.h>
42 #include <stdbool.h>
43 
44 //*****************************************************************************
45 //
48 //
49 //*****************************************************************************
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 //*****************************************************************************
63 //
64 // Miscellaneous defines for Message ID Types
65 //
66 //*****************************************************************************
67 
68 //*****************************************************************************
69 //
70 // These are the flags used by the tCANMsgObject.ui32Flags value when calling
71 // the CANMessageSet() and CANMessageGet() functions.
72 //
73 //*****************************************************************************
74 
75 //
77 //
78 #define MSG_OBJ_TX_INT_ENABLE 0x00000001
79 
80 //
82 //
83 #define MSG_OBJ_RX_INT_ENABLE 0x00000002
84 
85 //
87 //
88 #define MSG_OBJ_EXTENDED_ID 0x00000004
89 
90 //
93 //
94 #define MSG_OBJ_USE_ID_FILTER 0x00000008
95 
96 //
98 //
99 #define MSG_OBJ_NEW_DATA 0x00000080
100 
101 //
104 //
105 #define MSG_OBJ_DATA_LOST 0x00000100
106 
107 //
111 //
112 #define MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER)
113 
114 //
118 //
119 #define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER)
120 
121 //
123 //
124 #define MSG_OBJ_REMOTE_FRAME 0x00000040
125 
126 //
129 //
130 #define MSG_OBJ_FIFO 0x00000200
131 
132 //
134 //
135 #define MSG_OBJ_NO_FLAGS 0x00000000
136 
137 //*****************************************************************************
138 //
141 //
142 //*****************************************************************************
143 #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
144 
145 //*****************************************************************************
146 //
149 //
150 //*****************************************************************************
151 typedef struct
152 {
153  //
155  //
156  uint32_t ui32MsgID;
157 
158  //
160  //
161  uint32_t ui32MsgIDMask;
162 
163  //
166  //
167  uint32_t ui32Flags;
168 
169  //
171  //
172  uint32_t ui32MsgLen;
173 
174  //
176  //
177  uint8_t *pui8MsgData;
178 }
180 
181 //*****************************************************************************
182 //
186 //
187 //*****************************************************************************
188 typedef struct
189 {
190  //
194  //
196 
197  //
200  //
201  uint32_t ui32Phase2Seg;
202 
203  //
206  //
207  uint32_t ui32SJW;
208 
209  //
212  //
214 }
216 
217 //*****************************************************************************
218 //
221 //
222 //*****************************************************************************
223 typedef enum
224 {
225  //
227  //
229 
230  //
232  //
234 }
236 
237 //*****************************************************************************
238 //
241 //
242 //*****************************************************************************
243 typedef enum
244 {
245  //
247  //
249 
250  //
253  //
255 
256  //
258  //
260 
261  //
263  //
265 }
266 tCANStsReg;
267 
268 //*****************************************************************************
269 //
270 // These definitions are used to specify interrupt sources to CANIntEnable()
271 // and CANIntDisable().
272 //
273 //*****************************************************************************
274 //
277 //
278 #define CAN_INT_ERROR 0x00000008
279 
280 //
283 //
284 #define CAN_INT_STATUS 0x00000004
285 
286 //
290 //
291 #define CAN_INT_MASTER 0x00000002
292 
293 //*****************************************************************************
294 //
297 //
298 //*****************************************************************************
299 typedef enum
300 {
301  //
303  //
305 
306  //
308  //
310 
311  //
313  //
315 
316  //
318  //
320 
321  //
323  //
325 }
327 
328 //*****************************************************************************
329 //
330 // The following enumeration contains all error or status indicators that can
331 // be returned when calling the CANStatusGet() function.
332 //
333 //*****************************************************************************
334 //
336 //
337 #define CAN_STATUS_BUS_OFF 0x00000080
338 
339 //
341 //
342 #define CAN_STATUS_EWARN 0x00000040
343 
344 //
346 //
347 #define CAN_STATUS_EPASS 0x00000020
348 
349 //
351 //
352 #define CAN_STATUS_RXOK 0x00000010
353 
354 //
357 //
358 #define CAN_STATUS_TXOK 0x00000008
359 
360 //
362 //
363 #define CAN_STATUS_LEC_MSK 0x00000007
364 
365 //
367 //
368 #define CAN_STATUS_LEC_NONE 0x00000000
369 
370 //
372 //
373 #define CAN_STATUS_LEC_STUFF 0x00000001
374 
375 //
377 //
378 #define CAN_STATUS_LEC_FORM 0x00000002
379 
380 //
382 //
383 #define CAN_STATUS_LEC_ACK 0x00000003
384 
385 //
387 //
388 #define CAN_STATUS_LEC_BIT1 0x00000004
389 
390 //
392 //
393 #define CAN_STATUS_LEC_BIT0 0x00000005
394 
395 //
397 //
398 #define CAN_STATUS_LEC_CRC 0x00000006
399 
400 //
402 //
403 #define CAN_STATUS_LEC_MASK 0x00000007
404 
405 //*****************************************************************************
406 //
407 // Close the Doxygen group.
409 //
410 //*****************************************************************************
411 
412 //*****************************************************************************
413 //
414 // API Function prototypes
415 //
416 //*****************************************************************************
417 extern void CANBitTimingGet(uint32_t ui32Base, tCANBitClkParms *psClkParms);
418 extern void CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms *psClkParms);
419 extern uint32_t CANBitRateSet(uint32_t ui32Base, uint32_t ui32SourceClock,
420  uint32_t ui32BitRate);
421 extern void CANDisable(uint32_t ui32Base);
422 extern void CANEnable(uint32_t ui32Base);
423 extern bool CANErrCntrGet(uint32_t ui32Base, uint32_t *pui32RxCount,
424  uint32_t *pui32TxCount);
425 extern void CANInit(uint32_t ui32Base);
426 extern void CANIntClear(uint32_t ui32Base, uint32_t ui32IntClr);
427 extern void CANIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
428 extern void CANIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
429 extern void CANIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
430 extern uint32_t CANIntStatus(uint32_t ui32Base, tCANIntStsReg eIntStsReg);
431 extern void CANIntUnregister(uint32_t ui32Base);
432 extern void CANMessageClear(uint32_t ui32Base, uint32_t ui32ObjID);
433 extern void CANMessageGet(uint32_t ui32Base, uint32_t ui32ObjID,
434  tCANMsgObject *psMsgObject, bool bClrPendingInt);
435 extern void CANMessageSet(uint32_t ui32Base, uint32_t ui32ObjID,
436  tCANMsgObject *psMsgObject, tMsgObjType eMsgType);
437 extern bool CANRetryGet(uint32_t ui32Base);
438 extern void CANRetrySet(uint32_t ui32Base, bool bAutoRetry);
439 extern uint32_t CANStatusGet(uint32_t ui32Base, tCANStsReg eStatusReg);
440 
441 //*****************************************************************************
442 //
443 // Mark the end of the C bindings section for C++ compilers.
444 //
445 //*****************************************************************************
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif // __DRIVERLIB_CAN_H__
Definition: can.h:188
void CANEnable(uint32_t ui32Base)
Definition: can.c:407
uint32_t ui32Phase2Seg
Definition: can.h:201
void CANIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: can.c:924
bool CANRetryGet(uint32_t ui32Base)
Definition: can.c:1173
uint32_t ui32MsgLen
This value is the number of bytes of data in the message object.
Definition: can.h:172
void CANMessageGet(uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, bool bClrPendingInt)
Definition: can.c:1818
uint32_t ui32MsgID
The CAN message identifier used for 11 or 29 bit identifiers.
Definition: can.h:156
uint32_t ui32SyncPropPhase1Seg
Definition: can.h:195
void CANInit(uint32_t ui32Base)
Definition: can.c:308
uint8_t * pui8MsgData
This is a pointer to the message object&#39;s data.
Definition: can.h:177
void CANBitTimingGet(uint32_t ui32Base, tCANBitClkParms *psClkParms)
Definition: can.c:466
tCANIntStsReg
Definition: can.h:223
void CANIntUnregister(uint32_t ui32Base)
Definition: can.c:835
uint32_t ui32QuantumPrescaler
Definition: can.h:213
void CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms *psClkParms)
Definition: can.c:693
uint32_t ui32MsgIDMask
The message identifier mask used when identifier filtering is enabled.
Definition: can.h:161
Receive message object.
Definition: can.h:314
uint32_t ui32SJW
Definition: can.h:207
Transmit remote request message object.
Definition: can.h:309
void CANDisable(uint32_t ui32Base)
Definition: can.c:436
bool CANErrCntrGet(uint32_t ui32Base, uint32_t *pui32RxCount, uint32_t *pui32TxCount)
Definition: can.c:1344
uint32_t CANStatusGet(uint32_t ui32Base, tCANStsReg eStatusReg)
Definition: can.c:1256
Transmit message object.
Definition: can.h:304
tCANStsReg
Definition: can.h:243
void CANMessageSet(uint32_t ui32Base, uint32_t ui32ObjID, tCANMsgObject *psMsgObject, tMsgObjType eMsgType)
Definition: can.c:1457
void CANIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Definition: can.c:793
uint32_t ui32Flags
Definition: can.h:167
uint32_t CANBitRateSet(uint32_t ui32Base, uint32_t ui32SourceClock, uint32_t ui32BitRate)
Definition: can.c:534
Definition: can.h:151
void CANIntClear(uint32_t ui32Base, uint32_t ui32IntClr)
Definition: can.c:1064
Read the full CAN controller status.
Definition: can.h:248
void CANRetrySet(uint32_t ui32Base, bool bAutoRetry)
Definition: can.c:1124
Read the CAN interrupt status information.
Definition: can.h:228
Read the full 32-bit mask of message objects that are enabled.
Definition: can.h:264
Read a message object&#39;s interrupt status.
Definition: can.h:233
Definition: can.h:254
uint32_t CANIntStatus(uint32_t ui32Base, tCANIntStsReg eIntStsReg)
Definition: can.c:975
Read the full 32-bit mask of message objects with new data available.
Definition: can.h:259
Receive remote request message object.
Definition: can.h:319
tMsgObjType
Definition: can.h:299
Remote frame receive remote, with auto-transmit message object.
Definition: can.h:324
void CANIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: can.c:892
void CANMessageClear(uint32_t ui32Base, uint32_t ui32ObjID)
Definition: can.c:2063
Copyright 2018, Texas Instruments Incorporated