stm32f4xx_hal_can.h 35.8 KB
Newer Older
Dave Hylands's avatar
Dave Hylands committed
1
2
3
4
/**
  ******************************************************************************
  * @file    stm32f4xx_hal_can.h
  * @author  MCD Application Team
5
6
  * @version V1.5.1
  * @date    01-July-2016
Dave Hylands's avatar
Dave Hylands committed
7
8
9
10
  * @brief   Header file of CAN HAL module.
  ******************************************************************************
  * @attention
  *
11
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Dave Hylands's avatar
Dave Hylands committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F4xx_HAL_CAN_H
#define __STM32F4xx_HAL_CAN_H

#ifdef __cplusplus
 extern "C" {
#endif

46
47
48
49
#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
    defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  	defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)   || defined(STM32F412Zx) ||\
    defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx)
Dave Hylands's avatar
Dave Hylands committed
50
51
52
53
54
55
56
57
58
59
60
61
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal_def.h"

/** @addtogroup STM32F4xx_HAL_Driver
  * @{
  */

/** @addtogroup CAN
  * @{
  */

/* Exported types ------------------------------------------------------------*/
62
63
64
/** @defgroup CAN_Exported_Types CAN Exported Types
  * @{
  */
Dave Hylands's avatar
Dave Hylands committed
65

66
67
68
/**
  * @brief  HAL State structures definition
  */
Dave Hylands's avatar
Dave Hylands committed
69
70
typedef enum
{
71
72
73
74
75
76
77
78
  HAL_CAN_STATE_RESET             = 0x00U,  /*!< CAN not yet initialized or disabled */
  HAL_CAN_STATE_READY             = 0x01U,  /*!< CAN initialized and ready for use   */
  HAL_CAN_STATE_BUSY              = 0x02U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_TX           = 0x12U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_RX           = 0x22U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_BUSY_TX_RX        = 0x32U,  /*!< CAN process is ongoing              */
  HAL_CAN_STATE_TIMEOUT           = 0x03U,  /*!< Timeout state                       */
  HAL_CAN_STATE_ERROR             = 0x04U   /*!< CAN error state                     */
Dave Hylands's avatar
Dave Hylands committed
79
80
81

}HAL_CAN_StateTypeDef;

82
/**
Dave Hylands's avatar
Dave Hylands committed
83
84
85
86
  * @brief  CAN init structure definition
  */
typedef struct
{
87
  uint32_t Prescaler;  /*!< Specifies the length of a time quantum.
Dave Hylands's avatar
Dave Hylands committed
88
                            This parameter must be a number between Min_Data = 1 and Max_Data = 1024 */
89

Dave Hylands's avatar
Dave Hylands committed
90
91
92
  uint32_t Mode;       /*!< Specifies the CAN operating mode.
                            This parameter can be a value of @ref CAN_operating_mode */

93
94
  uint32_t SJW;        /*!< Specifies the maximum number of time quanta
                            the CAN hardware is allowed to lengthen or
Dave Hylands's avatar
Dave Hylands committed
95
96
97
                            shorten a bit to perform resynchronization.
                            This parameter can be a value of @ref CAN_synchronisation_jump_width */

98
  uint32_t BS1;        /*!< Specifies the number of time quanta in Bit Segment 1.
Dave Hylands's avatar
Dave Hylands committed
99
                            This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */
100

Dave Hylands's avatar
Dave Hylands committed
101
102
  uint32_t BS2;        /*!< Specifies the number of time quanta in Bit Segment 2.
                            This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */
103

Dave Hylands's avatar
Dave Hylands committed
104
105
  uint32_t TTCM;       /*!< Enable or disable the time triggered communication mode.
                            This parameter can be set to ENABLE or DISABLE. */
106

Dave Hylands's avatar
Dave Hylands committed
107
108
109
  uint32_t ABOM;       /*!< Enable or disable the automatic bus-off management.
                            This parameter can be set to ENABLE or DISABLE */

110
  uint32_t AWUM;       /*!< Enable or disable the automatic wake-up mode.
Dave Hylands's avatar
Dave Hylands committed
111
112
113
114
115
116
117
118
119
120
121
122
                            This parameter can be set to ENABLE or DISABLE */

  uint32_t NART;       /*!< Enable or disable the non-automatic retransmission mode.
                            This parameter can be set to ENABLE or DISABLE */

  uint32_t RFLM;       /*!< Enable or disable the receive FIFO Locked mode.
                            This parameter can be set to ENABLE or DISABLE */

  uint32_t TXFP;       /*!< Enable or disable the transmit FIFO priority.
                            This parameter can be set to ENABLE or DISABLE */
}CAN_InitTypeDef;

123
/**
Dave Hylands's avatar
Dave Hylands committed
124
125
126
127
128
129
  * @brief  CAN filter configuration structure definition
  */
