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