TUKS MCU Introductory course / TUKS-COURSE-2-LED
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_can.h Source File

stm32l4xx_hal_can.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_can.h
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of CAN HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_CAN_H
00040 #define __STM32L4xx_CAN_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup CAN
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup CAN_Exported_Types CAN Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief  HAL State structures definition
00064   */
00065 typedef enum
00066 {
00067   HAL_CAN_STATE_RESET             = 0x00,  /*!< CAN not yet initialized or disabled */
00068   HAL_CAN_STATE_READY             = 0x01,  /*!< CAN initialized and ready for use   */
00069   HAL_CAN_STATE_BUSY              = 0x02,  /*!< CAN process is ongoing              */
00070   HAL_CAN_STATE_BUSY_TX           = 0x12,  /*!< CAN process is ongoing              */
00071   HAL_CAN_STATE_BUSY_RX           = 0x22,  /*!< CAN process is ongoing              */
00072   HAL_CAN_STATE_BUSY_TX_RX        = 0x32,  /*!< CAN process is ongoing              */
00073   HAL_CAN_STATE_TIMEOUT           = 0x03,  /*!< Timeout state                       */
00074   HAL_CAN_STATE_ERROR             = 0x04   /*!< CAN error state                     */
00075 
00076 }HAL_CAN_StateTypeDef;
00077 
00078 /**
00079   * @brief  CAN init structure definition
00080   */
00081 typedef struct
00082 {
00083   uint32_t Prescaler;  /*!< Specifies the length of a time quantum.
00084                             This parameter must be a number between Min_Data = 1 and Max_Data = 1024 */
00085 
00086   uint32_t Mode;       /*!< Specifies the CAN operating mode.
00087                             This parameter can be a value of @ref CAN_operating_mode */
00088 
00089   uint32_t SJW;        /*!< Specifies the maximum number of time quanta
00090                             the CAN hardware is allowed to lengthen or
00091                             shorten a bit to perform resynchronization.
00092                             This parameter can be a value of @ref CAN_synchronisation_jump_width */
00093 
00094   uint32_t BS1;        /*!< Specifies the number of time quanta in Bit Segment 1.
00095                             This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */
00096 
00097   uint32_t BS2;        /*!< Specifies the number of time quanta in Bit Segment 2.
00098                             This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */
00099 
00100   uint32_t TTCM;       /*!< Enable or disable the time triggered communication mode.
00101                             This parameter can be set to ENABLE or DISABLE. */
00102 
00103   uint32_t ABOM;       /*!< Enable or disable the automatic bus-off management.
00104                             This parameter can be set to ENABLE or DISABLE */
00105 
00106   uint32_t AWUM;       /*!< Enable or disable the automatic wake-up mode.
00107                             This parameter can be set to ENABLE or DISABLE */
00108 
00109   uint32_t NART;       /*!< Enable or disable the non-automatic retransmission mode.
00110                             This parameter can be set to ENABLE or DISABLE */
00111 
00112   uint32_t RFLM;       /*!< Enable or disable the receive FIFO Locked mode.
00113                             This parameter can be set to ENABLE or DISABLE */
00114 
00115   uint32_t TXFP;       /*!< Enable or disable the transmit FIFO priority.
00116                             This parameter can be set to ENABLE or DISABLE */
00117 }CAN_InitTypeDef;
00118 
00119 /**
00120   * @brief  CAN filter configuration structure definition
00121   */
00122 typedef struct
00123 {
00124   uint32_t FilterIdHigh;          /*!< Specifies the filter identification number (MSBs for a 32-bit
00125                                        configuration, first one for a 16-bit configuration).
00126                                        This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
00127 
00128   uint32_t FilterIdLow;           /*!< Specifies the filter identification number (LSBs for a 32-bit
00129                                        configuration, second one for a 16-bit configuration).
00130                                        This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
00131 
00132   uint32_t FilterMaskIdHigh;      /*!< Specifies the filter mask number or identification number,
00133                                        according to the mode (MSBs for a 32-bit configuration,
00134                                        first one for a 16-bit configuration).
00135                                        This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
00136 
00137   uint32_t FilterMaskIdLow;       /*!< Specifies the filter mask number or identification number,
00138                                        according to the mode (LSBs for a 32-bit configuration,
00139                                        second one for a 16-bit configuration).
00140                                        This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
00141 
00142   uint32_t FilterFIFOAssignment;  /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
00143                                        This parameter can be a value of @ref CAN_filter_FIFO */
00144 
00145   uint32_t FilterNumber;          /*!< Specifies the filter which will be initialized.
00146                                        This parameter must be a number between Min_Data = 0 and Max_Data = 27 */
00147 
00148   uint32_t FilterMode;            /*!< Specifies the filter mode to be initialized.
00149                                        This parameter can be a value of @ref CAN_filter_mode */
00150 
00151   uint32_t FilterScale;           /*!< Specifies the filter scale.
00152                                        This parameter can be a value of @ref CAN_filter_scale */
00153 
00154   uint32_t FilterActivation;      /*!< Enable or disable the filter.
00155                                        This parameter can be set to ENABLE or DISABLE */
00156 
00157   uint32_t BankNumber;            /*!< Select the start slave bank filter.
00158                                        This parameter must be a number between Min_Data = 0 and Max_Data = 28 */ 
00159 
00160 }CAN_FilterConfTypeDef;
00161 
00162 /**
00163   * @brief  CAN Tx message structure definition
00164   */
00165 typedef struct
00166 {
00167   uint32_t StdId;    /*!< Specifies the standard identifier.
00168                           This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */
00169 
00170   uint32_t ExtId;    /*!< Specifies the extended identifier.
00171                           This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */
00172 
00173   uint32_t IDE;      /*!< Specifies the type of identifier for the message that will be transmitted.
00174                           This parameter can be a value of @ref CAN_identifier_type */
00175 
00176   uint32_t RTR;      /*!< Specifies the type of frame for the message that will be transmitted.
00177                           This parameter can be a value of @ref CAN_remote_transmission_request */
00178 
00179   uint32_t DLC;      /*!< Specifies the length of the frame that will be transmitted.
00180                           This parameter must be a number between Min_Data = 0 and Max_Data = 8 */
00181 
00182   uint8_t Data[8];   /*!< Contains the data to be transmitted.
00183                           This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
00184 
00185 }CanTxMsgTypeDef;
00186 
00187 /**
00188   * @brief  CAN Rx message structure definition
00189   */
00190 typedef struct
00191 {
00192   uint32_t StdId;       /*!< Specifies the standard identifier.
00193                              This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */
00194 
00195   uint32_t ExtId;       /*!< Specifies the extended identifier.
00196                              This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */
00197 
00198   uint32_t IDE;         /*!< Specifies the type of identifier for the message that will be received.
00199                              This parameter can be a value of @ref CAN_identifier_type */
00200 
00201   uint32_t RTR;         /*!< Specifies the type of frame for the received message.
00202                              This parameter can be a value of @ref CAN_remote_transmission_request */
00203 
00204   uint32_t DLC;         /*!< Specifies the length of the frame that will be received.
00205                              This parameter must be a number between Min_Data = 0 and Max_Data = 8 */
00206 
00207   uint8_t Data[8];      /*!< Contains the data to be received.
00208                              This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
00209 
00210   uint32_t FMI;         /*!< Specifies the index of the filter the message stored in the mailbox passes through.
00211                              This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
00212 
00213   uint32_t FIFONumber;  /*!< Specifies the receive FIFO number.
00214                              This parameter can be CAN_FIFO0 or CAN_FIFO1 */
00215 
00216 }CanRxMsgTypeDef;
00217 
00218 /**
00219   * @brief  CAN handle Structure definition
00220   */
00221 typedef struct
00222 {
00223   CAN_TypeDef                 *Instance;  /*!< Register base address          */
00224 
00225   CAN_InitTypeDef             Init;       /*!< CAN required parameters        */
00226 
00227   CanTxMsgTypeDef*            pTxMsg;     /*!< Pointer to transmit structure  */
00228 
00229   CanRxMsgTypeDef*            pRxMsg;     /*!< Pointer to reception structure */
00230 
00231   __IO HAL_CAN_StateTypeDef   State;      /*!< CAN communication state        */
00232 
00233   HAL_LockTypeDef             Lock;       /*!< CAN locking object             */
00234 
00235   __IO uint32_t               ErrorCode;  /*!< CAN Error code                 */
00236 
00237 }CAN_HandleTypeDef;
00238 
00239 /**
00240   * @}
00241   */
00242 
00243 /* Exported constants --------------------------------------------------------*/
00244 /** @defgroup CAN_Exported_Constants CAN Exported Constants
00245   * @{
00246   */
00247 
00248 /** @defgroup CAN_Error_Code CAN Error Code
00249   * @{
00250   */
00251 #define   HAL_CAN_ERROR_NONE        ((uint32_t)0x00000000)    /*!< No error             */
00252 #define   HAL_CAN_ERROR_EWG         ((uint32_t)0x00000001)    /*!< EWG error            */
00253 #define   HAL_CAN_ERROR_EPV         ((uint32_t)0x00000002)    /*!< EPV error            */
00254 #define   HAL_CAN_ERROR_BOF         ((uint32_t)0x00000004)    /*!< BOF error            */
00255 #define   HAL_CAN_ERROR_STF         ((uint32_t)0x00000008)    /*!< Stuff error          */
00256 #define   HAL_CAN_ERROR_FOR         ((uint32_t)0x00000010)    /*!< Form error           */
00257 #define   HAL_CAN_ERROR_ACK         ((uint32_t)0x00000020)    /*!< Acknowledgment error */
00258 #define   HAL_CAN_ERROR_BR          ((uint32_t)0x00000040)    /*!< Bit recessive        */
00259 #define   HAL_CAN_ERROR_BD          ((uint32_t)0x00000080)    /*!< LEC dominant         */
00260 #define   HAL_CAN_ERROR_CRC         ((uint32_t)0x00000100)   /*!< LEC transfer error   */
00261 /**
00262   * @}
00263   */
00264 
00265 /** @defgroup CAN_InitStatus CAN initialization Status
00266   * @{
00267   */
00268 #define CAN_INITSTATUS_FAILED       ((uint32_t)0x00000000)  /*!< CAN initialization failed */
00269 #define CAN_INITSTATUS_SUCCESS      ((uint32_t)0x00000001)  /*!< CAN initialization OK */
00270 /**
00271   * @}
00272   */
00273 
00274 /** @defgroup CAN_operating_mode CAN Operating Mode
00275   * @{
00276   */
00277 #define CAN_MODE_NORMAL             ((uint32_t)0x00000000)                     /*!< Normal mode   */
00278 #define CAN_MODE_LOOPBACK           ((uint32_t)CAN_BTR_LBKM)                   /*!< Loopback mode */
00279 #define CAN_MODE_SILENT             ((uint32_t)CAN_BTR_SILM)                   /*!< Silent mode   */
00280 #define CAN_MODE_SILENT_LOOPBACK    ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM))  /*!< Loopback combined with silent mode */
00281 /**
00282   * @}
00283   */
00284 
00285 
00286 /** @defgroup CAN_synchronisation_jump_width CAN Synchronization Jump Width
00287   * @{
00288   */
00289 #define CAN_SJW_1TQ                 ((uint32_t)0x00000000)     /*!< 1 time quantum */
00290 #define CAN_SJW_2TQ                 ((uint32_t)CAN_BTR_SJW_0)  /*!< 2 time quantum */
00291 #define CAN_SJW_3TQ                 ((uint32_t)CAN_BTR_SJW_1)  /*!< 3 time quantum */
00292 #define CAN_SJW_4TQ                 ((uint32_t)CAN_BTR_SJW)    /*!< 4 time quantum */
00293 /**
00294   * @}
00295   */
00296 
00297 /** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in Bit Segment 1
00298   * @{
00299   */
00300 #define CAN_BS1_1TQ                 ((uint32_t)0x00000000)                                       /*!< 1 time quantum  */
00301 #define CAN_BS1_2TQ                 ((uint32_t)CAN_BTR_TS1_0)                                    /*!< 2 time quantum  */
00302 #define CAN_BS1_3TQ                 ((uint32_t)CAN_BTR_TS1_1)                                    /*!< 3 time quantum  */
00303 #define CAN_BS1_4TQ                 ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0))                  /*!< 4 time quantum  */
00304 #define CAN_BS1_5TQ                 ((uint32_t)CAN_BTR_TS1_2)                                    /*!< 5 time quantum  */
00305 #define CAN_BS1_6TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0))                  /*!< 6 time quantum  */
00306 #define CAN_BS1_7TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1))                  /*!< 7 time quantum  */
00307 #define CAN_BS1_8TQ                 ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 8 time quantum  */
00308 #define CAN_BS1_9TQ                 ((uint32_t)CAN_BTR_TS1_3)                                    /*!< 9 time quantum  */
00309 #define CAN_BS1_10TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0))                  /*!< 10 time quantum */
00310 #define CAN_BS1_11TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1))                  /*!< 11 time quantum */
00311 #define CAN_BS1_12TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 12 time quantum */
00312 #define CAN_BS1_13TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2))                  /*!< 13 time quantum */
00313 #define CAN_BS1_14TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0))  /*!< 14 time quantum */
00314 #define CAN_BS1_15TQ                ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1))  /*!< 15 time quantum */
00315 #define CAN_BS1_16TQ                ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */
00316 /**
00317   * @}
00318   */
00319 
00320 /** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in Bit Segment 2
00321   * @{
00322   */
00323 #define CAN_BS2_1TQ                 ((uint32_t)0x00000000)                       /*!< 1 time quantum */
00324 #define CAN_BS2_2TQ                 ((uint32_t)CAN_BTR_TS2_0)                    /*!< 2 time quantum */
00325 #define CAN_BS2_3TQ                 ((uint32_t)CAN_BTR_TS2_1)                    /*!< 3 time quantum */
00326 #define CAN_BS2_4TQ                 ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0))  /*!< 4 time quantum */
00327 #define CAN_BS2_5TQ                 ((uint32_t)CAN_BTR_TS2_2)                    /*!< 5 time quantum */
00328 #define CAN_BS2_6TQ                 ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0))  /*!< 6 time quantum */
00329 #define CAN_BS2_7TQ                 ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1))  /*!< 7 time quantum */
00330 #define CAN_BS2_8TQ                 ((uint32_t)CAN_BTR_TS2)                      /*!< 8 time quantum */
00331 /**
00332   * @}
00333   */
00334 
00335 /** @defgroup CAN_filter_mode CAN Filter Mode
00336   * @{
00337   */
00338 #define CAN_FILTERMODE_IDMASK       ((uint8_t)0x00)  /*!< Identifier mask mode */
00339 #define CAN_FILTERMODE_IDLIST       ((uint8_t)0x01)  /*!< Identifier list mode */
00340 /**
00341   * @}
00342   */
00343 
00344 /** @defgroup CAN_filter_scale CAN Filter Scale
00345   * @{
00346   */
00347 #define CAN_FILTERSCALE_16BIT       ((uint8_t)0x00)  /*!< Two 16-bit filters */
00348 #define CAN_FILTERSCALE_32BIT       ((uint8_t)0x01)  /*!< One 32-bit filter  */
00349 /**
00350   * @}
00351   */
00352 
00353 /** @defgroup CAN_filter_FIFO CAN Filter FIFO
00354   * @{
00355   */
00356 #define CAN_FILTER_FIFO0             ((uint8_t)0x00)  /*!< Filter FIFO 0 assignment for filter x */
00357 #define CAN_FILTER_FIFO1             ((uint8_t)0x01)  /*!< Filter FIFO 1 assignment for filter x */
00358 /**
00359   * @}
00360   */
00361 
00362 /** @defgroup CAN_identifier_type CAN Identifier Type
00363   * @{
00364   */
00365 #define CAN_ID_STD             ((uint32_t)0x00000000)  /*!< Standard Id */
00366 #define CAN_ID_EXT             ((uint32_t)0x00000004)  /*!< Extended Id */
00367 /**
00368   * @}
00369   */
00370 
00371 /** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request
00372   * @{
00373   */
00374 #define CAN_RTR_DATA                ((uint32_t)0x00000000)  /*!< Data frame */
00375 #define CAN_RTR_REMOTE              ((uint32_t)0x00000002)  /*!< Remote frame */
00376 /**
00377   * @}
00378   */
00379 
00380 /** @defgroup CAN_receive_FIFO_number_constants CAN Receive FIFO Number
00381   * @{
00382   */
00383 #define CAN_FIFO0                   ((uint8_t)0x00)  /*!< CAN FIFO 0 used to receive */
00384 #define CAN_FIFO1                   ((uint8_t)0x01)  /*!< CAN FIFO 1 used to receive */
00385 /**
00386   * @}
00387   */
00388 
00389 /** @defgroup CAN_flags CAN Flags
00390   * @{
00391   */
00392 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
00393    and CAN_ClearFlag() functions. */
00394 /* If the flag is 0x1XXXXXXX, it means that it can only be used with
00395    CAN_GetFlagStatus() function.  */
00396 
00397 /* Transmit Flags */
00398 #define CAN_FLAG_RQCP0             ((uint32_t)0x00000500)  /*!< Request MailBox0 flag         */
00399 #define CAN_FLAG_RQCP1             ((uint32_t)0x00000508)  /*!< Request MailBox1 flag         */
00400 #define CAN_FLAG_RQCP2             ((uint32_t)0x00000510)  /*!< Request MailBox2 flag         */
00401 #define CAN_FLAG_TXOK0             ((uint32_t)0x00000501)  /*!< Transmission OK MailBox0 flag */
00402 #define CAN_FLAG_TXOK1             ((uint32_t)0x00000509)  /*!< Transmission OK MailBox1 flag */
00403 #define CAN_FLAG_TXOK2             ((uint32_t)0x00000511)  /*!< Transmission OK MailBox2 flag */
00404 #define CAN_FLAG_TME0              ((uint32_t)0x0000051A)  /*!< Transmit mailbox 0 empty flag */
00405 #define CAN_FLAG_TME1              ((uint32_t)0x0000051B)  /*!< Transmit mailbox 0 empty flag */
00406 #define CAN_FLAG_TME2              ((uint32_t)0x0000051C)  /*!< Transmit mailbox 0 empty flag */
00407 
00408 /* Receive Flags */
00409 #define CAN_FLAG_FF0               ((uint32_t)0x00000203)  /*!< FIFO 0 Full flag    */
00410 #define CAN_FLAG_FOV0              ((uint32_t)0x00000204)  /*!< FIFO 0 Overrun flag */
00411 
00412 #define CAN_FLAG_FF1               ((uint32_t)0x00000403)  /*!< FIFO 1 Full flag    */
00413 #define CAN_FLAG_FOV1              ((uint32_t)0x00000404)  /*!< FIFO 1 Overrun flag */
00414 
00415 /* Operating Mode Flags */
00416 #define CAN_FLAG_WKU               ((uint32_t)0x00000103)  /*!< Wake up flag           */
00417 #define CAN_FLAG_SLAK              ((uint32_t)0x00000101)  /*!< Sleep acknowledge flag */
00418 #define CAN_FLAG_SLAKI             ((uint32_t)0x00000104)  /*!< Sleep acknowledge flag */
00419 /* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible.
00420          In this case the SLAK bit can be polled.*/
00421 
00422 /* Error Flags */
00423 #define CAN_FLAG_EWG               ((uint32_t)0x00000300)  /*!< Error warning flag   */
00424 #define CAN_FLAG_EPV               ((uint32_t)0x00000301)  /*!< Error passive flag   */
00425 #define CAN_FLAG_BOF               ((uint32_t)0x00000302)  /*!< Bus-Off flag         */
00426 /**
00427   * @}
00428   */
00429 
00430 /** @defgroup CAN_interrupts CAN Interrupts
00431   * @{
00432   */
00433 #define CAN_IT_TME                  ((uint32_t)CAN_IER_TMEIE)   /*!< Transmit mailbox empty interrupt */
00434 
00435 /* Receive Interrupts */
00436 #define CAN_IT_FMP0                 ((uint32_t)CAN_IER_FMPIE0)  /*!< FIFO 0 message pending interrupt */
00437 #define CAN_IT_FF0                  ((uint32_t)CAN_IER_FFIE0)   /*!< FIFO 0 full interrupt            */
00438 #define CAN_IT_FOV0                 ((uint32_t)CAN_IER_FOVIE0)  /*!< FIFO 0 overrun interrupt         */
00439 #define CAN_IT_FMP1                 ((uint32_t)CAN_IER_FMPIE1)  /*!< FIFO 1 message pending interrupt */
00440 #define CAN_IT_FF1                  ((uint32_t)CAN_IER_FFIE1)   /*!< FIFO 1 full interrupt            */
00441 #define CAN_IT_FOV1                 ((uint32_t)CAN_IER_FOVIE1)  /*!< FIFO 1 overrun interrupt         */
00442 
00443 /* Operating Mode Interrupts */
00444 #define CAN_IT_WKU                  ((uint32_t)CAN_IER_WKUIE)  /*!< Wake-up interrupt           */
00445 #define CAN_IT_SLK                  ((uint32_t)CAN_IER_SLKIE)  /*!< Sleep acknowledge interrupt */
00446 
00447 /* Error Interrupts */
00448 #define CAN_IT_EWG                  ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt   */
00449 #define CAN_IT_EPV                  ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt   */
00450 #define CAN_IT_BOF                  ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt         */
00451 #define CAN_IT_LEC                  ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */
00452 #define CAN_IT_ERR                  ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt           */
00453 
00454 /**
00455   * @}
00456   */
00457 
00458 /* Mailboxes definition */
00459 #define CAN_TXMAILBOX_0   ((uint8_t)0x00)
00460 #define CAN_TXMAILBOX_1   ((uint8_t)0x01)
00461 #define CAN_TXMAILBOX_2   ((uint8_t)0x02)
00462 
00463 /**
00464   * @}
00465   */
00466 
00467 /* Exported macros -----------------------------------------------------------*/
00468 /** @defgroup CAN_Exported_Macro CAN Exported Macros
00469   * @{
00470   */
00471 
00472 /** @brief  Reset CAN handle state.
00473   * @param  __HANDLE__: CAN handle.
00474   * @retval None
00475   */
00476 #define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET)
00477 
00478 /**
00479   * @brief  Enable the specified CAN interrupt.
00480   * @param  __HANDLE__: CAN handle.
00481   * @param  __INTERRUPT__: CAN Interrupt.
00482   * @retval None
00483   */
00484 #define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
00485 
00486 /**
00487   * @brief  Disable the specified CAN interrupt.
00488   * @param  __HANDLE__: CAN handle.
00489   * @param  __INTERRUPT__: CAN Interrupt.
00490   * @retval None
00491   */
00492 #define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
00493 
00494 /**
00495   * @brief  Return the number of pending received messages.
00496   * @param  __HANDLE__: CAN handle.
00497   * @param  __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
00498   * @retval The number of pending message.
00499   */
00500 #define __HAL_CAN_MSG_PENDING(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
00501 ((uint8_t)((__HANDLE__)->Instance->RF0R&(uint32_t)0x03)) : ((uint8_t)((__HANDLE__)->Instance->RF1R&(uint32_t)0x03)))
00502 
00503 /** @brief  Check whether the specified CAN flag is set or not.
00504   * @param  __HANDLE__: specifies the CAN Handle.
00505   * @param  __FLAG__: specifies the flag to check.
00506   *         This parameter can be one of the following values:
00507   *            @arg CAN_TSR_RQCP0: Request MailBox0 Flag
00508   *            @arg CAN_TSR_RQCP1: Request MailBox1 Flag
00509   *            @arg CAN_TSR_RQCP2: Request MailBox2 Flag
00510   *            @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
00511   *            @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
00512   *            @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
00513   *            @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
00514   *            @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
00515   *            @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
00516   *            @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
00517   *            @arg CAN_FLAG_FF0: FIFO 0 Full Flag
00518   *            @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
00519   *            @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
00520   *            @arg CAN_FLAG_FF1: FIFO 1 Full Flag
00521   *            @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
00522   *            @arg CAN_FLAG_WKU: Wake up Flag
00523   *            @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
00524   *            @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
00525   *            @arg CAN_FLAG_EWG: Error Warning Flag
00526   *            @arg CAN_FLAG_EPV: Error Passive Flag
00527   *            @arg CAN_FLAG_BOF: Bus-Off Flag
00528   * @retval The new state of __FLAG__ (TRUE or FALSE).
00529   */
00530 #define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \
00531 ((((__FLAG__) >> 8) == 5)? ((((__HANDLE__)->Instance->TSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00532  (((__FLAG__) >> 8) == 2)? ((((__HANDLE__)->Instance->RF0R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00533  (((__FLAG__) >> 8) == 4)? ((((__HANDLE__)->Instance->RF1R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00534  (((__FLAG__) >> 8) == 1)? ((((__HANDLE__)->Instance->MSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00535  ((((__HANDLE__)->Instance->ESR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))))
00536 
00537 /** @brief  Clear the specified CAN pending flag.
00538   * @param  __HANDLE__: specifies the CAN Handle.
00539   * @param  __FLAG__: specifies the flag to check.
00540   *         This parameter can be one of the following values:
00541   *            @arg CAN_TSR_RQCP0: Request MailBox0 Flag
00542   *            @arg CAN_TSR_RQCP1: Request MailBox1 Flag
00543   *            @arg CAN_TSR_RQCP2: Request MailBox2 Flag
00544   *            @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
00545   *            @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
00546   *            @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
00547   *            @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
00548   *            @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
00549   *            @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
00550   *            @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
00551   *            @arg CAN_FLAG_FF0: FIFO 0 Full Flag
00552   *            @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
00553   *            @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
00554   *            @arg CAN_FLAG_FF1: FIFO 1 Full Flag
00555   *            @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
00556   *            @arg CAN_FLAG_WKU: Wake up Flag
00557   *            @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
00558   * @retval The new state of __FLAG__ (TRUE or FALSE).
00559   */
00560 #define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \
00561 ((((__FLAG__) >> 8U) == 5)? (((__HANDLE__)->Instance->TSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00562  (((__FLAG__) >> 8U) == 2)? (((__HANDLE__)->Instance->RF0R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00563  (((__FLAG__) >> 8U) == 4)? (((__HANDLE__)->Instance->RF1R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
00564  (((__FLAG__) >> 8U) == 1)? (((__HANDLE__)->Instance->MSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0)
00565 
00566 
00567 /** @brief  Check whether the specified CAN interrupt source is enabled or not.
00568   * @param  __HANDLE__: specifies the CAN Handle.
00569   * @param  __INTERRUPT__: specifies the CAN interrupt source to check.
00570   *         This parameter can be one of the following values:
00571   *            @arg CAN_IT_TME: Transmit mailbox empty interrupt enable
00572   *            @arg CAN_IT_FMP0: FIFO0 message pending interrupt enable
00573   *            @arg CAN_IT_FMP1: FIFO1 message pending interrupt enable
00574   * @retval The new state of __IT__ (TRUE or FALSE).
00575   */
00576 #define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
00577 
00578 /**
00579   * @brief  Check the transmission status of a CAN Frame.
00580   * @param  __HANDLE__: specifies the CAN Handle.
00581   * @param  __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
00582   * @retval The new status of transmission  (TRUE or FALSE).
00583   */
00584 #define __HAL_CAN_TRANSMIT_STATUS(__HANDLE__, __TRANSMITMAILBOX__)\
00585 (((__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)) :\
00586  ((__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)) :\
00587  ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)) == (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)))
00588 
00589 
00590 
00591 /**
00592   * @brief  Release the specified receive FIFO.
00593   * @param  __HANDLE__: CAN handle.
00594   * @param  __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
00595   * @retval None
00596   */
00597 #define __HAL_CAN_FIFO_RELEASE(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
00598 ((__HANDLE__)->Instance->RF0R |= CAN_RF0R_RFOM0) : ((__HANDLE__)->Instance->RF1R |= CAN_RF1R_RFOM1)) 
00599 
00600 /**
00601   * @brief  Cancel a transmit request.
00602   * @param  __HANDLE__: specifies the CAN Handle.
00603   * @param  __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
00604   * @retval None
00605   */
00606 #define __HAL_CAN_CANCEL_TRANSMIT(__HANDLE__, __TRANSMITMAILBOX__)\
00607 (((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ0) :\
00608  ((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ1) :\
00609  ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ2))
00610 
00611 /**
00612   * @brief  Enable or disable the DBG Freeze for CAN.
00613   * @param  __HANDLE__: specifies the CAN Handle.
00614   * @param  __NEWSTATE__: new state of the CAN peripheral. 
00615   *         This parameter can be: ENABLE (CAN reception/transmission is frozen
00616   *         during debug. Reception FIFO can still be accessed/controlled normally) 
00617   *         or DISABLE (CAN is working during debug).
00618   * @retval None
00619   */
00620 #define __HAL_CAN_DBG_FREEZE(__HANDLE__, __NEWSTATE__) (((__NEWSTATE__) == ENABLE)? \
00621 ((__HANDLE__)->Instance->MCR |= CAN_MCR_DBF) : ((__HANDLE__)->Instance->MCR &= ~CAN_MCR_DBF)) 
00622 
00623 /**
00624  * @}
00625  */  
00626  
00627 /* Exported functions --------------------------------------------------------*/  
00628 /** @addtogroup CAN_Exported_Functions CAN Exported Functions
00629   * @{
00630   */
00631   
00632 /** @defgroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions 
00633  *  @brief    Initialization and Configuration functions 
00634  * @{
00635  */
00636 /* addtogroup and de-initialization functions *****************************/ 
00637 HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan);
00638 HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig);
00639 HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan);
00640 void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan);
00641 void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan);
00642 /**
00643  * @}
00644  */ 
00645  
00646 /** @addtogroup CAN_Exported_Functions_Group2 Input and Output operation functions
00647  *  @brief    I/O operation functions 
00648  * @{
00649  */
00650 /* IO operation functions *****************************************************/
00651 HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout);
00652 HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef *hcan);
00653 HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef *hcan, uint8_t FIFONumber, uint32_t Timeout);
00654 HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef *hcan, uint8_t FIFONumber);
00655 HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef *hcan);
00656 HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan);
00657 void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan);
00658 void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan);
00659 void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan);
00660 void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan);
00661 /**
00662  * @}
00663  */ 
00664  
00665 /** @addtogroup CAN_Exported_Functions_Group3 Peripheral State and Error functions
00666  *  @brief   CAN Peripheral State functions 
00667  * @{
00668  */
00669 /* Peripheral State and Error functions ***************************************/
00670 uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan);
00671 HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan);
00672 /**
00673  * @}
00674  */ 
00675 
00676 /**
00677  * @}
00678  */ 
00679 
00680 /* Private types -------------------------------------------------------------*/
00681 /* Private constants ---------------------------------------------------------*/
00682 /** @defgroup CAN_Private_Constants CAN Private Constants
00683   * @{
00684   */
00685 /** @defgroup CAN_transmit_constants CAN Transmit Constants
00686   * @{
00687   */
00688 #define CAN_TXSTATUS_NOMAILBOX      ((uint8_t)0x04)  /*!< CAN cell did not provide CAN_TxStatus_NoMailBox */
00689 /**
00690   * @}
00691   */
00692 #define CAN_FLAG_MASK     ((uint32_t)0x000000FF)
00693 
00694 
00695 /**
00696   * @}
00697   */
00698 
00699 /* Private macros ------------------------------------------------------------*/
00700 /** @defgroup CAN_Private_Macros CAN Private Macros
00701   * @{
00702   */
00703 
00704 #define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \
00705                            ((MODE) == CAN_MODE_LOOPBACK)|| \
00706                            ((MODE) == CAN_MODE_SILENT) || \
00707                            ((MODE) == CAN_MODE_SILENT_LOOPBACK))
00708 
00709 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ)|| \
00710                          ((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ))
00711 
00712 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16TQ)
00713 
00714 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8TQ)
00715 
00716 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
00717 
00718 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
00719 
00720 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \
00721                                   ((MODE) == CAN_FILTERMODE_IDLIST))
00722 
00723 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \
00724                                     ((SCALE) == CAN_FILTERSCALE_32BIT))
00725 
00726 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \
00727                                   ((FIFO) == CAN_FILTER_FIFO1))
00728 
00729 #define IS_CAN_BANKNUMBER(BANKNUMBER) ((BANKNUMBER) <= 28)
00730 
00731 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
00732 
00733 #define IS_CAN_STDID(STDID)   ((STDID) <= ((uint32_t)0x7FF))
00734 
00735 #define IS_CAN_EXTID(EXTID)   ((EXTID) <= ((uint32_t)0x1FFFFFFF))
00736 
00737 #define IS_CAN_DLC(DLC)       ((DLC) <= ((uint8_t)0x08))
00738 
00739 #define IS_CAN_IDTYPE(IDTYPE)  (((IDTYPE) == CAN_ID_STD) || \
00740                                 ((IDTYPE) == CAN_ID_EXT))
00741 
00742 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE))
00743 
00744 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
00745 
00746 /**
00747   * @}
00748   */
00749 
00750 /* Private functions ---------------------------------------------------------*/
00751 
00752 /**
00753   * @}
00754   */
00755 
00756 /**
00757   * @}
00758   */
00759 
00760 
00761 #ifdef __cplusplus
00762 }
00763 #endif
00764 
00765 #endif /* __STM32L4xx_CAN_H */
00766 
00767 
00768 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/