typedef struct
{
  uint32_t FilterIdHigh;          /*!< Specifies the filter identification number (MSBs for a 32-bit
                                       configuration, first one for a 16-bit configuration).
130
131
                                       This parameter must be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */

Dave Hylands's avatar
Dave Hylands committed
132
133
  uint32_t FilterIdLow;           /*!< Specifies the filter identification number (LSBs for a 32-bit
                                       configuration, second one for a 16-bit configuration).
134
                                       This parameter must be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */
Dave Hylands's avatar
Dave Hylands committed
135
136
137
138

  uint32_t FilterMaskIdHigh;      /*!< Specifies the filter mask number or identification number,
                                       according to the mode (MSBs for a 32-bit configuration,
                                       first one for a 16-bit configuration).
139
                                       This parameter must be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */
Dave Hylands's avatar
Dave Hylands committed
140
141
142
143

  uint32_t FilterMaskIdLow;       /*!< Specifies the filter mask number or identification number,
                                       according to the mode (LSBs for a 32-bit configuration,
                                       second one for a 16-bit configuration).
144
                                       This parameter must be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */
Dave Hylands's avatar
Dave Hylands committed
145
146
147

  uint32_t FilterFIFOAssignment;  /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
                                       This parameter can be a value of @ref CAN_filter_FIFO */
148
149

  uint32_t FilterNumber;          /*!< Specifies the filter which will be initialized.
Dave Hylands's avatar
Dave Hylands committed
150
151
152
153
154
155
156
157
158
159
                                       This parameter must be a number between Min_Data = 0 and Max_Data = 27 */

  uint32_t FilterMode;            /*!< Specifies the filter mode to be initialized.
                                       This parameter can be a value of @ref CAN_filter_mode */

  uint32_t FilterScale;           /*!< Specifies the filter scale.
                                       This parameter can be a value of @ref CAN_filter_scale */

  uint32_t FilterActivation;      /*!< Enable or disable the filter.
                                       This parameter can be set to ENABLE or DISABLE. */
160

161
  uint32_t BankNumber;            /*!< Select the start slave bank filter.
162
163
                                       This parameter must be a number between Min_Data = 0 and Max_Data = 28 */

Dave Hylands's avatar
Dave Hylands committed
164
165
}CAN_FilterConfTypeDef;

166
167
/**
  * @brief  CAN Tx message structure definition
Dave Hylands's avatar
Dave Hylands committed
168
169
170
171
  */
