CC27xxDriverLibrary
can.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  * Filename: can.h
4  *
5  * Description: Defines and prototypes for the CAN peripheral.
6  *
7  * Copyright (c) 2023-2025 Texas Instruments Incorporated
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1) Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2) Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3) Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 #ifndef __CAN_H__
38 #define __CAN_H__
39 
40 //*****************************************************************************
41 //
46 //
47 //*****************************************************************************
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 #include <stdint.h>
60 #include "../inc/hw_types.h"
61 #include "../inc/hw_memmap.h"
62 #include "../inc/hw_canfd.h"
63 
64 //*****************************************************************************
65 //
66 // Flags that can be passed to CANSSSetControl and CANSSClearControl.
67 //
68 //*****************************************************************************
69 #define CANSS_CTRL_EXT_TIMESTAMP_EN (CANFD_MCANSS_CTRL_EXT_TS_CNTR_EN_M)
70 #define CANSS_CTRL_AUTOWAKEUP_EN (CANFD_MCANSS_CTRL_AUTOWAKEUP_M)
71 #define CANSS_CTRL_WAKEUP_REQ_EN (CANFD_MCANSS_CTRL_WAKEUPREQEN_M)
72 #define CANSS_CTRL_DEBUG_SUSPEND_EN (CANFD_MCANSS_CTRL_DBGSUSP_FREE_M)
73 
74 //*****************************************************************************
75 //
76 // Flags that can be returned by CANSSGetStatus.
77 //
78 //*****************************************************************************
79 #define CANSS_STATUS_ENABLE_FDOE (CANFD_MCANSS_STAT_ENABLE_FDOE_M)
80 #define CANSS_STATUS_MEM_INIT_DONE (CANFD_MCANSS_STAT_MEM_INIT_DONE_M)
81 
82 //*****************************************************************************
83 //
84 // Flags that can be passed to CANSSClearInt, CANSSEnableInt, and
85 // CANSSDisableInt or returned by CANSSGetIntStatus.
86 //
87 //*****************************************************************************
88 #define CANSS_INT_EXT_TIMESTAMP_OVERFLOW \
89  (CANFD_MCANSS_IRS_EXT_TS_CNTR_OVFL_M)
90 
91 //*****************************************************************************
92 //
93 // Flags that can be passed to CANSSSetEndOfInterrupt.
94 //
95 //*****************************************************************************
96 #define CANSS_EOI_EXT_TIMESTAMP 0U
97 #define CANSS_EOI_MCAN0 1U
98 #define CANSS_EOI_MCAN1 2U
99 
100 //*****************************************************************************
101 //
102 // Interrupt line numbers that can be passed to CANSetIntMask, CANClearIntMask,
103 // CANGetIntStatus, and CANClearInt.
104 //
105 //*****************************************************************************
106 #define CAN_INT_LINE0 0U
107 #define CAN_INT_LINE1 1U
108 
109 //*****************************************************************************
110 //
111 // Flags that can be passed to CANSetIntMask, CANClearIntMask, and CANClearInt
112 // or returned by CANGetIntStatus.
113 //
114 //*****************************************************************************
115 #define CAN_INT_DMA_DONE1 (CANFD_IMASK0_DMA_DONE1_M)
116 #define CAN_INT_DMA_DONE0 (CANFD_IMASK0_DMA_DONE0_M)
117 #define CAN_INT_FILTER_EVENT2 (CANFD_IMASK0_FE2_M)
118 #define CAN_INT_EXT_TS_OR_WAKE (CANFD_IMASK0_EXT_TS_OR_WAKE_M)
119 #define CAN_INT_DED (CANFD_IMASK0_DED_M)
120 #define CAN_INT_SEC (CANFD_IMASK0_SEC_M)
121 #define CAN_INT_INTL1 (CANFD_IMASK0_INTL1_M)
122 #define CAN_INT_INTL0 (CANFD_IMASK0_INTL0_M)
123 #define CAN_INT_MASK (0x0000000FU)
124 
125 //*****************************************************************************
126 //
127 // Clock divider ratios that can be passed to CANSSSetClockDivider.
128 //
129 //*****************************************************************************
130 #define CANSS_CLK_DIVIDE_BY_1 0U
131 #define CANSS_CLK_DIVIDE_BY_2 1U
132 #define CANSS_CLK_DIVIDE_BY_4 2U
133 
134 //*****************************************************************************
135 //
136 // Flags that can be passed to CANSSSetClkStopCtrl and CANSSClearClkStopCtrl.
137 //
138 //*****************************************************************************
139 #define CANSS_CLKCTRL_WAKEUP_GLITCH_FILTER_EN (CANFD_MCANSS_CLKCTL_WKUP_GLTFLT_EN_M)
140 #define CANSS_CLKCTRL_WAKEUP_INT_EN (CANFD_MCANSS_CLKCTL_WAKEUP_INT_EN_M)
141 #define CANSS_CLKCTRL_STOP_REQ (CANFD_MCANSS_CLKCTL_STOPREQ_M)
142 
143 //*****************************************************************************
144 //
145 // Flags that can be returned by CANSSGetClkStopCtrlStatus.
146 //
147 //*****************************************************************************
148 #define CANSS_CLKSTAT_CLKSTOP_REQ_OVR \
149  (CANFD_MCANSS_CLKSTS_STOPREQ_HW_OVR_M)
150 #define CANSS_CLKSTAT_CLKSTOP_ACK (CANFD_MCANSS_CLKSTS_CLKSTOP_ACKSTS_M)
151 
152 //*****************************************************************************
153 //
166 //
167 //*****************************************************************************
168 __STATIC_INLINE void CANSSSetControl(uint32_t flags)
169 {
170  HWREG(CANFD_BASE + CANFD_O_MCANSS_CTRL) |= flags;
171 }
172 
173 //*****************************************************************************
174 //
187 //
188 //*****************************************************************************
189 __STATIC_INLINE void CANSSClearControl(uint32_t flags)
190 {
191  HWREG(CANFD_BASE + CANFD_O_MCANSS_CTRL) &= (uint32_t)~flags;
192 }
193 
194 //*****************************************************************************
195 //
204 //
205 //*****************************************************************************
207 {
208  return (HWREG(CANFD_BASE + CANFD_O_MCANSS_STAT));
209 }
210 
211 //*****************************************************************************
212 //
217 //
218 //*****************************************************************************
220 {
221  return (HWREG(CANFD_BASE + CANFD_O_MCANSS_IES));
222 }
223 
224 //*****************************************************************************
225 //
230 //
231 //*****************************************************************************
233 {
234  return (HWREG(CANFD_BASE + CANFD_O_MCANSS_IRS));
235 }
236 
237 //*****************************************************************************
238 //
246 //
247 //*****************************************************************************
248 __STATIC_INLINE void CANSSClearInt(uint32_t flags)
249 {
250  HWREG(CANFD_BASE + CANFD_O_MCANSS_ICS) = flags;
251 }
252 
253 //*****************************************************************************
254 //
264 //
265 //*****************************************************************************
266 __STATIC_INLINE void CANSSEnableInt(uint32_t flags)
267 {
268  HWREG(CANFD_BASE + CANFD_O_MCANSS_IE) = flags;
269 }
270 
271 //*****************************************************************************
272 //
282 //
283 //*****************************************************************************
284 __STATIC_INLINE void CANSSDisableInt(uint32_t flags)
285 {
286  HWREG(CANFD_BASE + CANFD_O_MCANSS_IECS) = flags;
287 }
288 
289 //*****************************************************************************
290 //
304 //
305 //*****************************************************************************
306 void CANSSSetEndOfInt(uint32_t eoi) __attribute__((weak));
307 
308 //*****************************************************************************
309 //
317 //
318 //*****************************************************************************
320 {
321  HWREG(CANFD_BASE + CANFD_O_MCANSS_EXT_TS_PRESCALER) = prescaler;
322 }
323 
324 //*****************************************************************************
325 //
329 //
330 //*****************************************************************************
332 {
333  return (HWREG(CANFD_BASE + CANFD_O_MCANSS_EXT_TS_UNSERVICED_INTR_CNTR));
334 }
335 
336 //*****************************************************************************
337 //
359 //
360 //*****************************************************************************
361 __STATIC_INLINE void CANSetIntMask(uint32_t lineNum, uint32_t flags)
362 {
363  uint32_t offset = (lineNum == CAN_INT_LINE0) ? CANFD_O_IMASK0 : CANFD_O_IMASK1;
364 
365  HWREG(CANFD_BASE + offset) |= flags;
366 }
367 
368 //*****************************************************************************
369 //
391 //
392 //*****************************************************************************
393 __STATIC_INLINE void CANClearIntMask(uint8_t lineNum, uint32_t flags)
394 {
395  uint32_t offset = (lineNum == CAN_INT_LINE0) ? CANFD_O_IMASK0 : CANFD_O_IMASK1;
396 
397  HWREG(CANFD_BASE + offset) &= (uint32_t)~flags;
398 }
399 
400 //*****************************************************************************
401 //
417 //
418 //*****************************************************************************
419 __STATIC_INLINE uint32_t CANGetMaskedIntStatus(uint8_t lineNum)
420 {
421  uint32_t offset = (lineNum == CAN_INT_LINE0) ? CANFD_O_MIS0 : CANFD_O_MIS1;
422  return (HWREG(CANFD_BASE + offset));
423 }
424 
425 //*****************************************************************************
426 //
442 //
443 //*****************************************************************************
444 __STATIC_INLINE uint32_t CANGetRawIntStatus(uint8_t lineNum)
445 {
446  uint32_t offset = (lineNum == CAN_INT_LINE0) ? CANFD_O_RIS0 : CANFD_O_RIS1;
447  return (HWREG(CANFD_BASE + offset));
448 }
449 
450 //*****************************************************************************
451 //
473 //
474 //*****************************************************************************
475 void CANClearInt(uint8_t lineNum, uint32_t flags) __attribute__((weak));
476 
477 //*****************************************************************************
478 //
489 //
490 //*****************************************************************************
492 {
493  HWREG(CANFD_BASE + CANFD_O_MCANSS_CLKDIV) = ratio;
494 }
495 
496 //*****************************************************************************
497 //
509 //
510 //*****************************************************************************
511 void CANSSSetClkStopCtrl(uint32_t flags) __attribute__((weak));
512 
513 //*****************************************************************************
514 //
526 //
527 //*****************************************************************************
528 void CANSSClearClkStopCtrl(uint32_t flags) __attribute__((weak));
529 
530 //*****************************************************************************
531 //
539 //
540 //*****************************************************************************
542 {
543  return HWREG(CANFD_BASE + CANFD_O_MCANSS_CLKSTS);
544 }
545 
546 //*****************************************************************************
547 //
548 // Mark the end of the C bindings section for C++ compilers.
549 //
550 //*****************************************************************************
551 #ifdef __cplusplus
552 }
553 #endif
554 
555 //*****************************************************************************
556 //
560 //
561 //*****************************************************************************
562 
563 #endif // __CAN_H__
__STATIC_INLINE uint32_t CANGetRawIntStatus(uint8_t lineNum)
Gets the CAN raw peripheral interrupt status.
Definition: can.h:444
__STATIC_INLINE void CANSSSetClockDivider(uint32_t ratio)
Sets the CAN Subsystem clock divider ratio for the functional clock input.
Definition: can.h:491
__STATIC_INLINE uint32_t CANSSGetRawIntStatus(void)
Gets the CAN Subsystem raw interrupt status.
Definition: can.h:232
__STATIC_INLINE void CANSSEnableInt(uint32_t flags)
Enables the specified CAN Subsytem interrupt(s).
Definition: can.h:266
void CANSSSetEndOfInt(uint32_t eoi) __attribute__((weak))
Sets the CAN Subsystem End Of Interrupt (EOI).
void CANSSSetClkStopCtrl(uint32_t flags) __attribute__((weak))
Sets the CAN Subsystem clock stop control feature flag(s).
__STATIC_INLINE void CANSSClearInt(uint32_t flags)
Clears the specified CAN Subsytem interrupt enable(s).
Definition: can.h:248
#define CAN_INT_LINE0
Interrupt Line 0.
Definition: can.h:106
void CANSSClearClkStopCtrl(uint32_t flags) __attribute__((weak))
Clears the CAN Subsystem clock stop control feature flag(s).
__STATIC_INLINE void CANSetIntMask(uint32_t lineNum, uint32_t flags)
Sets the CAN peripheral interrupt mask.
Definition: can.h:361
__attribute__((weak))
Definition: can.c:43
__STATIC_INLINE void CANSSDisableInt(uint32_t flags)
Disables the specified CAN Subsytem interrupt(s).
Definition: can.h:284
__STATIC_INLINE uint32_t CANSSGetStatus(void)
Gets the CAN Subsystem status.
Definition: can.h:206
__STATIC_INLINE void CANSSSetExtTimestampPrescaler(uint32_t prescaler)
Sets the CAN Subsystem external timestamp prescaler.
Definition: can.h:319
__STATIC_INLINE void CANSSClearControl(uint32_t flags)
Clears the specified CAN Subsystem control feature flag(s).
Definition: can.h:189
__STATIC_INLINE uint32_t CANSSGetExtTSUnservicedIntCounter(void)
Gets the CAN Subsystem external timestamp unserviced interrupts counter.
Definition: can.h:331
__STATIC_INLINE void CANSSSetControl(uint32_t flags)
Sets the specified CAN Subsystem control feature flag(s).
Definition: can.h:168
__STATIC_INLINE void CANClearIntMask(uint8_t lineNum, uint32_t flags)
Clears the CAN peripheral interrupt mask.
Definition: can.h:393
__STATIC_INLINE uint32_t CANSSGetClkStopCtrlStatus(void)
Gets the CAN Subsystem clock stop control status.
Definition: can.h:541
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__STATIC_INLINE uint32_t CANGetMaskedIntStatus(uint8_t lineNum)
Gets the CAN masked peripheral interrupt status.
Definition: can.h:419
void CANClearInt(uint8_t lineNum, uint32_t flags) __attribute__((weak))
Clears the specified CAN peripheral interrupt(s).
__STATIC_INLINE uint32_t CANSSGetMaskedIntStatus(void)
Gets the CAN Subsystem masked interrupt status.
Definition: can.h:219