1 /* Define to prevent recursive inclusion -------------------------------------*/
2 #ifndef __AIR32F10x_CAN_H
3 #define __AIR32F10x_CAN_H
4 
5 #ifdef __cplusplus
6  extern "C" {
7 #endif
8 
9 /* Includes ------------------------------------------------------------------*/
10 #include "air32f10x.h"
11 
12 /** @addtogroup air32f10x_StdPeriph_Driver
13   * @{
14   */
15 
16 /** @addtogroup CAN
17   * @{
18   */
19 
20 /** @defgroup CAN_Exported_Types
21   * @{
22   */
23 
24 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
25                                    ((PERIPH) == CAN2))
26 
27 /**
28   * @brief  CAN init structure definition
29   */
30 
31 typedef struct
32 {
33   uint16_t CAN_Prescaler;   /*!< Specifies the length of a time quantum.
34                                  It ranges from 1 to 1024. */
35 
36   uint8_t CAN_Mode;         /*!< Specifies the CAN operating mode.
37                                  This parameter can be a value of
38                                 @ref CAN_operating_mode */
39 
40   uint8_t CAN_SJW;          /*!< Specifies the maximum number of time quanta
41                                  the CAN hardware is allowed to lengthen or
42                                  shorten a bit to perform resynchronization.
43                                  This parameter can be a value of
44                                  @ref CAN_synchronisation_jump_width */
45 
46   uint8_t CAN_BS1;          /*!< Specifies the number of time quanta in Bit
47                                  Segment 1. This parameter can be a value of
48                                  @ref CAN_time_quantum_in_bit_segment_1 */
49 
50   uint8_t CAN_BS2;          /*!< Specifies the number of time quanta in Bit
51                                  Segment 2.
52                                  This parameter can be a value of
53                                  @ref CAN_time_quantum_in_bit_segment_2 */
54 
55   FunctionalState CAN_TTCM; /*!< Enable or disable the time triggered
56                                  communication mode. This parameter can be set
57                                  either to ENABLE or DISABLE. */
58 
59   FunctionalState CAN_ABOM;  /*!< Enable or disable the automatic bus-off
60                                   management. This parameter can be set either
61                                   to ENABLE or DISABLE. */
62 
63   FunctionalState CAN_AWUM;  /*!< Enable or disable the automatic wake-up mode.
64                                   This parameter can be set either to ENABLE or
65                                   DISABLE. */
66 
67   FunctionalState CAN_NART;  /*!< Enable or disable the no-automatic
68                                   retransmission mode. This parameter can be
69                                   set either to ENABLE or DISABLE. */
70 
71   FunctionalState CAN_RFLM;  /*!< Enable or disable the Receive FIFO Locked mode.
72                                   This parameter can be set either to ENABLE
73                                   or DISABLE. */
74 
75   FunctionalState CAN_TXFP;  /*!< Enable or disable the transmit FIFO priority.
76                                   This parameter can be set either to ENABLE
77                                   or DISABLE. */
78 } CAN_InitTypeDef;
79 
80 /**
81   * @brief  CAN filter init structure definition
82   */
83 
84 typedef struct
85 {
86   uint16_t CAN_FilterIdHigh;         /*!< Specifies the filter identification number (MSBs for a 32-bit
87                                               configuration, first one for a 16-bit configuration).
88                                               This parameter can be a value between 0x0000 and 0xFFFF */
89 
90   uint16_t CAN_FilterIdLow;          /*!< Specifies the filter identification number (LSBs for a 32-bit
91                                               configuration, second one for a 16-bit configuration).
92                                               This parameter can be a value between 0x0000 and 0xFFFF */
93 
94   uint16_t CAN_FilterMaskIdHigh;     /*!< Specifies the filter mask number or identification number,
95                                               according to the mode (MSBs for a 32-bit configuration,
96                                               first one for a 16-bit configuration).
97                                               This parameter can be a value between 0x0000 and 0xFFFF */
98 
99   uint16_t CAN_FilterMaskIdLow;      /*!< Specifies the filter mask number or identification number,
100                                               according to the mode (LSBs for a 32-bit configuration,
101                                               second one for a 16-bit configuration).
102                                               This parameter can be a value between 0x0000 and 0xFFFF */
103 
104   uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
105                                               This parameter can be a value of @ref CAN_filter_FIFO */
106 
107   uint8_t CAN_FilterNumber;          /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */
108 
109   uint8_t CAN_FilterMode;            /*!< Specifies the filter mode to be initialized.
110                                               This parameter can be a value of @ref CAN_filter_mode */
111 
112   uint8_t CAN_FilterScale;           /*!< Specifies the filter scale.
113                                               This parameter can be a value of @ref CAN_filter_scale */
114 
115   FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.
116                                               This parameter can be set either to ENABLE or DISABLE. */
117 } CAN_FilterInitTypeDef;
118 
119 /**
120   * @brief  CAN Tx message structure definition
121   */
122 
123 typedef struct
124 {
125   uint32_t StdId;  /*!< Specifies the standard identifier.
126                         This parameter can be a value between 0 to 0x7FF. */
127 
128   uint32_t ExtId;  /*!< Specifies the extended identifier.
129                         This parameter can be a value between 0 to 0x1FFFFFFF. */
130 
131   uint8_t IDE;     /*!< Specifies the type of identifier for the message that
132                         will be transmitted. This parameter can be a value
133                         of @ref CAN_identifier_type */
134 
135   uint8_t RTR;     /*!< Specifies the type of frame for the message that will
136                         be transmitted. This parameter can be a value of
137                         @ref CAN_remote_transmission_request */
138 
139   uint8_t DLC;     /*!< Specifies the length of the frame that will be
140                         transmitted. This parameter can be a value between
141                         0 to 8 */
142 
143   uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0
144                         to 0xFF. */
145 } CanTxMsg;
146 
147 /**
148   * @brief  CAN Rx message structure definition
149   */
150 
151 typedef struct
152 {
153   uint32_t StdId;  /*!< Specifies the standard identifier.
154                         This parameter can be a value between 0 to 0x7FF. */
155 
156   uint32_t ExtId;  /*!< Specifies the extended identifier.
157                         This parameter can be a value between 0 to 0x1FFFFFFF. */
158 
159   uint8_t IDE;     /*!< Specifies the type of identifier for the message that
160                         will be received. This parameter can be a value of
161                         @ref CAN_identifier_type */
162 
163   uint8_t RTR;     /*!< Specifies the type of frame for the received message.
164                         This parameter can be a value of
165                         @ref CAN_remote_transmission_request */
166 
167   uint8_t DLC;     /*!< Specifies the length of the frame that will be received.
168                         This parameter can be a value between 0 to 8 */
169 
170   uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to
171                         0xFF. */
172 
173   uint8_t FMI;     /*!< Specifies the index of the filter the message stored in
174                         the mailbox passes through. This parameter can be a
175                         value between 0 to 0xFF */
176 } CanRxMsg;
177 
178 /**
179   * @}
180   */
181 
182 /** @defgroup CAN_Exported_Constants
183   * @{
184   */
185 
186 /** @defgroup CAN_sleep_constants
187   * @{
188   */
189 
190 #define CAN_InitStatus_Failed              ((uint8_t)0x00) /*!< CAN initialization failed */
191 #define CAN_InitStatus_Success             ((uint8_t)0x01) /*!< CAN initialization OK */
192 
193 /**
194   * @}
195   */
196 
197 /** @defgroup CAN_Mode
198   * @{
199   */
200 
201 #define CAN_Mode_Normal             ((uint8_t)0x00)  /*!< normal mode */
202 #define CAN_Mode_LoopBack           ((uint8_t)0x01)  /*!< loopback mode */
203 #define CAN_Mode_Silent             ((uint8_t)0x02)  /*!< silent mode */
204 #define CAN_Mode_Silent_LoopBack    ((uint8_t)0x03)  /*!< loopback combined with silent mode */
205 
206 #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
207                            ((MODE) == CAN_Mode_LoopBack)|| \
208                            ((MODE) == CAN_Mode_Silent) || \
209                            ((MODE) == CAN_Mode_Silent_LoopBack))
210 /**
211   * @}
212   */
213 
214 
215 /**
216   * @defgroup CAN_Operating_Mode
217   * @{
218   */
219 #define CAN_OperatingMode_Initialization  ((uint8_t)0x00) /*!< Initialization mode */
220 #define CAN_OperatingMode_Normal          ((uint8_t)0x01) /*!< Normal mode */
221 #define CAN_OperatingMode_Sleep           ((uint8_t)0x02) /*!< sleep mode */
222 
223 
224 #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
225                                     ((MODE) == CAN_OperatingMode_Normal)|| \
226                                                                         ((MODE) == CAN_OperatingMode_Sleep))
227 /**
228   * @}
229   */
230 
231 /**
232   * @defgroup CAN_Mode_Status
233   * @{
234   */
235 
236 #define CAN_ModeStatus_Failed    ((uint8_t)0x00)                /*!< CAN entering the specific mode failed */
237 #define CAN_ModeStatus_Success   ((uint8_t)!CAN_ModeStatus_Failed)   /*!< CAN entering the specific mode Succeed */
238 
239 
240 /**
241   * @}
242   */
243 
244 /** @defgroup CAN_synchronisation_jump_width
245   * @{
246   */
247 
248 #define CAN_SJW_1tq                 ((uint8_t)0x00)  /*!< 1 time quantum */
249 #define CAN_SJW_2tq                 ((uint8_t)0x01)  /*!< 2 time quantum */
250 #define CAN_SJW_3tq                 ((uint8_t)0x02)  /*!< 3 time quantum */
251 #define CAN_SJW_4tq                 ((uint8_t)0x03)  /*!< 4 time quantum */
252 
253 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
254                          ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
255 /**
256   * @}
257   */
258 
259 /** @defgroup CAN_time_quantum_in_bit_segment_1
260   * @{
261   */
262 
263 #define CAN_BS1_1tq                 ((uint8_t)0x00)  /*!< 1 time quantum */
264 #define CAN_BS1_2tq                 ((uint8_t)0x01)  /*!< 2 time quantum */
265 #define CAN_BS1_3tq                 ((uint8_t)0x02)  /*!< 3 time quantum */
266 #define CAN_BS1_4tq                 ((uint8_t)0x03)  /*!< 4 time quantum */
267 #define CAN_BS1_5tq                 ((uint8_t)0x04)  /*!< 5 time quantum */
268 #define CAN_BS1_6tq                 ((uint8_t)0x05)  /*!< 6 time quantum */
269 #define CAN_BS1_7tq                 ((uint8_t)0x06)  /*!< 7 time quantum */
270 #define CAN_BS1_8tq                 ((uint8_t)0x07)  /*!< 8 time quantum */
271 #define CAN_BS1_9tq                 ((uint8_t)0x08)  /*!< 9 time quantum */
272 #define CAN_BS1_10tq                ((uint8_t)0x09)  /*!< 10 time quantum */
273 #define CAN_BS1_11tq                ((uint8_t)0x0A)  /*!< 11 time quantum */
274 #define CAN_BS1_12tq                ((uint8_t)0x0B)  /*!< 12 time quantum */
275 #define CAN_BS1_13tq                ((uint8_t)0x0C)  /*!< 13 time quantum */
276 #define CAN_BS1_14tq                ((uint8_t)0x0D)  /*!< 14 time quantum */
277 #define CAN_BS1_15tq                ((uint8_t)0x0E)  /*!< 15 time quantum */
278 #define CAN_BS1_16tq                ((uint8_t)0x0F)  /*!< 16 time quantum */
279 
280 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
281 /**
282   * @}
283   */
284 
285 /** @defgroup CAN_time_quantum_in_bit_segment_2
286   * @{
287   */
288 
289 #define CAN_BS2_1tq                 ((uint8_t)0x00)  /*!< 1 time quantum */
290 #define CAN_BS2_2tq                 ((uint8_t)0x01)  /*!< 2 time quantum */
291 #define CAN_BS2_3tq                 ((uint8_t)0x02)  /*!< 3 time quantum */
292 #define CAN_BS2_4tq                 ((uint8_t)0x03)  /*!< 4 time quantum */
293 #define CAN_BS2_5tq                 ((uint8_t)0x04)  /*!< 5 time quantum */
294 #define CAN_BS2_6tq                 ((uint8_t)0x05)  /*!< 6 time quantum */
295 #define CAN_BS2_7tq                 ((uint8_t)0x06)  /*!< 7 time quantum */
296 #define CAN_BS2_8tq                 ((uint8_t)0x07)  /*!< 8 time quantum */
297 
298 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
299 
300 /**
301   * @}
302   */
303 
304 /** @defgroup CAN_clock_prescaler
305   * @{
306   */
307 
308 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
309 
310 /**
311   * @}
312   */
313 
314 /** @defgroup CAN_filter_number
315   * @{
316   */
317 #ifndef air32f10x_CL
318   #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13)
319 #else
320   #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
321 #endif /* air32f10x_CL */
322 /**
323   * @}
324   */
325 
326 /** @defgroup CAN_filter_mode
327   * @{
328   */
329 
330 #define CAN_FilterMode_IdMask       ((uint8_t)0x00)  /*!< identifier/mask mode */
331 #define CAN_FilterMode_IdList       ((uint8_t)0x01)  /*!< identifier list mode */
332 
333 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
334                                   ((MODE) == CAN_FilterMode_IdList))
335 /**
336   * @}
337   */
338 
339 /** @defgroup CAN_filter_scale
340   * @{
341   */
342 
343 #define CAN_FilterScale_16bit       ((uint8_t)0x00) /*!< Two 16-bit filters */
344 #define CAN_FilterScale_32bit       ((uint8_t)0x01) /*!< One 32-bit filter */
345 
346 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
347                                     ((SCALE) == CAN_FilterScale_32bit))
348 
349 /**
350   * @}
351   */
352 
353 /** @defgroup CAN_filter_FIFO
354   * @{
355   */
356 
357 #define CAN_Filter_FIFO0             ((uint8_t)0x00)  /*!< Filter FIFO 0 assignment for filter x */
358 #define CAN_Filter_FIFO1             ((uint8_t)0x01)  /*!< Filter FIFO 1 assignment for filter x */
359 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
360                                   ((FIFO) == CAN_FilterFIFO1))
361 /**
362   * @}
363   */
364 
365 /** @defgroup Start_bank_filter_for_slave_CAN
366   * @{
367   */
368 #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
369 /**
370   * @}
371   */
372 
373 /** @defgroup CAN_Tx
374   * @{
375   */
376 
377 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
378 #define IS_CAN_STDID(STDID)   ((STDID) <= ((uint32_t)0x7FF))
379 #define IS_CAN_EXTID(EXTID)   ((EXTID) <= ((uint32_t)0x1FFFFFFF))
380 #define IS_CAN_DLC(DLC)       ((DLC) <= ((uint8_t)0x08))
381 
382 /**
383   * @}
384   */
385 
386 /** @defgroup CAN_identifier_type
387   * @{
388   */
389 
390 #define CAN_Id_Standard             ((uint32_t)0x00000000)  /*!< Standard Id */
391 #define CAN_Id_Extended             ((uint32_t)0x00000004)  /*!< Extended Id */
392 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
393                                ((IDTYPE) == CAN_Id_Extended))
394 /**
395   * @}
396   */
397 
398 /** @defgroup CAN_remote_transmission_request
399   * @{
400   */
401 
402 #define CAN_RTR_Data                ((uint32_t)0x00000000)  /*!< Data frame */
403 #define CAN_RTR_Remote              ((uint32_t)0x00000002)  /*!< Remote frame */
404 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
405 
406 /**
407   * @}
408   */
409 
410 /** @defgroup CAN_transmit_constants
411   * @{
412   */
413 
414 #define CAN_TxStatus_Failed         ((uint8_t)0x00)/*!< CAN transmission failed */
415 #define CAN_TxStatus_Ok             ((uint8_t)0x01) /*!< CAN transmission succeeded */
416 #define CAN_TxStatus_Pending        ((uint8_t)0x02) /*!< CAN transmission pending */
417 #define CAN_TxStatus_NoMailBox      ((uint8_t)0x04) /*!< CAN cell did not provide an empty mailbox */
418 
419 /**
420   * @}
421   */
422 
423 /** @defgroup CAN_receive_FIFO_number_constants
424   * @{
425   */
426 
427 #define CAN_FIFO0                 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */
428 #define CAN_FIFO1                 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */
429 
430 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
431 
432 /**
433   * @}
434   */
435 
436 /** @defgroup CAN_sleep_constants
437   * @{
438   */
439 
440 #define CAN_Sleep_Failed     ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */
441 #define CAN_Sleep_Ok         ((uint8_t)0x01) /*!< CAN entered the sleep mode */
442 
443 /**
444   * @}
445   */
446 
447 /** @defgroup CAN_wake_up_constants
448   * @{
449   */
450 
451 #define CAN_WakeUp_Failed        ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */
452 #define CAN_WakeUp_Ok            ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
453 
454 /**
455   * @}
456   */
457 
458 /**
459   * @defgroup   CAN_Error_Code_constants
460   * @{
461   */
462 
463 #define CAN_ErrorCode_NoErr           ((uint8_t)0x00) /*!< No Error */
464 #define CAN_ErrorCode_StuffErr        ((uint8_t)0x10) /*!< Stuff Error */
465 #define CAN_ErrorCode_FormErr         ((uint8_t)0x20) /*!< Form Error */
466 #define CAN_ErrorCode_ACKErr          ((uint8_t)0x30) /*!< Acknowledgment Error */
467 #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */
468 #define CAN_ErrorCode_BitDominantErr  ((uint8_t)0x50) /*!< Bit Dominant Error */
469 #define CAN_ErrorCode_CRCErr          ((uint8_t)0x60) /*!< CRC Error  */
470 #define CAN_ErrorCode_SoftwareSetErr  ((uint8_t)0x70) /*!< Software Set Error */
471 
472 
473 /**
474   * @}
475   */
476 
477 /** @defgroup CAN_flags
478   * @{
479   */
480 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
481    and CAN_ClearFlag() functions. */
482 /* If the flag is 0x1XXXXXXX, it means that it can only be used with CAN_GetFlagStatus() function.  */
483 
484 /* Transmit Flags */
485 #define CAN_FLAG_RQCP0             ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */
486 #define CAN_FLAG_RQCP1             ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */
487 #define CAN_FLAG_RQCP2             ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */
488 
489 /* Receive Flags */
490 #define CAN_FLAG_FMP0              ((uint32_t)0x12000003) /*!< FIFO 0 Message Pending Flag */
491 #define CAN_FLAG_FF0               ((uint32_t)0x32000008) /*!< FIFO 0 Full Flag            */
492 #define CAN_FLAG_FOV0              ((uint32_t)0x32000010) /*!< FIFO 0 Overrun Flag         */
493 #define CAN_FLAG_FMP1              ((uint32_t)0x14000003) /*!< FIFO 1 Message Pending Flag */
494 #define CAN_FLAG_FF1               ((uint32_t)0x34000008) /*!< FIFO 1 Full Flag            */
495 #define CAN_FLAG_FOV1              ((uint32_t)0x34000010) /*!< FIFO 1 Overrun Flag         */
496 
497 /* Operating Mode Flags */
498 #define CAN_FLAG_WKU               ((uint32_t)0x31000008) /*!< Wake up Flag */
499 #define CAN_FLAG_SLAK              ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */
500 /* Note: When SLAK intterupt is disabled (SLKIE=0), no polling on SLAKI is possible.
501          In this case the SLAK bit can be polled.*/
502 
503 /* Error Flags */
504 #define CAN_FLAG_EWG               ((uint32_t)0x10F00001) /*!< Error Warning Flag   */
505 #define CAN_FLAG_EPV               ((uint32_t)0x10F00002) /*!< Error Passive Flag   */
506 #define CAN_FLAG_BOF               ((uint32_t)0x10F00004) /*!< Bus-Off Flag         */
507 #define CAN_FLAG_LEC               ((uint32_t)0x30F00070) /*!< Last error code Flag */
508 
509 #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC)  || ((FLAG) == CAN_FLAG_BOF)   || \
510                                ((FLAG) == CAN_FLAG_EPV)  || ((FLAG) == CAN_FLAG_EWG)   || \
511                                ((FLAG) == CAN_FLAG_WKU)  || ((FLAG) == CAN_FLAG_FOV0)  || \
512                                ((FLAG) == CAN_FLAG_FF0)  || ((FLAG) == CAN_FLAG_FMP0)  || \
513                                ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1)   || \
514                                ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
515                                ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
516                                ((FLAG) == CAN_FLAG_SLAK ))
517 
518 #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
519                                 ((FLAG) == CAN_FLAG_RQCP1)  || ((FLAG) == CAN_FLAG_RQCP0) || \
520                                 ((FLAG) == CAN_FLAG_FF0)  || ((FLAG) == CAN_FLAG_FOV0) ||\
521                                 ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
522                                 ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
523 /**
524   * @}
525   */
526 
527 
528 /** @defgroup CAN_interrupts
529   * @{
530   */
531 
532 
533 
534 #define CAN_IT_TME                  ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/
535 
536 /* Receive Interrupts */
537 #define CAN_IT_FMP0                 ((uint32_t)0x00000002) /*!< FIFO 0 message pending Interrupt*/
538 #define CAN_IT_FF0                  ((uint32_t)0x00000004) /*!< FIFO 0 full Interrupt*/
539 #define CAN_IT_FOV0                 ((uint32_t)0x00000008) /*!< FIFO 0 overrun Interrupt*/
540 #define CAN_IT_FMP1                 ((uint32_t)0x00000010) /*!< FIFO 1 message pending Interrupt*/
541 #define CAN_IT_FF1                  ((uint32_t)0x00000020) /*!< FIFO 1 full Interrupt*/
542 #define CAN_IT_FOV1                 ((uint32_t)0x00000040) /*!< FIFO 1 overrun Interrupt*/
543 
544 /* Operating Mode Interrupts */
545 #define CAN_IT_WKU                  ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/
546 #define CAN_IT_SLK                  ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/
547 
548 /* Error Interrupts */
549 #define CAN_IT_EWG                  ((uint32_t)0x00000100) /*!< Error warning Interrupt*/
550 #define CAN_IT_EPV                  ((uint32_t)0x00000200) /*!< Error passive Interrupt*/
551 #define CAN_IT_BOF                  ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/
552 #define CAN_IT_LEC                  ((uint32_t)0x00000800) /*!< Last error code Interrupt*/
553 #define CAN_IT_ERR                  ((uint32_t)0x00008000) /*!< Error Interrupt*/
554 
555 /* Flags named as Interrupts : kept only for FW compatibility */
556 #define CAN_IT_RQCP0   CAN_IT_TME
557 #define CAN_IT_RQCP1   CAN_IT_TME
558 #define CAN_IT_RQCP2   CAN_IT_TME
559 
560 
561 #define IS_CAN_IT(IT)        (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0)  ||\
562                              ((IT) == CAN_IT_FF0)  || ((IT) == CAN_IT_FOV0)  ||\
563                              ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1)   ||\
564                              ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG)   ||\
565                              ((IT) == CAN_IT_EPV)  || ((IT) == CAN_IT_BOF)   ||\
566                              ((IT) == CAN_IT_LEC)  || ((IT) == CAN_IT_ERR)   ||\
567                              ((IT) == CAN_IT_WKU)  || ((IT) == CAN_IT_SLK))
568 
569 #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0)    ||\
570                              ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1)    ||\
571                              ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG)    ||\
572                              ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF)    ||\
573                              ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR)    ||\
574                              ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
575 
576 /**
577   * @}
578   */
579 
580 /** @defgroup CAN_Legacy
581   * @{
582   */
583 #define CANINITFAILED               CAN_InitStatus_Failed
584 #define CANINITOK                   CAN_InitStatus_Success
585 #define CAN_FilterFIFO0             CAN_Filter_FIFO0
586 #define CAN_FilterFIFO1             CAN_Filter_FIFO1
587 #define CAN_ID_STD                  CAN_Id_Standard
588 #define CAN_ID_EXT                  CAN_Id_Extended
589 #define CAN_RTR_DATA                CAN_RTR_Data
590 #define CAN_RTR_REMOTE              CAN_RTR_Remote
591 #define CANTXFAILE                  CAN_TxStatus_Failed
592 #define CANTXOK                     CAN_TxStatus_Ok
593 #define CANTXPENDING                CAN_TxStatus_Pending
594 #define CAN_NO_MB                   CAN_TxStatus_NoMailBox
595 #define CANSLEEPFAILED              CAN_Sleep_Failed
596 #define CANSLEEPOK                  CAN_Sleep_Ok
597 #define CANWAKEUPFAILED             CAN_WakeUp_Failed
598 #define CANWAKEUPOK                 CAN_WakeUp_Ok
599 
600 /**
601   * @}
602   */
603 
604 /**
605   * @}
606   */
607 
608 /** @defgroup CAN_Exported_Macros
609   * @{
610   */
611 
612 /**
613   * @}
614   */
615 
616 /** @defgroup CAN_Exported_Functions
617   * @{
618   */
619 /*  Function used to set the CAN configuration to the default reset state *****/
620 void CAN_DeInit(CAN_TypeDef* CANx);
621 
622 /* Initialization and Configuration functions *********************************/
623 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
624 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
625 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
626 void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
627 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
628 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
629 
630 /* Transmit functions *********************************************************/
631 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
632 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
633 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
634 
635 /* Receive functions **********************************************************/
636 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
637 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
638 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
639 
640 
641 /* Operation modes functions **************************************************/
642 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
643 uint8_t CAN_Sleep(CAN_TypeDef* CANx);
644 uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
645 
646 /* Error management functions *************************************************/
647 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
648 uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx);
649 uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx);
650 
651 /* Interrupts and flags management functions **********************************/
652 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
653 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
654 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
655 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
656 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
657 
658 #ifdef __cplusplus
659 }
660 #endif
661 
662 #endif /* __AIR32F10x_CAN_H */
663 /**
664   * @}
665   */
666 
667 /**
668   * @}
669   */
670 
671 /**
672   * @}
673   */
674 
675