typedef struct
{
  uint32_t StdId;    /*!< Specifies the standard identifier.
172
173
                          This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */

Dave Hylands's avatar
Dave Hylands committed
174
  uint32_t ExtId;    /*!< Specifies the extended identifier.
175
176
                          This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFFU */

Dave Hylands's avatar
Dave Hylands committed
177
  uint32_t IDE;      /*!< Specifies the type of identifier for the message that will be transmitted.
178
                          This parameter can be a value of @ref CAN_Identifier_Type */
Dave Hylands's avatar
Dave Hylands committed
179
180

  uint32_t RTR;      /*!< Specifies the type of frame for the message that will be transmitted.
181
                          This parameter can be a value of @ref CAN_remote_transmission_request */
Dave Hylands's avatar
Dave Hylands committed
182
183
184
185

  uint32_t DLC;      /*!< Specifies the length of the frame that will be transmitted.
                          This parameter must be a number between Min_Data = 0 and Max_Data = 8 */

186
  uint8_t Data[8];   /*!< Contains the data to be transmitted.
Dave Hylands's avatar
Dave Hylands committed
187
                          This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
188

Dave Hylands's avatar
Dave Hylands committed
189
190
}CanTxMsgTypeDef;

191
192
/**
  * @brief  CAN Rx message structure definition
Dave Hylands's avatar
Dave Hylands committed
193
194
195
196
  */
typedef struct
{
  uint32_t StdId;       /*!< Specifies the standard identifier.
197
                             This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */
Dave Hylands's avatar
Dave Hylands committed
198
199

  uint32_t ExtId;       /*!< Specifies the extended identifier.
200
                             This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFFU */
Dave Hylands's avatar
Dave Hylands committed
201

202
203
  uint32_t IDE;         /*!< Specifies the type of identifier for the message that will be received.
                             This parameter can be a value of @ref CAN_Identifier_Type */
Dave Hylands's avatar
Dave Hylands committed
204
205
206
207
208
209
210

  uint32_t RTR;         /*!< Specifies the type of frame for the received message.
                             This parameter can be a value of @ref CAN_remote_transmission_request */

  uint32_t DLC;         /*!< Specifies the length of the frame that will be received.
                             This parameter must be a number between Min_Data = 0 and Max_Data = 8 */

211
  uint8_t Data[8];      /*!< Contains the data to be received.
Dave Hylands's avatar
Dave Hylands committed
212
213
214
215
                             This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */

  uint32_t FMI;         /*!< Specifies the index of the filter the message stored in the mailbox passes through.
                             This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
216
217

  uint32_t FIFONumber;  /*!< Specifies the receive FIFO number.
Dave Hylands's avatar
Dave Hylands committed
218
                             This parameter can be CAN_FIFO0 or CAN_FIFO1 */
219

Dave Hylands's avatar
Dave Hylands committed
220
221
}CanRxMsgTypeDef;

222
223
224
/**
  * @brief  CAN handle Structure definition
  */
Dave Hylands's avatar
Dave Hylands committed
225
226
227
typedef struct
{
  CAN_TypeDef                 *Instance;  /*!< Register base address          */
228

Dave Hylands's avatar
Dave Hylands committed
229
  CAN_InitTypeDef             Init;       /*!< CAN required parameters        */
230

Dave Hylands's avatar
Dave Hylands committed
231
232
233
  CanTxMsgTypeDef*            pTxMsg;     /*!< Pointer to transmit structure  */

  CanRxMsgTypeDef*            pRxMsg;     /*!< Pointer to reception structure */
234

Dave Hylands's avatar
Dave Hylands committed
235
  __IO HAL_CAN_StateTypeDef   State;      /*!< CAN communication state        */
236

Dave Hylands's avatar
Dave Hylands committed
237
  HAL_LockTypeDef             Lock;       /*!< CAN locking object             */
238

Dave Hylands's avatar
Dave Hylands committed
239
  __IO uint32_t               ErrorCode;  /*!< CAN Error code                 */
240

Dave Hylands's avatar
Dave Hylands committed
241
242
}CAN_HandleTypeDef;

243
244
245
/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
246

247
248
/* Exported constants --------------------------------------------------------*/
/** @defgroup CAN_Exported_Constants CAN Exported Constants
Dave Hylands's avatar
Dave Hylands committed
249
250
251
  * @{
  */

252
/** @defgroup HAL_CAN_Error_Code HAL CAN Error Code
Dave Hylands's avatar
Dave Hylands committed
253
254
  * @{
  */
255
256
257
258
259
260
261
262
263
264
#define   HAL_CAN_ERROR_NONE      0x00U    /*!< No error             */
#define   HAL_CAN_ERROR_EWG       0x01U    /*!< EWG error            */
#define   HAL_CAN_ERROR_EPV       0x02U    /*!< EPV error            */
#define   HAL_CAN_ERROR_BOF       0x04U    /*!< BOF error            */
#define   HAL_CAN_ERROR_STF       0x08U    /*!< Stuff error          */
#define   HAL_CAN_ERROR_FOR       0x10U    /*!< Form error           */
#define   HAL_CAN_ERROR_ACK       0x20U    /*!< Acknowledgment error */
#define   HAL_CAN_ERROR_BR        0x40U    /*!< Bit recessive        */
#define   HAL_CAN_ERROR_BD        0x80U    /*!< LEC dominant         */
#define   HAL_CAN_ERROR_CRC       0x100U   /*!< LEC transfer error   */
Dave Hylands's avatar
Dave Hylands committed
265
266
/**
  * @}
267
  */
Dave Hylands's avatar
Dave Hylands committed
268

269
/** @defgroup CAN_InitStatus CAN InitStatus
Dave Hylands's avatar
Dave Hylands committed
270
271
  * @{
  */
272
273
#define CAN_INITSTATUS_FAILED       ((uint8_t)0x00U)  /*!< CAN initialization failed */
#define CAN_INITSTATUS_SUCCESS      ((uint8_t)0x01U)  /*!< CAN initialization OK */
Dave Hylands's avatar
Dave Hylands committed
274
275
276
277
/**
  * @}
  */

278
/** @defgroup CAN_operating_mode CAN Operating Mode
Dave Hylands's avatar
Dave Hylands committed
279
280
  * @{
  */
281
#define CAN_MODE_NORMAL             ((uint32_t)0x00000000U)                     /*!< Normal mode   */
Dave Hylands's avatar
Dave Hylands committed
282
283
284
285
286
287
288
#define CAN_MODE_LOOPBACK           ((uint32_t)CAN_BTR_LBKM)                   /*!< Loopback mode */
#define CAN_MODE_SILENT             ((uint32_t)CAN_BTR_SILM)                   /*!< Silent mode   */
#define CAN_MODE_SILENT_LOOPBACK    ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM))  /*!< Loopback combined with silent mode */
/**
  * @}
  */

289
/** @defgroup CAN_synchronisation_jump_width CAN Synchronisation Jump Width
Dave Hylands's avatar
Dave Hylands committed
290
291
  * @{
  */
292
#define CAN_SJW_1TQ                 ((uint32_t)0x00000000U)     /*!< 1 time quantum */
Dave Hylands's avatar
Dave Hylands committed
293
294
295
296
297
298
299
#define CAN_SJW_2TQ                 ((uint32_t)CAN_BTR_SJW_0)  /*!< 2 time quantum */
#define CAN_SJW_3TQ                 ((uint32_t)CAN_BTR_SJW_1)  /*!< 3 time quantum */
#define CAN_SJW_4TQ                 ((uint32_t)CAN_BTR_SJW)    /*!< 4 time quantum */
/**
  * @}
  */

300
/** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in bit segment 1
Dave Hylands's avatar
Dave Hylands committed
301
302
  * @{
  */
303
#define CAN_BS1_1TQ                 ((uint32_t)0x00000000U)                                       /*!< 1 time quantum  */
Dave Hylands's avatar
Dave Hylands committed
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#define CAN_BS1_2TQ                 ((uint32_t)CAN_BTR_TS1_0)                                    /*!< 2 time quantum  */
#define CAN_BS1_3TQ                 ((uint32_t)CAN_BTR_TS1_1)                                    /*!< 3 time quantum  */
#define CAN_BS1_4TQ                 ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0))                  /*!< 4 time quantum  */
#define CAN_BS1_5TQ                 ((uint32_t)CAN_BTR_TS1_2)                                    /*!< 5 time quantum  */
#define CAN_BS1_6TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0))                  /*!< 6 time quantum  */
#define CAN_BS1_7TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1))                  /*!< 7 time quantum  */
#define CAN_BS1_8TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 8 time quantum  */
#define CAN_BS1_9TQ                 ((uint32_t)CAN_BTR_TS1_3)                                    /*!< 9 time quantum  */
#define CAN_BS1_10TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0))                  /*!< 10 time quantum */
#define CAN_BS1_11TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1))                  /*!< 11 time quantum */
#define CAN_BS1_12TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 12 time quantum */
#define CAN_BS1_13TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2))                  /*!< 13 time quantum */
#define CAN_BS1_14TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0))  /*!< 14 time quantum */
#define CAN_BS1_15TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1))  /*!< 15 time quantum */
#define CAN_BS1_16TQ                ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */
/**
  * @}
  */

323
/** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in bit segment 2
Dave Hylands's avatar
Dave Hylands committed
324
325
  * @{
  */
326
#define CAN_BS2_1TQ                 ((uint32_t)0x00000000U)                       /*!< 1 time quantum */
Dave Hylands's avatar
Dave Hylands committed
327
328
329
330
331
332
333
334
335
336
337
#define CAN_BS2_2TQ                 ((uint32_t)CAN_BTR_TS2_0)                    /*!< 2 time quantum */
#define CAN_BS2_3TQ                 ((uint32_t)CAN_BTR_TS2_1)                    /*!< 3 time quantum */
#define CAN_BS2_4TQ                 ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0))  /*!< 4 time quantum */
#define CAN_BS2_5TQ                 ((uint32_t)CAN_BTR_TS2_2)                    /*!< 5 time quantum */
#define CAN_BS2_6TQ                 ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0))  /*!< 6 time quantum */
#define CAN_BS2_7TQ                 ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1))  /*!< 7 time quantum */
#define CAN_BS2_8TQ                 ((uint32_t)CAN_BTR_TS2)                      /*!< 8 time quantum */
/**
  * @}
  */

338
/** @defgroup CAN_filter_mode  CAN Filter Mode
Dave Hylands's avatar
Dave Hylands committed
339
340
  * @{
  */
341
342
#define CAN_FILTERMODE_IDMASK       ((uint8_t)0x00U)  /*!< Identifier mask mode */
#define CAN_FILTERMODE_IDLIST       ((uint8_t)0x01U)  /*!< Identifier list mode */
Dave Hylands's avatar
Dave Hylands committed
343
344
345
346
/**
  * @}
  */

347
/** @defgroup CAN_filter_scale CAN Filter Scale
Dave Hylands's avatar
Dave Hylands committed
348
349
  * @{
  */
350
351
#define CAN_FILTERSCALE_16BIT       ((uint8_t)0x00U)  /*!< Two 16-bit filters */
#define CAN_FILTERSCALE_32BIT       ((uint8_t)0x01U)  /*!< One 32-bit filter  */
Dave Hylands's avatar
Dave Hylands committed
352
353
354
355
/**
  * @}
  */

356
/** @defgroup CAN_filter_FIFO CAN Filter FIFO
Dave Hylands's avatar
Dave Hylands committed
357
358
  * @{
  */
359
360
#define CAN_FILTER_FIFO0             ((uint8_t)0x00U)  /*!< Filter FIFO 0 assignment for filter x */
#define CAN_FILTER_FIFO1             ((uint8_t)0x01U)  /*!< Filter FIFO 1 assignment for filter x */
Dave Hylands's avatar
Dave Hylands committed
361
362
363
364
/**
  * @}
  */

365
/** @defgroup CAN_Identifier_Type CAN Identifier Type
Dave Hylands's avatar
Dave Hylands committed
366
367
  * @{
  */
368
369
#define CAN_ID_STD             ((uint32_t)0x00000000U)  /*!< Standard Id */
#define CAN_ID_EXT             ((uint32_t)0x00000004U)  /*!< Extended Id */
Dave Hylands's avatar
Dave Hylands committed
370
371
372
373
/**
  * @}
  */

374
/** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request
Dave Hylands's avatar
Dave Hylands committed
375
376
  * @{
  */
377
378
#define CAN_RTR_DATA                ((uint32_t)0x00000000U)  /*!< Data frame */
#define CAN_RTR_REMOTE              ((uint32_t)0x00000002U)  /*!< Remote frame */
Dave Hylands's avatar
Dave Hylands committed
379
380
381
382
/**
  * @}
  */

383
/** @defgroup CAN_receive_FIFO_number_constants CAN Receive FIFO Number Constants
Dave Hylands's avatar
Dave Hylands committed
384
385
  * @{
  */
386
387
#define CAN_FIFO0                   ((uint8_t)0x00U)  /*!< CAN FIFO 0 used to receive */
#define CAN_FIFO1                   ((uint8_t)0x01U)  /*!< CAN FIFO 1 used to receive */
Dave Hylands's avatar
Dave Hylands committed
388
389
390
391
/**
  * @}
  */

392
/** @defgroup CAN_flags CAN Flags
Dave Hylands's avatar
Dave Hylands committed
393
394
395
396
  * @{
  */
/* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
   and CAN_ClearFlag() functions. */
397
/* If the flag is 0x1XXXXXXX, it means that it can only be used with
Dave Hylands's avatar
Dave Hylands committed
398
399
400
   CAN_GetFlagStatus() function.  */

/* Transmit Flags */
401
402
403
404
405
406
407
408
409
#define CAN_FLAG_RQCP0             ((uint32_t)0x00000500U)  /*!< Request MailBox0 flag         */
#define CAN_FLAG_RQCP1             ((uint32_t)0x00000508U)  /*!< Request MailBox1 flag         */
#define CAN_FLAG_RQCP2             ((uint32_t)0x00000510U)  /*!< Request MailBox2 flag         */
#define CAN_FLAG_TXOK0             ((uint32_t)0x00000501U)  /*!< Transmission OK MailBox0 flag */
#define CAN_FLAG_TXOK1             ((uint32_t)0x00000509U)  /*!< Transmission OK MailBox1 flag */
#define CAN_FLAG_TXOK2             ((uint32_t)0x00000511U)  /*!< Transmission OK MailBox2 flag */
#define CAN_FLAG_TME0              ((uint32_t)0x0000051AU)  /*!< Transmit mailbox 0 empty flag */
#define CAN_FLAG_TME1              ((uint32_t)0x0000051BU)  /*!< Transmit mailbox 0 empty flag */
#define CAN_FLAG_TME2              ((uint32_t)0x0000051CU)  /*!< Transmit mailbox 0 empty flag */
Dave Hylands's avatar
Dave Hylands committed
410
411

/* Receive Flags */
412
413
#define CAN_FLAG_FF0               ((uint32_t)0x00000203U)  /*!< FIFO 0 Full flag    */
#define CAN_FLAG_FOV0              ((uint32_t)0x00000204U)  /*!< FIFO 0 Overrun flag */
Dave Hylands's avatar
Dave Hylands committed
414

415
416
#define CAN_FLAG_FF1               ((uint32_t)0x00000403U)  /*!< FIFO 1 Full flag    */
#define CAN_FLAG_FOV1              ((uint32_t)0x00000404U)  /*!< FIFO 1 Overrun flag */
Dave Hylands's avatar
Dave Hylands committed
417
418

/* Operating Mode Flags */
419
420
421
422
423
424
425
#define CAN_FLAG_INAK              ((uint32_t)0x00000100U)  /*!<  Initialization acknowledge flag */
#define CAN_FLAG_SLAK              ((uint32_t)0x00000101U)  /*!< Sleep acknowledge flag */
#define CAN_FLAG_ERRI              ((uint32_t)0x00000102U)  /*!<  Error flag */
#define CAN_FLAG_WKU               ((uint32_t)0x00000103U)  /*!< Wake up flag           */
#define CAN_FLAG_SLAKI             ((uint32_t)0x00000104U)  /*!< Sleep acknowledge flag */

/* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible.
Dave Hylands's avatar
Dave Hylands committed
426
427
428
         In this case the SLAK bit can be polled.*/

/* Error Flags */
429
430
431
#define CAN_FLAG_EWG               ((uint32_t)0x00000300U)  /*!< Error warning flag   */
#define CAN_FLAG_EPV               ((uint32_t)0x00000301U)  /*!< Error passive flag   */
#define CAN_FLAG_BOF               ((uint32_t)0x00000302U)  /*!< Bus-Off flag         */
Dave Hylands's avatar
Dave Hylands committed
432
433
434
435
/**
  * @}
  */

436
/** @defgroup CAN_Interrupts CAN Interrupts
Dave Hylands's avatar
Dave Hylands committed
437
  * @{
438
  */
Dave Hylands's avatar
Dave Hylands committed
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#define CAN_IT_TME                  ((uint32_t)CAN_IER_TMEIE)   /*!< Transmit mailbox empty interrupt */

/* Receive Interrupts */
#define CAN_IT_FMP0                 ((uint32_t)CAN_IER_FMPIE0)  /*!< FIFO 0 message pending interrupt */
#define CAN_IT_FF0                  ((uint32_t)CAN_IER_FFIE0)   /*!< FIFO 0 full interrupt            */
#define CAN_IT_FOV0                 ((uint32_t)CAN_IER_FOVIE0)  /*!< FIFO 0 overrun interrupt         */
#define CAN_IT_FMP1                 ((uint32_t)CAN_IER_FMPIE1)  /*!< FIFO 1 message pending interrupt */
#define CAN_IT_FF1                  ((uint32_t)CAN_IER_FFIE1)   /*!< FIFO 1 full interrupt            */
#define CAN_IT_FOV1                 ((uint32_t)CAN_IER_FOVIE1)  /*!< FIFO 1 overrun interrupt         */

/* Operating Mode Interrupts */
#define CAN_IT_WKU                  ((uint32_t)CAN_IER_WKUIE)  /*!< Wake-up interrupt           */
#define CAN_IT_SLK                  ((uint32_t)CAN_IER_SLKIE)  /*!< Sleep acknowledge interrupt */

/* Error Interrupts */
#define CAN_IT_EWG                  ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt   */
#define CAN_IT_EPV                  ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt   */
#define CAN_IT_BOF                  ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt         */
#define CAN_IT_LEC                  ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */
#define CAN_IT_ERR                  ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt           */
/**
  * @}
  */

463
464
465
466
467
468
469
470
471
/** @defgroup CAN_Mailboxes_Definition CAN Mailboxes Definition
  * @{
  */
#define CAN_TXMAILBOX_0   ((uint8_t)0x00U)
#define CAN_TXMAILBOX_1   ((uint8_t)0x01U)
#define CAN_TXMAILBOX_2   ((uint8_t)0x02U)
/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
472
473
474
475
476
477

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
478
479
480
/** @defgroup CAN_Exported_Macros CAN Exported Macros
  * @{
  */
Dave Hylands's avatar
Dave Hylands committed
481

482
483
484
485
486
487
/** @brief Reset CAN handle state
  * @param  __HANDLE__: specifies the CAN Handle.
  * @retval None
  */
#define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET)

Dave Hylands's avatar
Dave Hylands committed
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/**
  * @brief  Enable the specified CAN interrupts.
  * @param  __HANDLE__: CAN handle
  * @param  __INTERRUPT__: CAN Interrupt
  * @retval None
  */
#define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))

/**
  * @brief  Disable the specified CAN interrupts.
  * @param  __HANDLE__: CAN handle
  * @param  __INTERRUPT__: CAN Interrupt
  * @retval None
  */
#define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))

/**
  * @brief  Return the number of pending received messages.
  * @param  __HANDLE__: CAN handle
  * @param  __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
  * @retval The number of pending message.
  */
#define __HAL_CAN_MSG_PENDING(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
511
((uint8_t)((__HANDLE__)->Instance->RF0R&(uint32_t)0x03U)) : ((uint8_t)((__HANDLE__)->Instance->RF1R & (uint32_t)0x03U)))
Dave Hylands's avatar
Dave Hylands committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

