1 /*****************************************************************************
2  * Copyright (c) 2022, Nations Technologies Inc.
3  *
4  * All rights reserved.
5  * ****************************************************************************
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the disclaimer below.
12  *
13  * Nations' name may not be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
19  * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  * ****************************************************************************/
27 
28 /**
29  * @file n32g43x_can.h
30  * @author Nations
31  * @version v1.2.0
32  *
33  * @copyright Copyright (c) 2022, Nations Technologies Inc. All rights reserved.
34  */
35 #ifndef __N32G43X_CAN_H__
36 #define __N32G43X_CAN_H__
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "n32g43x.h"
43 
44 /** @addtogroup N32G43x_StdPeriph_Driver
45  * @{
46  */
47 
48 /** @addtogroup CAN
49  * @{
50  */
51 
52 /** @addtogroup CAN_Exported_Types
53  * @{
54  */
55 
56 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN))
57 
58 /**
59  * @brief  CAN init structure definition
60  */
61 
62 typedef struct
63 {
64     uint16_t BaudRatePrescaler; /*!< Specifies the length of a time quantum.
65                                  It ranges from 1 to 1024. */
66 
67     uint8_t OperatingMode; /*!< Specifies the CAN operating mode.
68                            This parameter can be a value of
69                           @ref CAN_operating_mode */
70 
71     uint8_t RSJW; /*!< Specifies the maximum number of time quanta
72                           the CAN hardware is allowed to lengthen or
73                           shorten a bit to perform resynchronization.
74                           This parameter can be a value of
75                           @ref CAN_synchronisation_jump_width */
76 
77     uint8_t TBS1; /*!< Specifies the number of time quanta in Bit
78                           Segment 1. This parameter can be a value of
79                           @ref CAN_time_quantum_in_bit_segment_1 */
80 
81     uint8_t TBS2; /*!< Specifies the number of time quanta in Bit
82                           Segment 2.
83                           This parameter can be a value of
84                           @ref CAN_time_quantum_in_bit_segment_2 */
85 
86     FunctionalState TTCM; /*!< Enable or disable the time triggered
87                                    communication mode. This parameter can be set
88                                    either to ENABLE or DISABLE. */
89 
90     FunctionalState ABOM; /*!< Enable or disable the automatic bus-off
91                                    management. This parameter can be set either
92                                    to ENABLE or DISABLE. */
93 
94     FunctionalState AWKUM; /*!< Enable or disable the automatic wake-up mode.
95                                    This parameter can be set either to ENABLE or
96                                    DISABLE. */
97 
98     FunctionalState NART; /*!< Enable or disable the no-automatic
99                                    retransmission mode. This parameter can be
100                                    set either to ENABLE or DISABLE. */
101 
102     FunctionalState RFLM; /*!< Enable or disable the Receive DATFIFO Locked mode.
103                                    This parameter can be set either to ENABLE
104                                    or DISABLE. */
105 
106     FunctionalState TXFP; /*!< Enable or disable the transmit DATFIFO priority.
107                                    This parameter can be set either to ENABLE
108                                    or DISABLE. */
109 } CAN_InitType;
110 
111 /**
112  * @brief  CAN filter init structure definition
113  */
114 
115 typedef struct
116 {
117     uint16_t Filter_HighId; /*!< Specifies the filter identification number (MSBs for a 32-bit
118                                         configuration, first one for a 16-bit configuration).
119                                         This parameter can be a value between 0x0000 and 0xFFFF */
120 
121     uint16_t Filter_LowId; /*!< Specifies the filter identification number (LSBs for a 32-bit
122                                        configuration, second one for a 16-bit configuration).
123                                        This parameter can be a value between 0x0000 and 0xFFFF */
124 
125     uint16_t FilterMask_HighId; /*!< Specifies the filter mask number or identification number,
126                                             according to the mode (MSBs for a 32-bit configuration,
127                                             first one for a 16-bit configuration).
128                                             This parameter can be a value between 0x0000 and 0xFFFF */
129 
130     uint16_t FilterMask_LowId; /*!< Specifies the filter mask number or identification number,
131                                            according to the mode (LSBs for a 32-bit configuration,
132                                            second one for a 16-bit configuration).
133                                            This parameter can be a value between 0x0000 and 0xFFFF */
134 
135     uint16_t Filter_FIFOAssignment; /*!< Specifies the DATFIFO (0 or 1) which will be assigned to the filter.
136                                                 This parameter can be a value of @ref CAN_filter_FIFO */
137 
138     uint8_t Filter_Num; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */
139 
140     uint8_t Filter_Mode; /*!< Specifies the filter mode to be initialized.
141                                      This parameter can be a value of @ref CAN_filter_mode */
142 
143     uint8_t Filter_Scale; /*!< Specifies the filter scale.
144                                       This parameter can be a value of @ref CAN_filter_scale */
145 
146     FunctionalState Filter_Act; /*!< Enable or disable the filter.
147                                                 This parameter can be set either to ENABLE or DISABLE. */
148 } CAN_FilterInitType;
149 
150 /**
151  * @brief  CAN Tx message structure definition
152  */
153 
154 typedef struct
155 {
156     uint32_t StdId; /*!< Specifies the standard identifier.
157                          This parameter can be a value between 0 to 0x7FF. */
158 
159     uint32_t ExtId; /*!< Specifies the extended identifier.
160                          This parameter can be a value between 0 to 0x1FFFFFFF. */
161 
162     uint8_t IDE; /*!< Specifies the type of identifier for the message that
163                       will be transmitted. This parameter can be a value
164                       of @ref CAN_identifier_type */
165 
166     uint8_t RTR; /*!< Specifies the type of frame for the message that will
167                       be transmitted. This parameter can be a value of
168                       @ref CAN_remote_transmission_request */
169 
170     uint8_t DLC; /*!< Specifies the length of the frame that will be
171                       transmitted. This parameter can be a value between
172                       0 to 8 */
173 
174     uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0
175                           to 0xFF. */
176 } CanTxMessage;
177 
178 /**
179  * @brief  CAN Rx message structure definition
180  */
181 
182 typedef struct
183 {
184     uint32_t StdId; /*!< Specifies the standard identifier.
185                          This parameter can be a value between 0 to 0x7FF. */
186 
187     uint32_t ExtId; /*!< Specifies the extended identifier.
188                          This parameter can be a value between 0 to 0x1FFFFFFF. */
189 
190     uint8_t IDE; /*!< Specifies the type of identifier for the message that
191                       will be received. This parameter can be a value of
192                       @ref CAN_identifier_type */
193 
194     uint8_t RTR; /*!< Specifies the type of frame for the received message.
195                       This parameter can be a value of
196                       @ref CAN_remote_transmission_request */
197 
198     uint8_t DLC; /*!< Specifies the length of the frame that will be received.
199                       This parameter can be a value between 0 to 8 */
200 
201     uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to
202                           0xFF. */
203 
204     uint8_t FMI; /*!< Specifies the index of the filter the message stored in
205                       the mailbox passes through. This parameter can be a
206                       value between 0 to 0xFF */
207 } CanRxMessage;
208 
209 /**
210  * @}
211  */
212 
213 /** @addtogroup CAN_Exported_Constants
214  * @{
215  */
216 
217 /** @addtogroup CAN_sleep_constants
218  * @{
219  */
220 
221 #define CAN_InitSTS_Failed  ((uint8_t)0x00) /*!< CAN initialization failed */
222 #define CAN_InitSTS_Success ((uint8_t)0x01) /*!< CAN initialization OK */
223 
224 /**
225  * @}
226  */
227 
228 /** @addtogroup OperatingMode
229  * @{
230  */
231 
232 #define CAN_Normal_Mode          ((uint8_t)0x00) /*!< normal mode */
233 #define CAN_LoopBack_Mode        ((uint8_t)0x01) /*!< loopback mode */
234 #define CAN_Silent_Mode          ((uint8_t)0x02) /*!< silent mode */
235 #define CAN_Silent_LoopBack_Mode ((uint8_t)0x03) /*!< loopback combined with silent mode */
236 
237 #define IS_CAN_MODE(MODE)                                                                                              \
238     (((MODE) == CAN_Normal_Mode) || ((MODE) == CAN_LoopBack_Mode) || ((MODE) == CAN_Silent_Mode)                       \
239      || ((MODE) == CAN_Silent_LoopBack_Mode))
240 /**
241  * @}
242  */
243 
244 /**
245  * @addtogroup CAN_operating_mode
246  * @{
247  */
248 #define CAN_Operating_InitMode   ((uint8_t)0x00) /*!< Initialization mode */
249 #define CAN_Operating_NormalMode ((uint8_t)0x01) /*!< Normal mode */
250 #define CAN_Operating_SleepMode  ((uint8_t)0x02) /*!< sleep mode */
251 
252 #define IS_CAN_OPERATING_MODE(MODE)                                                                                    \
253     (((MODE) == CAN_Operating_InitMode) || ((MODE) == CAN_Operating_NormalMode) || ((MODE) == CAN_Operating_SleepMode))
254 /**
255  * @}
256  */
257 
258 /**
259  * @addtogroup CAN_Mode_Status
260  * @{
261  */
262 
263 #define CAN_ModeSTS_Failed  ((uint8_t)0x00)                /*!< CAN entering the specific mode failed */
264 #define CAN_ModeSTS_Success ((uint8_t)!CAN_ModeSTS_Failed) /*!< CAN entering the specific mode Succeed */
265 
266 /**
267  * @}
268  */
269 
270 /** @addtogroup CAN_synchronisation_jump_width
271  * @{
272  */
273 
274 #define CAN_RSJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */
275 #define CAN_RSJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */
276 #define CAN_RSJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */
277 #define CAN_RSJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */
278 
279 #define IS_CAN_RSJW(SJW)                                                                                               \
280     (((SJW) == CAN_RSJW_1tq) || ((SJW) == CAN_RSJW_2tq) || ((SJW) == CAN_RSJW_3tq) || ((SJW) == CAN_RSJW_4tq))
281 /**
282  * @}
283  */
284 
285 /** @addtogroup CAN_time_quantum_in_bit_segment_1
286  * @{
287  */
288 
289 #define CAN_TBS1_1tq  ((uint8_t)0x00) /*!< 1 time quantum */
290 #define CAN_TBS1_2tq  ((uint8_t)0x01) /*!< 2 time quantum */
291 #define CAN_TBS1_3tq  ((uint8_t)0x02) /*!< 3 time quantum */
292 #define CAN_TBS1_4tq  ((uint8_t)0x03) /*!< 4 time quantum */
293 #define CAN_TBS1_5tq  ((uint8_t)0x04) /*!< 5 time quantum */
294 #define CAN_TBS1_6tq  ((uint8_t)0x05) /*!< 6 time quantum */
295 #define CAN_TBS1_7tq  ((uint8_t)0x06) /*!< 7 time quantum */
296 #define CAN_TBS1_8tq  ((uint8_t)0x07) /*!< 8 time quantum */
297 #define CAN_TBS1_9tq  ((uint8_t)0x08) /*!< 9 time quantum */
298 #define CAN_TBS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
299 #define CAN_TBS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
300 #define CAN_TBS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
301 #define CAN_TBS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
302 #define CAN_TBS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
303 #define CAN_TBS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
304 #define CAN_TBS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */
305 
306 #define IS_CAN_TBS1(BS1) ((BS1) <= CAN_TBS1_16tq)
307 /**
308  * @}
309  */
310 
311 /** @addtogroup CAN_time_quantum_in_bit_segment_2
312  * @{
313  */
314 
315 #define CAN_TBS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
316 #define CAN_TBS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
317 #define CAN_TBS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
318 #define CAN_TBS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
319 #define CAN_TBS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
320 #define CAN_TBS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
321 #define CAN_TBS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
322 #define CAN_TBS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */
323 
324 #define IS_CAN_TBS2(BS2) ((BS2) <= CAN_TBS2_8tq)
325 
326 /**
327  * @}
328  */
329 
330 /** @addtogroup CAN_clock_prescaler
331  * @{
332  */
333 
334 #define IS_CAN_BAUDRATEPRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
335 
336 /**
337  * @}
338  */
339 
340 /** @addtogroup CAN_filter_number
341  * @{
342  */
343 #define IS_CAN_FILTER_NUM(NUMBER) ((NUMBER) <= 13)
344 /**
345  * @}
346  */
347 
348 /** @addtogroup CAN_filter_mode
349  * @{
350  */
351 
352 #define CAN_Filter_IdMaskMode ((uint8_t)0x00) /*!< identifier/mask mode */
353 #define CAN_Filter_IdListMode ((uint8_t)0x01) /*!< identifier list mode */
354 
355 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_Filter_IdMaskMode) || ((MODE) == CAN_Filter_IdListMode))
356 /**
357  * @}
358  */
359 
360 /** @addtogroup CAN_filter_scale
361  * @{
362  */
363 
364 #define CAN_Filter_16bitScale ((uint8_t)0x00) /*!< Two 16-bit filters */
365 #define CAN_Filter_32bitScale ((uint8_t)0x01) /*!< One 32-bit filter */
366 
367 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_Filter_16bitScale) || ((SCALE) == CAN_Filter_32bitScale))
368 
369 /**
370  * @}
371  */
372 
373 /** @addtogroup CAN_filter_FIFO
374  * @{
375  */
376 
377 #define CAN_Filter_FIFO0            ((uint8_t)0x00) /*!< Filter DATFIFO 0 assignment for filter x */
378 #define CAN_Filter_FIFO1            ((uint8_t)0x01) /*!< Filter DATFIFO 1 assignment for filter x */
379 #define IS_CAN_FILTER_FIFO(DATFIFO) (((DATFIFO) == CAN_FilterFIFO0) || ((DATFIFO) == CAN_FilterFIFO1))
380 /**
381  * @}
382  */
383 
384 /** @addtogroup CAN_Tx
385  * @{
386  */
387 
388 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
389 #define IS_CAN_STDID(STDID)                     ((STDID) <= ((uint32_t)0x7FF))
390 #define IS_CAN_EXTID(EXTID)                     ((EXTID) <= ((uint32_t)0x1FFFFFFF))
391 #define IS_CAN_DLC(DLC)                         ((DLC) <= ((uint8_t)0x08))
392 
393 /**
394  * @}
395  */
396 
397 /** @addtogroup CAN_identifier_type
398  * @{
399  */
400 
401 #define CAN_Standard_Id   ((uint32_t)0x00000000) /*!< Standard Id */
402 #define CAN_Extended_Id   ((uint32_t)0x00000004) /*!< Extended Id */
403 #define IS_CAN_ID(IDTYPE) (((IDTYPE) == CAN_Standard_Id) || ((IDTYPE) == CAN_Extended_Id))
404 /**
405  * @}
406  */
407 
408 /** @addtogroup CAN_remote_transmission_request
409  * @{
410  */
411 
412 #define CAN_RTRQ_Data    ((uint32_t)0x00000000) /*!< Data frame */
413 #define CAN_RTRQ_Remote  ((uint32_t)0x00000002) /*!< Remote frame */
414 #define IS_CAN_RTRQ(RTR) (((RTR) == CAN_RTRQ_Data) || ((RTR) == CAN_RTRQ_Remote))
415 
416 /**
417  * @}
418  */
419 
420 /** @addtogroup CAN_transmit_constants
421  * @{
422  */
423 
424 #define CAN_TxSTS_Failed    ((uint8_t)0x00) /*!< CAN transmission failed */
425 #define CAN_TxSTS_Ok        ((uint8_t)0x01) /*!< CAN transmission succeeded */
426 #define CAN_TxSTS_Pending   ((uint8_t)0x02) /*!< CAN transmission pending */
427 #define CAN_TxSTS_NoMailBox ((uint8_t)0x04) /*!< CAN cell did not provide an empty mailbox */
428 
429 /**
430  * @}
431  */
432 
433 /** @addtogroup CAN_receive_FIFO_number_constants
434  * @{
435  */
436 
437 #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN DATFIFO 0 used to receive */
438 #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN DATFIFO 1 used to receive */
439 
440 #define IS_CAN_FIFO(DATFIFO) (((DATFIFO) == CAN_FIFO0) || ((DATFIFO) == CAN_FIFO1))
441 
442 /**
443  * @}
444  */
445 
446 /** @addtogroup CAN_sleep_constants
447  * @{
448  */
449 
450 #define CAN_SLEEP_Failed ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */
451 #define CAN_SLEEP_Ok     ((uint8_t)0x01) /*!< CAN entered the sleep mode */
452 
453 /**
454  * @}
455  */
456 
457 /** @addtogroup CAN_wake_up_constants
458  * @{
459  */
460 
461 #define CAN_WKU_Failed ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */
462 #define CAN_WKU_Ok     ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
463 
464 /**
465  * @}
466  */
467 
468 /**
469  * @addtogroup   CAN_Error_Code_constants
470  * @{
471  */
472 
473 #define CAN_ERRCode_NoErr           ((uint8_t)0x00) /*!< No Error */
474 #define CAN_ERRCode_StuffErr        ((uint8_t)0x10) /*!< Stuff Error */
475 #define CAN_ERRCode_FormErr         ((uint8_t)0x20) /*!< Form Error */
476 #define CAN_ERRCode_ACKErr          ((uint8_t)0x30) /*!< Acknowledgment Error */
477 #define CAN_ERRCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */
478 #define CAN_ERRCode_BitDominantErr  ((uint8_t)0x50) /*!< Bit Dominant Error */
479 #define CAN_ERRCode_CRCErr          ((uint8_t)0x60) /*!< CRC Error  */
480 #define CAN_ERRCode_SWSetErr        ((uint8_t)0x70) /*!< Software Set Error */
481 
482 /**
483  * @}
484  */
485 
486 /** @addtogroup CAN_flags
487  * @{
488  */
489 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagSTS()
490    and CAN_ClearFlag() functions. */
491 /* If the flag is 0x1XXXXXXX, it means that it can only be used with CAN_GetFlagSTS() function.  */
492 
493 /* Transmit Flags */
494 #define CAN_FLAG_RQCPM0 ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */
495 #define CAN_FLAG_RQCPM1 ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */
496 #define CAN_FLAG_RQCPM2 ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */
497 
498 /* Receive Flags */
499 #define CAN_FLAG_FFMP0  ((uint32_t)0x12000003) /*!< DATFIFO 0 Message Pending Flag */
500 #define CAN_FLAG_FFULL0 ((uint32_t)0x32000008) /*!< DATFIFO 0 Full Flag            */
501 #define CAN_FLAG_FFOVR0 ((uint32_t)0x32000010) /*!< DATFIFO 0 Overrun Flag         */
502 #define CAN_FLAG_FFMP1  ((uint32_t)0x14000003) /*!< DATFIFO 1 Message Pending Flag */
503 #define CAN_FLAG_FFULL1 ((uint32_t)0x34000008) /*!< DATFIFO 1 Full Flag            */
504 #define CAN_FLAG_FFOVR1 ((uint32_t)0x34000010) /*!< DATFIFO 1 Overrun Flag         */
505 
506 /* Operating Mode Flags */
507 #define CAN_FLAG_WKU  ((uint32_t)0x31000008) /*!< Wake up Flag */
508 #define CAN_FLAG_SLAK ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */
509 /* Note: When SLAK intterupt is disabled (SLKIE=0), no polling on SLAKI is possible.
510          In this case the SLAK bit can be polled.*/
511 
512 /* Error Flags */
513 #define CAN_FLAG_EWGFL ((uint32_t)0x10F00001) /*!< Error Warning Flag   */
514 #define CAN_FLAG_EPVFL ((uint32_t)0x10F00002) /*!< Error Passive Flag   */
515 #define CAN_FLAG_BOFFL ((uint32_t)0x10F00004) /*!< Bus-Off Flag         */
516 #define CAN_FLAG_LEC   ((uint32_t)0x30F00070) /*!< Last error code Flag */
517 
518 #define IS_CAN_GET_FLAG(FLAG)                                                                                          \
519     (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOFFL) || ((FLAG) == CAN_FLAG_EPVFL)                              \
520      || ((FLAG) == CAN_FLAG_EWGFL) || ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FFOVR0)                          \
521      || ((FLAG) == CAN_FLAG_FFULL0) || ((FLAG) == CAN_FLAG_FFMP0) || ((FLAG) == CAN_FLAG_FFOVR1)                       \
522      || ((FLAG) == CAN_FLAG_FFULL1) || ((FLAG) == CAN_FLAG_FFMP1) || ((FLAG) == CAN_FLAG_RQCPM2)                       \
523      || ((FLAG) == CAN_FLAG_RQCPM1) || ((FLAG) == CAN_FLAG_RQCPM0) || ((FLAG) == CAN_FLAG_SLAK))
524 
525 #define IS_CAN_CLEAR_FLAG(FLAG)                                                                                        \
526     (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCPM2) || ((FLAG) == CAN_FLAG_RQCPM1)                            \
527      || ((FLAG) == CAN_FLAG_RQCPM0) || ((FLAG) == CAN_FLAG_FFULL0) || ((FLAG) == CAN_FLAG_FFOVR0)                      \
528      || ((FLAG) == CAN_FLAG_FFULL1) || ((FLAG) == CAN_FLAG_FFOVR1) || ((FLAG) == CAN_FLAG_WKU)                         \
529      || ((FLAG) == CAN_FLAG_SLAK))
530 /**
531  * @}
532  */
533 
534 /** @addtogroup CAN_interrupts
535  * @{
536  */
537 
538 #define CAN_INT_TME ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/
539 
540 /* Receive Interrupts */
541 #define CAN_INT_FMP0 ((uint32_t)0x00000002) /*!< DATFIFO 0 message pending Interrupt*/
542 #define CAN_INT_FF0  ((uint32_t)0x00000004) /*!< DATFIFO 0 full Interrupt*/
543 #define CAN_INT_FOV0 ((uint32_t)0x00000008) /*!< DATFIFO 0 overrun Interrupt*/
544 #define CAN_INT_FMP1 ((uint32_t)0x00000010) /*!< DATFIFO 1 message pending Interrupt*/
545 #define CAN_INT_FF1  ((uint32_t)0x00000020) /*!< DATFIFO 1 full Interrupt*/
546 #define CAN_INT_FOV1 ((uint32_t)0x00000040) /*!< DATFIFO 1 overrun Interrupt*/
547 
548 /* Operating Mode Interrupts */
549 #define CAN_INT_WKU ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/
550 #define CAN_INT_SLK ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/
551 
552 /* Error Interrupts */
553 #define CAN_INT_EWG ((uint32_t)0x00000100) /*!< Error warning Interrupt*/
554 #define CAN_INT_EPV ((uint32_t)0x00000200) /*!< Error passive Interrupt*/
555 #define CAN_INT_BOF ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/
556 #define CAN_INT_LEC ((uint32_t)0x00000800) /*!< Last error code Interrupt*/
557 #define CAN_INT_ERR ((uint32_t)0x00008000) /*!< Error Interrupt*/
558 
559 /* Flags named as Interrupts : kept only for FW compatibility */
560 #define CAN_INT_RQCPM0 CAN_INT_TME
561 #define CAN_INT_RQCPM1 CAN_INT_TME
562 #define CAN_INT_RQCPM2 CAN_INT_TME
563 
564 #define IS_CAN_INT(IT)                                                                                                 \
565     (((IT) == CAN_INT_TME) || ((IT) == CAN_INT_FMP0) || ((IT) == CAN_INT_FF0) || ((IT) == CAN_INT_FOV0)                \
566      || ((IT) == CAN_INT_FMP1) || ((IT) == CAN_INT_FF1) || ((IT) == CAN_INT_FOV1) || ((IT) == CAN_INT_EWG)             \
567      || ((IT) == CAN_INT_EPV) || ((IT) == CAN_INT_BOF) || ((IT) == CAN_INT_LEC) || ((IT) == CAN_INT_ERR)               \
568      || ((IT) == CAN_INT_WKU) || ((IT) == CAN_INT_SLK))
569 
570 #define IS_CAN_CLEAR_INT(IT)                                                                                           \
571     (((IT) == CAN_INT_TME) || ((IT) == CAN_INT_FF0) || ((IT) == CAN_INT_FOV0) || ((IT) == CAN_INT_FF1)                 \
572      || ((IT) == CAN_INT_FOV1) || ((IT) == CAN_INT_EWG) || ((IT) == CAN_INT_EPV) || ((IT) == CAN_INT_BOF)              \
573      || ((IT) == CAN_INT_LEC) || ((IT) == CAN_INT_ERR) || ((IT) == CAN_INT_WKU) || ((IT) == CAN_INT_SLK))
574 
575 /**
576  * @}
577  */
578 
579 /** @addtogroup CAN_Legacy
580  * @{
581  */
582 #define CANINITSTSFAILED CAN_InitSTS_Failed
583 #define CANINITSTSOK     CAN_InitSTS_Success
584 #define CAN_FilterFIFO0  CAN_Filter_FIFO0
585 #define CAN_FilterFIFO1  CAN_Filter_FIFO1
586 #define CAN_ID_STD       CAN_Standard_Id
587 #define CAN_ID_EXT       CAN_Extended_Id
588 #define CAN_RTRQ_DATA    CAN_RTRQ_Data
589 #define CAN_RTRQ_REMOTE  CAN_RTRQ_Remote
590 #define CANTXSTSFAILE    CAN_TxSTS_Failed
591 #define CANTXSTSOK       CAN_TxSTS_Ok
592 #define CANTXSTSPENDING  CAN_TxSTS_Pending
593 #define CAN_STS_NO_MB    CAN_TxSTS_NoMailBox
594 #define CANSLEEPFAILED   CAN_SLEEP_Failed
595 #define CANSLEEPOK       CAN_SLEEP_Ok
596 #define CANWKUFAILED     CAN_WKU_Failed
597 #define CANWKUOK         CAN_WKU_Ok
598 
599 /**
600  * @}
601  */
602 
603 /**
604  * @}
605  */
606 
607 /** @addtogroup CAN_Exported_Macros
608  * @{
609  */
610 
611 /**
612  * @}
613  */
614 
615 /** @addtogroup CAN_Exported_Functions
616  * @{
617  */
618 /*  Function used to set the CAN configuration to the default reset state *****/
619 void CAN_DeInit(CAN_Module* CANx);
620 
621 /* Initialization and Configuration functions *********************************/
622 uint8_t CAN_Init(CAN_Module* CANx, CAN_InitType* CAN_InitParam);
623 void CAN_InitFilter(CAN_FilterInitType* CAN_InitFilterStruct);
624 void CAN_InitStruct(CAN_InitType* CAN_InitParam);
625 void CAN_DebugFreeze(CAN_Module* CANx, FunctionalState Cmd);
626 void CAN_EnTTComMode(CAN_Module* CANx, FunctionalState Cmd);
627 
628 /* Transmit functions *********************************************************/
629 uint8_t CAN_TransmitMessage(CAN_Module* CANx, CanTxMessage* TxMessage);
630 uint8_t CAN_TransmitSTS(CAN_Module* CANx, uint8_t TransmitMailbox);
631 void CAN_CancelTransmitMessage(CAN_Module* CANx, uint8_t Mailbox);
632 
633 /* Receive functions **********************************************************/
634 void CAN_ReceiveMessage(CAN_Module* CANx, uint8_t FIFONum, CanRxMessage* RxMessage);
635 void CAN_ReleaseFIFO(CAN_Module* CANx, uint8_t FIFONum);
636 uint8_t CAN_PendingMessage(CAN_Module* CANx, uint8_t FIFONum);
637 
638 /* Operation modes functions **************************************************/
639 uint8_t CAN_OperatingModeReq(CAN_Module* CANx, uint8_t CAN_OperatingMode);
640 uint8_t CAN_EnterSleep(CAN_Module* CANx);
641 uint8_t CAN_WakeUp(CAN_Module* CANx);
642 
643 /* Error management functions *************************************************/
644 uint8_t CAN_GetLastErrCode(CAN_Module* CANx);
645 uint8_t CAN_GetReceiveErrCounter(CAN_Module* CANx);
646 uint8_t CAN_GetLSBTransmitErrCounter(CAN_Module* CANx);
647 
648 /* Interrupts and flags management functions **********************************/
649 void CAN_INTConfig(CAN_Module* CANx, uint32_t CAN_INT, FunctionalState Cmd);
650 FlagStatus CAN_GetFlagSTS(CAN_Module* CANx, uint32_t CAN_FLAG);
651 void CAN_ClearFlag(CAN_Module* CANx, uint32_t CAN_FLAG);
652 INTStatus CAN_GetIntStatus(CAN_Module* CANx, uint32_t CAN_INT);
653 void CAN_ClearINTPendingBit(CAN_Module* CANx, uint32_t CAN_INT);
654 
655 #ifdef __cplusplus
656 }
657 #endif
658 
659 #endif /* __N32G43X_CAN_H__ */
660 /**
661  * @}
662  */
663 
664 /**
665  * @}
666  */
667 
668 /**
669  * @}
670  */
671