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