/** @brief  Check whether the specified CAN flag is set or not.
  * @param  __HANDLE__: CAN Handle
  * @param  __FLAG__: specifies the flag to check.
  *         This parameter can be one of the following values:
  *            @arg CAN_TSR_RQCP0: Request MailBox0 Flag
  *            @arg CAN_TSR_RQCP1: Request MailBox1 Flag
  *            @arg CAN_TSR_RQCP2: Request MailBox2 Flag
  *            @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
  *            @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
  *            @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
  *            @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
  *            @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
  *            @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
  *            @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
  *            @arg CAN_FLAG_FF0: FIFO 0 Full Flag
  *            @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
  *            @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
  *            @arg CAN_FLAG_FF1: FIFO 1 Full Flag
  *            @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
  *            @arg CAN_FLAG_WKU: Wake up Flag
  *            @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
  *            @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
  *            @arg CAN_FLAG_EWG: Error Warning Flag
  *            @arg CAN_FLAG_EPV: Error Passive Flag
  *            @arg CAN_FLAG_BOF: Bus-Off Flag
  * @retval The new state of __FLAG__ (TRUE or FALSE).
  */
#define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \
541
542
543
544
545
((((__FLAG__) >> 8U) == 5U)? ((((__HANDLE__)->Instance->TSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__FLAG__) >> 8U) == 2U)? ((((__HANDLE__)->Instance->RF0R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__FLAG__) >> 8U) == 4U)? ((((__HANDLE__)->Instance->RF1R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__FLAG__) >> 8U) == 1U)? ((((__HANDLE__)->Instance->MSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 ((((__HANDLE__)->Instance->ESR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))))
Dave Hylands's avatar
Dave Hylands committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

/** @brief  Clear the specified CAN pending flag.
  * @param  __HANDLE__: CAN Handle.
  * @param  __FLAG__: specifies the flag to check.
  *         This parameter can be one of the following values:
  *            @arg CAN_TSR_RQCP0: Request MailBox0 Flag
  *            @arg CAN_TSR_RQCP1: Request MailBox1 Flag
  *            @arg CAN_TSR_RQCP2: Request MailBox2 Flag
  *            @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
  *            @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
  *            @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
  *            @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
  *            @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
  *            @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
  *            @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
  *            @arg CAN_FLAG_FF0: FIFO 0 Full Flag
  *            @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
  *            @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
  *            @arg CAN_FLAG_FF1: FIFO 1 Full Flag
  *            @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
  *            @arg CAN_FLAG_WKU: Wake up Flag
  *            @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
  *            @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
  * @retval The new state of __FLAG__ (TRUE or FALSE).
  */
#define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \
572
573
574
575
((((__FLAG__) >> 8U) == 5U)? (((__HANDLE__)->Instance->TSR) = ((uint32_t)1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__FLAG__) >> 8U) == 2U)? (((__HANDLE__)->Instance->RF0R) = ((uint32_t)1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__FLAG__) >> 8U) == 4U)? (((__HANDLE__)->Instance->RF1R) = ((uint32_t)1U << ((__FLAG__) & CAN_FLAG_MASK))): \
 (((__HANDLE__)->Instance->MSR) = ((uint32_t)1U << ((__FLAG__) & CAN_FLAG_MASK))))
Dave Hylands's avatar
Dave Hylands committed
576
577
578
579
580
581

/** @brief  Check if the specified CAN interrupt source is enabled or disabled.
  * @param  __HANDLE__: CAN Handle
  * @param  __INTERRUPT__: specifies the CAN interrupt source to check.
  *          This parameter can be one of the following values:
  *             @arg CAN_IT_TME: Transmit mailbox empty interrupt enable
582
  *             @arg CAN_IT_FMP0: FIFO0 message pending interrupt enable
Dave Hylands's avatar
Dave Hylands committed
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  *             @arg CAN_IT_FMP1: FIFO1 message pending interrupt enable
  * @retval The new state of __IT__ (TRUE or FALSE).
  */
#define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)

/**
  * @brief  Check the transmission status of a CAN Frame.
  * @param  __HANDLE__: CAN Handle
  * @param  __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
  * @retval The new status of transmission  (TRUE or FALSE).
  */
#define __HAL_CAN_TRANSMIT_STATUS(__HANDLE__, __TRANSMITMAILBOX__)\
(((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0)) == (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0)) :\
 ((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1)) == (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1)) :\
 ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)) == (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)))

/**
  * @brief  Release the specified receive FIFO.
  * @param  __HANDLE__: CAN handle
  * @param  __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
  * @retval None
  */
#define __HAL_CAN_FIFO_RELEASE(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
606
((__HANDLE__)->Instance->RF0R = CAN_RF0R_RFOM0) : ((__HANDLE__)->Instance->RF1R = CAN_RF1R_RFOM1))
Dave Hylands's avatar
Dave Hylands committed
607
608
609
610
611
612
613
614

/**
  * @brief  Cancel a transmit request.
  * @param  __HANDLE__: CAN Handle
  * @param  __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
  * @retval None
  */
#define __HAL_CAN_CANCEL_TRANSMIT(__HANDLE__, __TRANSMITMAILBOX__)\
615
616
617
(((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((__HANDLE__)->Instance->TSR = CAN_TSR_ABRQ0) :\
 ((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((__HANDLE__)->Instance->TSR = CAN_TSR_ABRQ1) :\
 ((__HANDLE__)->Instance->TSR = CAN_TSR_ABRQ2))
Dave Hylands's avatar
Dave Hylands committed
618
619
620
621

/**
  * @brief  Enable or disable the DBG Freeze for CAN.
  * @param  __HANDLE__: CAN Handle
622
  * @param  __NEWSTATE__: new state of the CAN peripheral.
Dave Hylands's avatar
Dave Hylands committed
623
  *          This parameter can be: ENABLE (CAN reception/transmission is frozen
624
  *          during debug. Reception FIFOs can still be accessed/controlled normally)
Dave Hylands's avatar
Dave Hylands committed
625
626
627
628
  *          or DISABLE (CAN is working during debug).
  * @retval None
  */
#define __HAL_CAN_DBG_FREEZE(__HANDLE__, __NEWSTATE__) (((__NEWSTATE__) == ENABLE)? \
629
((__HANDLE__)->Instance->MCR |= CAN_MCR_DBF) : ((__HANDLE__)->Instance->MCR &= ~CAN_MCR_DBF))
Dave Hylands's avatar
Dave Hylands committed
630

631
632
633
634
635
636
637
638
639
640
641
642
643
/**
  * @}
  */

/* Exported functions --------------------------------------------------------*/
/** @addtogroup CAN_Exported_Functions
  * @{
  */

/** @addtogroup CAN_Exported_Functions_Group1
  * @{
  */
/* Initialization/de-initialization functions ***********************************/
Dave Hylands's avatar
Dave Hylands committed
644
645
646
647
648
HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan);
HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig);
HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan);
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan);
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan);
649
650
651
/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
652

653
654
655
/** @addtogroup CAN_Exported_Functions_Group2
  * @{
  */
Dave Hylands's avatar
Dave Hylands committed
656
657
658
659
660
661
662
/* I/O operation functions ******************************************************/
HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout);
HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef *hcan, uint8_t FIFONumber, uint32_t Timeout);
HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef *hcan, uint8_t FIFONumber);
HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan);
663
664
665
666
667
668
669
void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan);
void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan);
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan);
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan);
/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
670

671
672
673
/** @addtogroup CAN_Exported_Functions_Group3
  * @{
  */
Dave Hylands's avatar
Dave Hylands committed
674
675
676
/* Peripheral State functions ***************************************************/
uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan);
HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan);
677
678
679
/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
680

681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/**
  * @}
  */

/* Private types -------------------------------------------------------------*/
/** @defgroup CAN_Private_Types CAN Private Types
  * @{
  */

/**
  * @}
  */

/* Private variables ---------------------------------------------------------*/
/** @defgroup CAN_Private_Variables CAN Private Variables
  * @{
  */

/**
  * @}
  */ 

/* Private constants ---------------------------------------------------------*/
/** @defgroup CAN_Private_Constants CAN Private Constants
  * @{
  */
#define CAN_TXSTATUS_NOMAILBOX      ((uint8_t)0x04U)  /*!< CAN cell did not provide CAN_TxStatus_NoMailBox */
#define CAN_FLAG_MASK  ((uint32_t)0x000000FFU)
/**
  * @}
  */

/* Private macros ------------------------------------------------------------*/
/** @defgroup CAN_Private_Macros CAN Private Macros
  * @{
  */
#define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \
                           ((MODE) == CAN_MODE_LOOPBACK)|| \
                           ((MODE) == CAN_MODE_SILENT) || \
                           ((MODE) == CAN_MODE_SILENT_LOOPBACK))
#define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ)|| \
                         ((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ))
#define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16TQ)
#define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8TQ)
#define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1U) && ((PRESCALER) <= 1024U))
#define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27U)
#define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \
                                  ((MODE) == CAN_FILTERMODE_IDLIST))
#define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \
                                    ((SCALE) == CAN_FILTERSCALE_32BIT))
#define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \
                                  ((FIFO) == CAN_FILTER_FIFO1))
#define IS_CAN_BANKNUMBER(BANKNUMBER) ((BANKNUMBER) <= 28U)

#define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02U))
#define IS_CAN_STDID(STDID)   ((STDID) <= ((uint32_t)0x7FFU))
#define IS_CAN_EXTID(EXTID)   ((EXTID) <= ((uint32_t)0x1FFFFFFFU))
#define IS_CAN_DLC(DLC)       ((DLC) <= ((uint8_t)0x08U))

#define IS_CAN_IDTYPE(IDTYPE)  (((IDTYPE) == CAN_ID_STD) || \
                                ((IDTYPE) == CAN_ID_EXT))
#define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE))
#define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))

/**
  * @}
  */

/* Private functions ---------------------------------------------------------*/
/** @defgroup CAN_Private_Functions CAN Private Functions
  * @{
  */

/**
  * @}
  */
Dave Hylands's avatar
Dave Hylands committed
757

758
759
760
#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
          STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx ||\
          STM32F412Vx || STM32F412Rx || STM32F412Cx */
Dave Hylands's avatar
Dave Hylands committed
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __STM32F4xx_CAN_H */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/