I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhon309 0:ac8863619623 1 /**
jhon309 0:ac8863619623 2 ******************************************************************************
jhon309 0:ac8863619623 3 * @file stm32f0xx_hal_can.h
jhon309 0:ac8863619623 4 * @author MCD Application Team
jhon309 0:ac8863619623 5 * @version V1.2.0
jhon309 0:ac8863619623 6 * @date 11-December-2014
jhon309 0:ac8863619623 7 * @brief Header file of CAN HAL module.
jhon309 0:ac8863619623 8 ******************************************************************************
jhon309 0:ac8863619623 9 * @attention
jhon309 0:ac8863619623 10 *
jhon309 0:ac8863619623 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
jhon309 0:ac8863619623 12 *
jhon309 0:ac8863619623 13 * Redistribution and use in source and binary forms, with or without modification,
jhon309 0:ac8863619623 14 * are permitted provided that the following conditions are met:
jhon309 0:ac8863619623 15 * 1. Redistributions of source code must retain the above copyright notice,
jhon309 0:ac8863619623 16 * this list of conditions and the following disclaimer.
jhon309 0:ac8863619623 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
jhon309 0:ac8863619623 18 * this list of conditions and the following disclaimer in the documentation
jhon309 0:ac8863619623 19 * and/or other materials provided with the distribution.
jhon309 0:ac8863619623 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
jhon309 0:ac8863619623 21 * may be used to endorse or promote products derived from this software
jhon309 0:ac8863619623 22 * without specific prior written permission.
jhon309 0:ac8863619623 23 *
jhon309 0:ac8863619623 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
jhon309 0:ac8863619623 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
jhon309 0:ac8863619623 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
jhon309 0:ac8863619623 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
jhon309 0:ac8863619623 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
jhon309 0:ac8863619623 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
jhon309 0:ac8863619623 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
jhon309 0:ac8863619623 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
jhon309 0:ac8863619623 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
jhon309 0:ac8863619623 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jhon309 0:ac8863619623 34 *
jhon309 0:ac8863619623 35 ******************************************************************************
jhon309 0:ac8863619623 36 */
jhon309 0:ac8863619623 37
jhon309 0:ac8863619623 38 /* Define to prevent recursive inclusion -------------------------------------*/
jhon309 0:ac8863619623 39 #ifndef __STM32F0xx_HAL_CAN_H
jhon309 0:ac8863619623 40 #define __STM32F0xx_HAL_CAN_H
jhon309 0:ac8863619623 41
jhon309 0:ac8863619623 42 #ifdef __cplusplus
jhon309 0:ac8863619623 43 extern "C" {
jhon309 0:ac8863619623 44 #endif
jhon309 0:ac8863619623 45
jhon309 0:ac8863619623 46 #if defined(STM32F072xB) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
jhon309 0:ac8863619623 47
jhon309 0:ac8863619623 48 /* Includes ------------------------------------------------------------------*/
jhon309 0:ac8863619623 49 #include "stm32f0xx_hal_def.h"
jhon309 0:ac8863619623 50
jhon309 0:ac8863619623 51 /** @addtogroup STM32F0xx_HAL_Driver
jhon309 0:ac8863619623 52 * @{
jhon309 0:ac8863619623 53 */
jhon309 0:ac8863619623 54
jhon309 0:ac8863619623 55 /** @addtogroup CAN CAN HAL Module Driver
jhon309 0:ac8863619623 56 * @{
jhon309 0:ac8863619623 57 */
jhon309 0:ac8863619623 58
jhon309 0:ac8863619623 59 /* Exported types ------------------------------------------------------------*/
jhon309 0:ac8863619623 60 /** @defgroup CAN_Exported_Types CAN Exported Types
jhon309 0:ac8863619623 61 * @{
jhon309 0:ac8863619623 62 */
jhon309 0:ac8863619623 63 /**
jhon309 0:ac8863619623 64 * @brief HAL State structures definition
jhon309 0:ac8863619623 65 */
jhon309 0:ac8863619623 66 typedef enum
jhon309 0:ac8863619623 67 {
jhon309 0:ac8863619623 68 HAL_CAN_STATE_RESET = 0x00, /*!< CAN not yet initialized or disabled */
jhon309 0:ac8863619623 69 HAL_CAN_STATE_READY = 0x01, /*!< CAN initialized and ready for use */
jhon309 0:ac8863619623 70 HAL_CAN_STATE_BUSY = 0x02, /*!< CAN process is ongoing */
jhon309 0:ac8863619623 71 HAL_CAN_STATE_BUSY_TX = 0x12, /*!< CAN process is ongoing */
jhon309 0:ac8863619623 72 HAL_CAN_STATE_BUSY_RX = 0x22, /*!< CAN process is ongoing */
jhon309 0:ac8863619623 73 HAL_CAN_STATE_BUSY_TX_RX = 0x32, /*!< CAN process is ongoing */
jhon309 0:ac8863619623 74 HAL_CAN_STATE_TIMEOUT = 0x03, /*!< CAN in Timeout state */
jhon309 0:ac8863619623 75 HAL_CAN_STATE_ERROR = 0x04 /*!< CAN error state */
jhon309 0:ac8863619623 76
jhon309 0:ac8863619623 77 }HAL_CAN_StateTypeDef;
jhon309 0:ac8863619623 78
jhon309 0:ac8863619623 79 /**
jhon309 0:ac8863619623 80 * @brief CAN init structure definition
jhon309 0:ac8863619623 81 */
jhon309 0:ac8863619623 82 typedef struct
jhon309 0:ac8863619623 83 {
jhon309 0:ac8863619623 84 uint32_t Prescaler; /*!< Specifies the length of a time quantum.
jhon309 0:ac8863619623 85 This parameter must be a number between Min_Data = 1 and Max_Data = 1024. */
jhon309 0:ac8863619623 86
jhon309 0:ac8863619623 87 uint32_t Mode; /*!< Specifies the CAN operating mode.
jhon309 0:ac8863619623 88 This parameter can be a value of @ref CAN_operating_mode */
jhon309 0:ac8863619623 89
jhon309 0:ac8863619623 90 uint32_t SJW; /*!< Specifies the maximum number of time quanta
jhon309 0:ac8863619623 91 the CAN hardware is allowed to lengthen or
jhon309 0:ac8863619623 92 shorten a bit to perform resynchronization.
jhon309 0:ac8863619623 93 This parameter can be a value of @ref CAN_synchronisation_jump_width */
jhon309 0:ac8863619623 94
jhon309 0:ac8863619623 95 uint32_t BS1; /*!< Specifies the number of time quanta in Bit Segment 1.
jhon309 0:ac8863619623 96 This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */
jhon309 0:ac8863619623 97
jhon309 0:ac8863619623 98 uint32_t BS2; /*!< Specifies the number of time quanta in Bit Segment 2.
jhon309 0:ac8863619623 99 This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */
jhon309 0:ac8863619623 100
jhon309 0:ac8863619623 101 uint32_t TTCM; /*!< Enable or disable the time triggered communication mode.
jhon309 0:ac8863619623 102 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 103
jhon309 0:ac8863619623 104 uint32_t ABOM; /*!< Enable or disable the automatic bus-off management.
jhon309 0:ac8863619623 105 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 106
jhon309 0:ac8863619623 107 uint32_t AWUM; /*!< Enable or disable the automatic wake-up mode.
jhon309 0:ac8863619623 108 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 109
jhon309 0:ac8863619623 110 uint32_t NART; /*!< Enable or disable the non-automatic retransmission mode.
jhon309 0:ac8863619623 111 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 112
jhon309 0:ac8863619623 113 uint32_t RFLM; /*!< Enable or disable the Receive FIFO Locked mode.
jhon309 0:ac8863619623 114 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 115
jhon309 0:ac8863619623 116 uint32_t TXFP; /*!< Enable or disable the transmit FIFO priority.
jhon309 0:ac8863619623 117 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 118 }CAN_InitTypeDef;
jhon309 0:ac8863619623 119
jhon309 0:ac8863619623 120 /**
jhon309 0:ac8863619623 121 * @brief CAN filter configuration structure definition
jhon309 0:ac8863619623 122 */
jhon309 0:ac8863619623 123 typedef struct
jhon309 0:ac8863619623 124 {
jhon309 0:ac8863619623 125 uint32_t FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit
jhon309 0:ac8863619623 126 configuration, first one for a 16-bit configuration).
jhon309 0:ac8863619623 127 This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
jhon309 0:ac8863619623 128
jhon309 0:ac8863619623 129 uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit
jhon309 0:ac8863619623 130 configuration, second one for a 16-bit configuration).
jhon309 0:ac8863619623 131 This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
jhon309 0:ac8863619623 132
jhon309 0:ac8863619623 133 uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,
jhon309 0:ac8863619623 134 according to the mode (MSBs for a 32-bit configuration,
jhon309 0:ac8863619623 135 first one for a 16-bit configuration).
jhon309 0:ac8863619623 136 This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
jhon309 0:ac8863619623 137
jhon309 0:ac8863619623 138 uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,
jhon309 0:ac8863619623 139 according to the mode (LSBs for a 32-bit configuration,
jhon309 0:ac8863619623 140 second one for a 16-bit configuration).
jhon309 0:ac8863619623 141 This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
jhon309 0:ac8863619623 142
jhon309 0:ac8863619623 143 uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
jhon309 0:ac8863619623 144 This parameter can be a value of @ref CAN_filter_FIFO */
jhon309 0:ac8863619623 145
jhon309 0:ac8863619623 146 uint32_t FilterNumber; /*!< Specifies the filter which will be initialized.
jhon309 0:ac8863619623 147 This parameter must be a number between Min_Data = 0 and Max_Data = 27. */
jhon309 0:ac8863619623 148
jhon309 0:ac8863619623 149 uint32_t FilterMode; /*!< Specifies the filter mode to be initialized.
jhon309 0:ac8863619623 150 This parameter can be a value of @ref CAN_filter_mode */
jhon309 0:ac8863619623 151
jhon309 0:ac8863619623 152 uint32_t FilterScale; /*!< Specifies the filter scale.
jhon309 0:ac8863619623 153 This parameter can be a value of @ref CAN_filter_scale */
jhon309 0:ac8863619623 154
jhon309 0:ac8863619623 155 uint32_t FilterActivation; /*!< Enable or disable the filter.
jhon309 0:ac8863619623 156 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:ac8863619623 157
jhon309 0:ac8863619623 158 uint32_t BankNumber; /*!< Select the start slave bank filter
jhon309 0:ac8863619623 159 This parameter must be a number between Min_Data = 0 and Max_Data = 28. */
jhon309 0:ac8863619623 160
jhon309 0:ac8863619623 161 }CAN_FilterConfTypeDef;
jhon309 0:ac8863619623 162
jhon309 0:ac8863619623 163 /**
jhon309 0:ac8863619623 164 * @brief CAN Tx message structure definition
jhon309 0:ac8863619623 165 */
jhon309 0:ac8863619623 166 typedef struct
jhon309 0:ac8863619623 167 {
jhon309 0:ac8863619623 168 uint32_t StdId; /*!< Specifies the standard identifier.
jhon309 0:ac8863619623 169 This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */
jhon309 0:ac8863619623 170
jhon309 0:ac8863619623 171 uint32_t ExtId; /*!< Specifies the extended identifier.
jhon309 0:ac8863619623 172 This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */
jhon309 0:ac8863619623 173
jhon309 0:ac8863619623 174 uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted.
jhon309 0:ac8863619623 175 This parameter can be a value of @ref CAN_identifier_type */
jhon309 0:ac8863619623 176
jhon309 0:ac8863619623 177 uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted.
jhon309 0:ac8863619623 178 This parameter can be a value of @ref CAN_remote_transmission_request */
jhon309 0:ac8863619623 179
jhon309 0:ac8863619623 180 uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted.
jhon309 0:ac8863619623 181 This parameter must be a number between Min_Data = 0 and Max_Data = 8. */
jhon309 0:ac8863619623 182
jhon309 0:ac8863619623 183 uint32_t Data[8]; /*!< Contains the data to be transmitted.
jhon309 0:ac8863619623 184 This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */
jhon309 0:ac8863619623 185
jhon309 0:ac8863619623 186 }CanTxMsgTypeDef;
jhon309 0:ac8863619623 187
jhon309 0:ac8863619623 188 /**
jhon309 0:ac8863619623 189 * @brief CAN Rx message structure definition
jhon309 0:ac8863619623 190 */
jhon309 0:ac8863619623 191 typedef struct
jhon309 0:ac8863619623 192 {
jhon309 0:ac8863619623 193 uint32_t StdId; /*!< Specifies the standard identifier.
jhon309 0:ac8863619623 194 This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */
jhon309 0:ac8863619623 195
jhon309 0:ac8863619623 196 uint32_t ExtId; /*!< Specifies the extended identifier.
jhon309 0:ac8863619623 197 This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */
jhon309 0:ac8863619623 198
jhon309 0:ac8863619623 199 uint32_t IDE; /*!< Specifies the type of identifier for the message that will be received.
jhon309 0:ac8863619623 200 This parameter can be a value of @ref CAN_identifier_type */
jhon309 0:ac8863619623 201
jhon309 0:ac8863619623 202 uint32_t RTR; /*!< Specifies the type of frame for the received message.
jhon309 0:ac8863619623 203 This parameter can be a value of @ref CAN_remote_transmission_request */
jhon309 0:ac8863619623 204
jhon309 0:ac8863619623 205 uint32_t DLC; /*!< Specifies the length of the frame that will be received.
jhon309 0:ac8863619623 206 This parameter must be a number between Min_Data = 0 and Max_Data = 8. */
jhon309 0:ac8863619623 207
jhon309 0:ac8863619623 208 uint32_t Data[8]; /*!< Contains the data to be received.
jhon309 0:ac8863619623 209 This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */
jhon309 0:ac8863619623 210
jhon309 0:ac8863619623 211 uint32_t FMI; /*!< Specifies the index of the filter the message stored in the mailbox passes through.
jhon309 0:ac8863619623 212 This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */
jhon309 0:ac8863619623 213
jhon309 0:ac8863619623 214 uint32_t FIFONumber; /*!< Specifies the receive FIFO number.
jhon309 0:ac8863619623 215 This parameter can be CAN_FIFO0 or CAN_FIFO1 */
jhon309 0:ac8863619623 216
jhon309 0:ac8863619623 217 }CanRxMsgTypeDef;
jhon309 0:ac8863619623 218
jhon309 0:ac8863619623 219 /**
jhon309 0:ac8863619623 220 * @brief CAN handle Structure definition
jhon309 0:ac8863619623 221 */
jhon309 0:ac8863619623 222 typedef struct
jhon309 0:ac8863619623 223 {
jhon309 0:ac8863619623 224 CAN_TypeDef *Instance; /*!< Register base address */
jhon309 0:ac8863619623 225
jhon309 0:ac8863619623 226 CAN_InitTypeDef Init; /*!< CAN required parameters */
jhon309 0:ac8863619623 227
jhon309 0:ac8863619623 228 CanTxMsgTypeDef* pTxMsg; /*!< Pointer to transmit structure */
jhon309 0:ac8863619623 229
jhon309 0:ac8863619623 230 CanRxMsgTypeDef* pRxMsg; /*!< Pointer to reception structure */
jhon309 0:ac8863619623 231
jhon309 0:ac8863619623 232 HAL_LockTypeDef Lock; /*!< CAN locking object */
jhon309 0:ac8863619623 233
jhon309 0:ac8863619623 234 __IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */
jhon309 0:ac8863619623 235
jhon309 0:ac8863619623 236 __IO uint32_t ErrorCode; /*!< CAN Error code
jhon309 0:ac8863619623 237 This parameter can be a value of @ref CAN_Error */
jhon309 0:ac8863619623 238
jhon309 0:ac8863619623 239 }CAN_HandleTypeDef;
jhon309 0:ac8863619623 240 /**
jhon309 0:ac8863619623 241 * @}
jhon309 0:ac8863619623 242 */
jhon309 0:ac8863619623 243
jhon309 0:ac8863619623 244 /* Exported constants --------------------------------------------------------*/
jhon309 0:ac8863619623 245
jhon309 0:ac8863619623 246 /** @defgroup CAN_Exported_Constants CAN Exported Constants
jhon309 0:ac8863619623 247 * @{
jhon309 0:ac8863619623 248 */
jhon309 0:ac8863619623 249
jhon309 0:ac8863619623 250 /** @defgroup CAN_Error CAN Error
jhon309 0:ac8863619623 251 * @{
jhon309 0:ac8863619623 252 */
jhon309 0:ac8863619623 253 #define HAL_CAN_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
jhon309 0:ac8863619623 254 #define HAL_CAN_ERROR_EWG ((uint32_t)0x00000001) /*!< EWG error */
jhon309 0:ac8863619623 255 #define HAL_CAN_ERROR_EPV ((uint32_t)0x00000002) /*!< EPV error */
jhon309 0:ac8863619623 256 #define HAL_CAN_ERROR_BOF ((uint32_t)0x00000004) /*!< BOF error */
jhon309 0:ac8863619623 257 #define HAL_CAN_ERROR_STF ((uint32_t)0x00000008) /*!< Stuff error */
jhon309 0:ac8863619623 258 #define HAL_CAN_ERROR_FOR ((uint32_t)0x00000010) /*!< Form error */
jhon309 0:ac8863619623 259 #define HAL_CAN_ERROR_ACK ((uint32_t)0x00000020) /*!< Acknowledgment error */
jhon309 0:ac8863619623 260 #define HAL_CAN_ERROR_BR ((uint32_t)0x00000040) /*!< Bit recessive */
jhon309 0:ac8863619623 261 #define HAL_CAN_ERROR_BD ((uint32_t)0x00000080) /*!< LEC dominant */
jhon309 0:ac8863619623 262 #define HAL_CAN_ERROR_CRC ((uint32_t)0x00000100) /*!< LEC transfer error */
jhon309 0:ac8863619623 263 /**
jhon309 0:ac8863619623 264 * @}
jhon309 0:ac8863619623 265 */
jhon309 0:ac8863619623 266
jhon309 0:ac8863619623 267 /** @defgroup CAN_InitStatus CAN InitStatus
jhon309 0:ac8863619623 268 * @{
jhon309 0:ac8863619623 269 */
jhon309 0:ac8863619623 270 #define CAN_INITSTATUS_FAILED ((uint32_t)0x00000000) /*!< CAN initialization failed */
jhon309 0:ac8863619623 271 #define CAN_INITSTATUS_SUCCESS ((uint32_t)0x00000001) /*!< CAN initialization OK */
jhon309 0:ac8863619623 272 /**
jhon309 0:ac8863619623 273 * @}
jhon309 0:ac8863619623 274 */
jhon309 0:ac8863619623 275
jhon309 0:ac8863619623 276 /** @defgroup CAN_operating_mode CAN operating mode
jhon309 0:ac8863619623 277 * @{
jhon309 0:ac8863619623 278 */
jhon309 0:ac8863619623 279 #define CAN_MODE_NORMAL ((uint32_t)0x00000000) /*!< Normal mode */
jhon309 0:ac8863619623 280 #define CAN_MODE_LOOPBACK ((uint32_t)CAN_BTR_LBKM) /*!< Loopback mode */
jhon309 0:ac8863619623 281 #define CAN_MODE_SILENT ((uint32_t)CAN_BTR_SILM) /*!< Silent mode */
jhon309 0:ac8863619623 282 #define CAN_MODE_SILENT_LOOPBACK ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM)) /*!< Loopback combined with silent mode */
jhon309 0:ac8863619623 283
jhon309 0:ac8863619623 284 #define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \
jhon309 0:ac8863619623 285 ((MODE) == CAN_MODE_LOOPBACK)|| \
jhon309 0:ac8863619623 286 ((MODE) == CAN_MODE_SILENT) || \
jhon309 0:ac8863619623 287 ((MODE) == CAN_MODE_SILENT_LOOPBACK))
jhon309 0:ac8863619623 288 /**
jhon309 0:ac8863619623 289 * @}
jhon309 0:ac8863619623 290 */
jhon309 0:ac8863619623 291
jhon309 0:ac8863619623 292
jhon309 0:ac8863619623 293 /** @defgroup CAN_synchronisation_jump_width CAN synchronisation jump width
jhon309 0:ac8863619623 294 * @{
jhon309 0:ac8863619623 295 */
jhon309 0:ac8863619623 296 #define CAN_SJW_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */
jhon309 0:ac8863619623 297 #define CAN_SJW_2TQ ((uint32_t)CAN_BTR_SJW_0) /*!< 2 time quantum */
jhon309 0:ac8863619623 298 #define CAN_SJW_3TQ ((uint32_t)CAN_BTR_SJW_1) /*!< 3 time quantum */
jhon309 0:ac8863619623 299 #define CAN_SJW_4TQ ((uint32_t)CAN_BTR_SJW) /*!< 4 time quantum */
jhon309 0:ac8863619623 300
jhon309 0:ac8863619623 301 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ)|| \
jhon309 0:ac8863619623 302 ((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ))
jhon309 0:ac8863619623 303 /**
jhon309 0:ac8863619623 304 * @}
jhon309 0:ac8863619623 305 */
jhon309 0:ac8863619623 306
jhon309 0:ac8863619623 307 /** @defgroup CAN_time_quantum_in_bit_segment_1 CAN time quantum in bit segment 1
jhon309 0:ac8863619623 308 * @{
jhon309 0:ac8863619623 309 */
jhon309 0:ac8863619623 310 #define CAN_BS1_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */
jhon309 0:ac8863619623 311 #define CAN_BS1_2TQ ((uint32_t)CAN_BTR_TS1_0) /*!< 2 time quantum */
jhon309 0:ac8863619623 312 #define CAN_BS1_3TQ ((uint32_t)CAN_BTR_TS1_1) /*!< 3 time quantum */
jhon309 0:ac8863619623 313 #define CAN_BS1_4TQ ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 4 time quantum */
jhon309 0:ac8863619623 314 #define CAN_BS1_5TQ ((uint32_t)CAN_BTR_TS1_2) /*!< 5 time quantum */
jhon309 0:ac8863619623 315 #define CAN_BS1_6TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 6 time quantum */
jhon309 0:ac8863619623 316 #define CAN_BS1_7TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 7 time quantum */
jhon309 0:ac8863619623 317 #define CAN_BS1_8TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 8 time quantum */
jhon309 0:ac8863619623 318 #define CAN_BS1_9TQ ((uint32_t)CAN_BTR_TS1_3) /*!< 9 time quantum */
jhon309 0:ac8863619623 319 #define CAN_BS1_10TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0)) /*!< 10 time quantum */
jhon309 0:ac8863619623 320 #define CAN_BS1_11TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1)) /*!< 11 time quantum */
jhon309 0:ac8863619623 321 #define CAN_BS1_12TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 12 time quantum */
jhon309 0:ac8863619623 322 #define CAN_BS1_13TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2)) /*!< 13 time quantum */
jhon309 0:ac8863619623 323 #define CAN_BS1_14TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 14 time quantum */
jhon309 0:ac8863619623 324 #define CAN_BS1_15TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 15 time quantum */
jhon309 0:ac8863619623 325 #define CAN_BS1_16TQ ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */
jhon309 0:ac8863619623 326
jhon309 0:ac8863619623 327 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16TQ)
jhon309 0:ac8863619623 328 /**
jhon309 0:ac8863619623 329 * @}
jhon309 0:ac8863619623 330 */
jhon309 0:ac8863619623 331
jhon309 0:ac8863619623 332 /** @defgroup CAN_time_quantum_in_bit_segment_2 CAN time quantum in bit segment 2
jhon309 0:ac8863619623 333 * @{
jhon309 0:ac8863619623 334 */
jhon309 0:ac8863619623 335 #define CAN_BS2_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */
jhon309 0:ac8863619623 336 #define CAN_BS2_2TQ ((uint32_t)CAN_BTR_TS2_0) /*!< 2 time quantum */
jhon309 0:ac8863619623 337 #define CAN_BS2_3TQ ((uint32_t)CAN_BTR_TS2_1) /*!< 3 time quantum */
jhon309 0:ac8863619623 338 #define CAN_BS2_4TQ ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0)) /*!< 4 time quantum */
jhon309 0:ac8863619623 339 #define CAN_BS2_5TQ ((uint32_t)CAN_BTR_TS2_2) /*!< 5 time quantum */
jhon309 0:ac8863619623 340 #define CAN_BS2_6TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0)) /*!< 6 time quantum */
jhon309 0:ac8863619623 341 #define CAN_BS2_7TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1)) /*!< 7 time quantum */
jhon309 0:ac8863619623 342 #define CAN_BS2_8TQ ((uint32_t)CAN_BTR_TS2) /*!< 8 time quantum */
jhon309 0:ac8863619623 343
jhon309 0:ac8863619623 344 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8TQ)
jhon309 0:ac8863619623 345 /**
jhon309 0:ac8863619623 346 * @}
jhon309 0:ac8863619623 347 */
jhon309 0:ac8863619623 348
jhon309 0:ac8863619623 349 /** @defgroup CAN_clock_prescaler CAN clock prescaler
jhon309 0:ac8863619623 350 * @{
jhon309 0:ac8863619623 351 */
jhon309 0:ac8863619623 352 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
jhon309 0:ac8863619623 353 /**
jhon309 0:ac8863619623 354 * @}
jhon309 0:ac8863619623 355 */
jhon309 0:ac8863619623 356
jhon309 0:ac8863619623 357 /** @defgroup CAN_filter_number CAN filter number
jhon309 0:ac8863619623 358 * @{
jhon309 0:ac8863619623 359 */
jhon309 0:ac8863619623 360 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
jhon309 0:ac8863619623 361 /**
jhon309 0:ac8863619623 362 * @}
jhon309 0:ac8863619623 363 */
jhon309 0:ac8863619623 364
jhon309 0:ac8863619623 365 /** @defgroup CAN_filter_mode CAN filter mode
jhon309 0:ac8863619623 366 * @{
jhon309 0:ac8863619623 367 */
jhon309 0:ac8863619623 368 #define CAN_FILTERMODE_IDMASK ((uint8_t)0x00) /*!< Identifier mask mode */
jhon309 0:ac8863619623 369 #define CAN_FILTERMODE_IDLIST ((uint8_t)0x01) /*!< Identifier list mode */
jhon309 0:ac8863619623 370
jhon309 0:ac8863619623 371 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \
jhon309 0:ac8863619623 372 ((MODE) == CAN_FILTERMODE_IDLIST))
jhon309 0:ac8863619623 373 /**
jhon309 0:ac8863619623 374 * @}
jhon309 0:ac8863619623 375 */
jhon309 0:ac8863619623 376
jhon309 0:ac8863619623 377 /** @defgroup CAN_filter_scale CAN filter scale
jhon309 0:ac8863619623 378 * @{
jhon309 0:ac8863619623 379 */
jhon309 0:ac8863619623 380 #define CAN_FILTERSCALE_16BIT ((uint8_t)0x00) /*!< Two 16-bit filters */
jhon309 0:ac8863619623 381 #define CAN_FILTERSCALE_32BIT ((uint8_t)0x01) /*!< One 32-bit filter */
jhon309 0:ac8863619623 382
jhon309 0:ac8863619623 383 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \
jhon309 0:ac8863619623 384 ((SCALE) == CAN_FILTERSCALE_32BIT))
jhon309 0:ac8863619623 385 /**
jhon309 0:ac8863619623 386 * @}
jhon309 0:ac8863619623 387 */
jhon309 0:ac8863619623 388
jhon309 0:ac8863619623 389 /** @defgroup CAN_filter_FIFO CAN filter FIFO
jhon309 0:ac8863619623 390 * @{
jhon309 0:ac8863619623 391 */
jhon309 0:ac8863619623 392 #define CAN_FILTER_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
jhon309 0:ac8863619623 393 #define CAN_FILTER_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */
jhon309 0:ac8863619623 394
jhon309 0:ac8863619623 395 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \
jhon309 0:ac8863619623 396 ((FIFO) == CAN_FILTER_FIFO1))
jhon309 0:ac8863619623 397
jhon309 0:ac8863619623 398 /* Legacy defines */
jhon309 0:ac8863619623 399 #define CAN_FilterFIFO0 CAN_FILTER_FIFO0
jhon309 0:ac8863619623 400 #define CAN_FilterFIFO1 CAN_FILTER_FIFO1
jhon309 0:ac8863619623 401 /**
jhon309 0:ac8863619623 402 * @}
jhon309 0:ac8863619623 403 */
jhon309 0:ac8863619623 404
jhon309 0:ac8863619623 405 /** @defgroup CAN_Start_bank_filter_for_slave_CAN CAN Start bank filter for slave CAN
jhon309 0:ac8863619623 406 * @{
jhon309 0:ac8863619623 407 */
jhon309 0:ac8863619623 408 #define IS_CAN_BANKNUMBER(BANKNUMBER) ((BANKNUMBER) <= 28)
jhon309 0:ac8863619623 409 /**
jhon309 0:ac8863619623 410 * @}
jhon309 0:ac8863619623 411 */
jhon309 0:ac8863619623 412
jhon309 0:ac8863619623 413 /** @defgroup CAN_Tx CAN Tx
jhon309 0:ac8863619623 414 * @{
jhon309 0:ac8863619623 415 */
jhon309 0:ac8863619623 416 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
jhon309 0:ac8863619623 417 #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
jhon309 0:ac8863619623 418 #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
jhon309 0:ac8863619623 419 #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
jhon309 0:ac8863619623 420 /**
jhon309 0:ac8863619623 421 * @}
jhon309 0:ac8863619623 422 */
jhon309 0:ac8863619623 423
jhon309 0:ac8863619623 424 /** @defgroup CAN_identifier_type CAN identifier type
jhon309 0:ac8863619623 425 * @{
jhon309 0:ac8863619623 426 */
jhon309 0:ac8863619623 427 #define CAN_ID_STD ((uint32_t)0x00000000) /*!< Standard Id */
jhon309 0:ac8863619623 428 #define CAN_ID_EXT ((uint32_t)0x00000004) /*!< Extended Id */
jhon309 0:ac8863619623 429 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_ID_STD) || \
jhon309 0:ac8863619623 430 ((IDTYPE) == CAN_ID_EXT))
jhon309 0:ac8863619623 431 /**
jhon309 0:ac8863619623 432 * @}
jhon309 0:ac8863619623 433 */
jhon309 0:ac8863619623 434
jhon309 0:ac8863619623 435 /** @defgroup CAN_remote_transmission_request CAN remote transmission request
jhon309 0:ac8863619623 436 * @{
jhon309 0:ac8863619623 437 */
jhon309 0:ac8863619623 438 #define CAN_RTR_DATA ((uint32_t)0x00000000) /*!< Data frame */
jhon309 0:ac8863619623 439 #define CAN_RTR_REMOTE ((uint32_t)0x00000002) /*!< Remote frame */
jhon309 0:ac8863619623 440 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE))
jhon309 0:ac8863619623 441
jhon309 0:ac8863619623 442 /**
jhon309 0:ac8863619623 443 * @}
jhon309 0:ac8863619623 444 */
jhon309 0:ac8863619623 445
jhon309 0:ac8863619623 446 /** @defgroup CAN_transmit_constants CAN transmit constants
jhon309 0:ac8863619623 447 * @{
jhon309 0:ac8863619623 448 */
jhon309 0:ac8863619623 449 #define CAN_TXSTATUS_FAILED ((uint8_t)0x00) /*!< CAN transmission failed */
jhon309 0:ac8863619623 450 #define CAN_TXSTATUS_OK ((uint8_t)0x01) /*!< CAN transmission succeeded */
jhon309 0:ac8863619623 451 #define CAN_TXSTATUS_PENDING ((uint8_t)0x02) /*!< CAN transmission pending */
jhon309 0:ac8863619623 452 #define CAN_TXSTATUS_NOMAILBOX ((uint8_t)0x04) /*!< CAN cell did not provide CAN_TxStatus_NoMailBox */
jhon309 0:ac8863619623 453
jhon309 0:ac8863619623 454 /**
jhon309 0:ac8863619623 455 * @}
jhon309 0:ac8863619623 456 */
jhon309 0:ac8863619623 457
jhon309 0:ac8863619623 458 /** @defgroup CAN_receive_FIFO_number_constants CAN receive FIFO number constants
jhon309 0:ac8863619623 459 * @{
jhon309 0:ac8863619623 460 */
jhon309 0:ac8863619623 461 #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */
jhon309 0:ac8863619623 462 #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */
jhon309 0:ac8863619623 463
jhon309 0:ac8863619623 464 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
jhon309 0:ac8863619623 465 /**
jhon309 0:ac8863619623 466 * @}
jhon309 0:ac8863619623 467 */
jhon309 0:ac8863619623 468
jhon309 0:ac8863619623 469 /** @defgroup CAN_flags CAN flags
jhon309 0:ac8863619623 470 * @{
jhon309 0:ac8863619623 471 */
jhon309 0:ac8863619623 472 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
jhon309 0:ac8863619623 473 and CAN_ClearFlag() functions. */
jhon309 0:ac8863619623 474 /* If the flag is 0x1XXXXXXX, it means that it can only be used with
jhon309 0:ac8863619623 475 CAN_GetFlagStatus() function. */
jhon309 0:ac8863619623 476
jhon309 0:ac8863619623 477 /* Transmit Flags */
jhon309 0:ac8863619623 478 #define CAN_FLAG_RQCP0 ((uint32_t)0x00000500) /*!< Request MailBox0 flag */
jhon309 0:ac8863619623 479 #define CAN_FLAG_RQCP1 ((uint32_t)0x00000508) /*!< Request MailBox1 flag */
jhon309 0:ac8863619623 480 #define CAN_FLAG_RQCP2 ((uint32_t)0x00000510) /*!< Request MailBox2 flag */
jhon309 0:ac8863619623 481 #define CAN_FLAG_TXOK0 ((uint32_t)0x00000501) /*!< Transmission OK MailBox0 flag */
jhon309 0:ac8863619623 482 #define CAN_FLAG_TXOK1 ((uint32_t)0x00000509) /*!< Transmission OK MailBox1 flag */
jhon309 0:ac8863619623 483 #define CAN_FLAG_TXOK2 ((uint32_t)0x00000511) /*!< Transmission OK MailBox2 flag */
jhon309 0:ac8863619623 484 #define CAN_FLAG_TME0 ((uint32_t)0x0000051A) /*!< Transmit mailbox 0 empty flag */
jhon309 0:ac8863619623 485 #define CAN_FLAG_TME1 ((uint32_t)0x0000051B) /*!< Transmit mailbox 0 empty flag */
jhon309 0:ac8863619623 486 #define CAN_FLAG_TME2 ((uint32_t)0x0000051C) /*!< Transmit mailbox 0 empty flag */
jhon309 0:ac8863619623 487
jhon309 0:ac8863619623 488 /* Receive Flags */
jhon309 0:ac8863619623 489 #define CAN_FLAG_FF0 ((uint32_t)0x00000203) /*!< FIFO 0 Full flag */
jhon309 0:ac8863619623 490 #define CAN_FLAG_FOV0 ((uint32_t)0x00000204) /*!< FIFO 0 Overrun flag */
jhon309 0:ac8863619623 491
jhon309 0:ac8863619623 492 #define CAN_FLAG_FF1 ((uint32_t)0x00000403) /*!< FIFO 1 Full flag */
jhon309 0:ac8863619623 493 #define CAN_FLAG_FOV1 ((uint32_t)0x00000404) /*!< FIFO 1 Overrun flag */
jhon309 0:ac8863619623 494
jhon309 0:ac8863619623 495 /* Operating Mode Flags */
jhon309 0:ac8863619623 496 #define CAN_FLAG_WKU ((uint32_t)0x00000103) /*!< Wake up flag */
jhon309 0:ac8863619623 497 #define CAN_FLAG_SLAK ((uint32_t)0x00000101) /*!< Sleep acknowledge flag */
jhon309 0:ac8863619623 498 #define CAN_FLAG_SLAKI ((uint32_t)0x00000104) /*!< Sleep acknowledge flag */
jhon309 0:ac8863619623 499 /* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible.
jhon309 0:ac8863619623 500 In this case the SLAK bit can be polled.*/
jhon309 0:ac8863619623 501
jhon309 0:ac8863619623 502 /* Error Flags */
jhon309 0:ac8863619623 503 #define CAN_FLAG_EWG ((uint32_t)0x00000300) /*!< Error warning flag */
jhon309 0:ac8863619623 504 #define CAN_FLAG_EPV ((uint32_t)0x00000301) /*!< Error passive flag */
jhon309 0:ac8863619623 505 #define CAN_FLAG_BOF ((uint32_t)0x00000302) /*!< Bus-Off flag */
jhon309 0:ac8863619623 506 /**
jhon309 0:ac8863619623 507 * @}
jhon309 0:ac8863619623 508 */
jhon309 0:ac8863619623 509
jhon309 0:ac8863619623 510
jhon309 0:ac8863619623 511 /** @defgroup CAN_interrupts CAN interrupts
jhon309 0:ac8863619623 512 * @{
jhon309 0:ac8863619623 513 */
jhon309 0:ac8863619623 514 #define CAN_IT_TME ((uint32_t)CAN_IER_TMEIE) /*!< Transmit mailbox empty interrupt */
jhon309 0:ac8863619623 515
jhon309 0:ac8863619623 516 /* Receive Interrupts */
jhon309 0:ac8863619623 517 #define CAN_IT_FMP0 ((uint32_t)CAN_IER_FMPIE0) /*!< FIFO 0 message pending interrupt */
jhon309 0:ac8863619623 518 #define CAN_IT_FF0 ((uint32_t)CAN_IER_FFIE0) /*!< FIFO 0 full interrupt */
jhon309 0:ac8863619623 519 #define CAN_IT_FOV0 ((uint32_t)CAN_IER_FOVIE0) /*!< FIFO 0 overrun interrupt */
jhon309 0:ac8863619623 520 #define CAN_IT_FMP1 ((uint32_t)CAN_IER_FMPIE1) /*!< FIFO 1 message pending interrupt */
jhon309 0:ac8863619623 521 #define CAN_IT_FF1 ((uint32_t)CAN_IER_FFIE1) /*!< FIFO 1 full interrupt */
jhon309 0:ac8863619623 522 #define CAN_IT_FOV1 ((uint32_t)CAN_IER_FOVIE1) /*!< FIFO 1 overrun interrupt */
jhon309 0:ac8863619623 523
jhon309 0:ac8863619623 524 /* Operating Mode Interrupts */
jhon309 0:ac8863619623 525 #define CAN_IT_WKU ((uint32_t)CAN_IER_WKUIE) /*!< Wake-up interrupt */
jhon309 0:ac8863619623 526 #define CAN_IT_SLK ((uint32_t)CAN_IER_SLKIE) /*!< Sleep acknowledge interrupt */
jhon309 0:ac8863619623 527
jhon309 0:ac8863619623 528 /* Error Interrupts */
jhon309 0:ac8863619623 529 #define CAN_IT_EWG ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt */
jhon309 0:ac8863619623 530 #define CAN_IT_EPV ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt */
jhon309 0:ac8863619623 531 #define CAN_IT_BOF ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt */
jhon309 0:ac8863619623 532 #define CAN_IT_LEC ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */
jhon309 0:ac8863619623 533 #define CAN_IT_ERR ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt */
jhon309 0:ac8863619623 534
jhon309 0:ac8863619623 535 /* Flags named as Interrupts : kept only for FW compatibility */
jhon309 0:ac8863619623 536 #define CAN_IT_RQCP0 CAN_IT_TME
jhon309 0:ac8863619623 537 #define CAN_IT_RQCP1 CAN_IT_TME
jhon309 0:ac8863619623 538 #define CAN_IT_RQCP2 CAN_IT_TME
jhon309 0:ac8863619623 539 /**
jhon309 0:ac8863619623 540 * @}
jhon309 0:ac8863619623 541 */
jhon309 0:ac8863619623 542
jhon309 0:ac8863619623 543 /** @defgroup CAN_Timeouts CAN Timeouts
jhon309 0:ac8863619623 544 * @{
jhon309 0:ac8863619623 545 */
jhon309 0:ac8863619623 546
jhon309 0:ac8863619623 547 /* Time out for INAK bit */
jhon309 0:ac8863619623 548 #define INAK_TIMEOUT ((uint32_t)0x00FFFFFF)
jhon309 0:ac8863619623 549 /* Time out for SLAK bit */
jhon309 0:ac8863619623 550 #define SLAK_TIMEOUT ((uint32_t)0x00FFFFFF)
jhon309 0:ac8863619623 551 /**
jhon309 0:ac8863619623 552 * @}
jhon309 0:ac8863619623 553 */
jhon309 0:ac8863619623 554
jhon309 0:ac8863619623 555 /** @defgroup CAN_Mailboxes CAN Mailboxes
jhon309 0:ac8863619623 556 * @{
jhon309 0:ac8863619623 557 */
jhon309 0:ac8863619623 558 /* Mailboxes definition */
jhon309 0:ac8863619623 559 #define CAN_TXMAILBOX_0 ((uint8_t)0x00)
jhon309 0:ac8863619623 560 #define CAN_TXMAILBOX_1 ((uint8_t)0x01)
jhon309 0:ac8863619623 561 #define CAN_TXMAILBOX_2 ((uint8_t)0x02)
jhon309 0:ac8863619623 562 /**
jhon309 0:ac8863619623 563 * @}
jhon309 0:ac8863619623 564 */
jhon309 0:ac8863619623 565
jhon309 0:ac8863619623 566 /**
jhon309 0:ac8863619623 567 * @}
jhon309 0:ac8863619623 568 */
jhon309 0:ac8863619623 569
jhon309 0:ac8863619623 570 /* Exported macros -----------------------------------------------------------*/
jhon309 0:ac8863619623 571 /** @defgroup CAN_Exported_Macros CAN Exported Macros
jhon309 0:ac8863619623 572 * @{
jhon309 0:ac8863619623 573 */
jhon309 0:ac8863619623 574
jhon309 0:ac8863619623 575 /** @brief Reset CAN handle state
jhon309 0:ac8863619623 576 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 577 * @retval None
jhon309 0:ac8863619623 578 */
jhon309 0:ac8863619623 579 #define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET)
jhon309 0:ac8863619623 580
jhon309 0:ac8863619623 581 /**
jhon309 0:ac8863619623 582 * @brief Enable the specified CAN interrupts.
jhon309 0:ac8863619623 583 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 584 * @param __INTERRUPT__: CAN Interrupt
jhon309 0:ac8863619623 585 * @retval None
jhon309 0:ac8863619623 586 */
jhon309 0:ac8863619623 587 #define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
jhon309 0:ac8863619623 588
jhon309 0:ac8863619623 589 /**
jhon309 0:ac8863619623 590 * @brief Disable the specified CAN interrupts.
jhon309 0:ac8863619623 591 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 592 * @param __INTERRUPT__: CAN Interrupt
jhon309 0:ac8863619623 593 * @retval None
jhon309 0:ac8863619623 594 */
jhon309 0:ac8863619623 595 #define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
jhon309 0:ac8863619623 596
jhon309 0:ac8863619623 597 /**
jhon309 0:ac8863619623 598 * @brief Return the number of pending received messages.
jhon309 0:ac8863619623 599 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 600 * @param __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
jhon309 0:ac8863619623 601 * @retval The number of pending message.
jhon309 0:ac8863619623 602 */
jhon309 0:ac8863619623 603 #define __HAL_CAN_MSG_PENDING(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
jhon309 0:ac8863619623 604 ((uint8_t)((__HANDLE__)->Instance->RF0R&(uint32_t)0x03)) : ((uint8_t)((__HANDLE__)->Instance->RF1R&(uint32_t)0x03)))
jhon309 0:ac8863619623 605
jhon309 0:ac8863619623 606 /** @brief Check whether the specified CAN flag is set or not.
jhon309 0:ac8863619623 607 * @param __HANDLE__: specifies the CAN Handle.
jhon309 0:ac8863619623 608 * @param __FLAG__: specifies the flag to check.
jhon309 0:ac8863619623 609 * This parameter can be one of the following values:
jhon309 0:ac8863619623 610 * @arg CAN_TSR_RQCP0: Request MailBox0 Flag
jhon309 0:ac8863619623 611 * @arg CAN_TSR_RQCP1: Request MailBox1 Flag
jhon309 0:ac8863619623 612 * @arg CAN_TSR_RQCP2: Request MailBox2 Flag
jhon309 0:ac8863619623 613 * @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
jhon309 0:ac8863619623 614 * @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
jhon309 0:ac8863619623 615 * @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
jhon309 0:ac8863619623 616 * @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
jhon309 0:ac8863619623 617 * @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
jhon309 0:ac8863619623 618 * @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
jhon309 0:ac8863619623 619 * @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
jhon309 0:ac8863619623 620 * @arg CAN_FLAG_FF0: FIFO 0 Full Flag
jhon309 0:ac8863619623 621 * @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
jhon309 0:ac8863619623 622 * @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
jhon309 0:ac8863619623 623 * @arg CAN_FLAG_FF1: FIFO 1 Full Flag
jhon309 0:ac8863619623 624 * @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
jhon309 0:ac8863619623 625 * @arg CAN_FLAG_WKU: Wake up Flag
jhon309 0:ac8863619623 626 * @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
jhon309 0:ac8863619623 627 * @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
jhon309 0:ac8863619623 628 * @arg CAN_FLAG_EWG: Error Warning Flag
jhon309 0:ac8863619623 629 * @arg CAN_FLAG_EPV: Error Passive Flag
jhon309 0:ac8863619623 630 * @arg CAN_FLAG_BOF: Bus-Off Flag
jhon309 0:ac8863619623 631 * @retval The new state of __FLAG__ (TRUE or FALSE).
jhon309 0:ac8863619623 632 */
jhon309 0:ac8863619623 633 #define CAN_FLAG_MASK ((uint32_t)0x000000FF)
jhon309 0:ac8863619623 634 #define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \
jhon309 0:ac8863619623 635 ((((__FLAG__) >> 8) == 5)? ((((__HANDLE__)->Instance->TSR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 636 (((__FLAG__) >> 8) == 2)? ((((__HANDLE__)->Instance->RF0R) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 637 (((__FLAG__) >> 8) == 4)? ((((__HANDLE__)->Instance->RF1R) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 638 (((__FLAG__) >> 8) == 1)? ((((__HANDLE__)->Instance->MSR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 639 ((((__HANDLE__)->Instance->ESR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))))
jhon309 0:ac8863619623 640
jhon309 0:ac8863619623 641 /** @brief Clear the specified CAN pending flag.
jhon309 0:ac8863619623 642 * @param __HANDLE__: specifies the CAN Handle.
jhon309 0:ac8863619623 643 * @param __FLAG__: specifies the flag to check.
jhon309 0:ac8863619623 644 * This parameter can be one of the following values:
jhon309 0:ac8863619623 645 * @arg CAN_TSR_RQCP0: Request MailBox0 Flag
jhon309 0:ac8863619623 646 * @arg CAN_TSR_RQCP1: Request MailBox1 Flag
jhon309 0:ac8863619623 647 * @arg CAN_TSR_RQCP2: Request MailBox2 Flag
jhon309 0:ac8863619623 648 * @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag
jhon309 0:ac8863619623 649 * @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag
jhon309 0:ac8863619623 650 * @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag
jhon309 0:ac8863619623 651 * @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag
jhon309 0:ac8863619623 652 * @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag
jhon309 0:ac8863619623 653 * @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag
jhon309 0:ac8863619623 654 * @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
jhon309 0:ac8863619623 655 * @arg CAN_FLAG_FF0: FIFO 0 Full Flag
jhon309 0:ac8863619623 656 * @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
jhon309 0:ac8863619623 657 * @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
jhon309 0:ac8863619623 658 * @arg CAN_FLAG_FF1: FIFO 1 Full Flag
jhon309 0:ac8863619623 659 * @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
jhon309 0:ac8863619623 660 * @arg CAN_FLAG_WKU: Wake up Flag
jhon309 0:ac8863619623 661 * @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag
jhon309 0:ac8863619623 662 * @arg CAN_FLAG_EWG: Error Warning Flag
jhon309 0:ac8863619623 663 * @arg CAN_FLAG_EPV: Error Passive Flag
jhon309 0:ac8863619623 664 * @arg CAN_FLAG_BOF: Bus-Off Flag
jhon309 0:ac8863619623 665 * @retval The new state of __FLAG__ (TRUE or FALSE).
jhon309 0:ac8863619623 666 */
jhon309 0:ac8863619623 667 #define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \
jhon309 0:ac8863619623 668 ((((__FLAG__) >> 8U) == 5)? (((__HANDLE__)->Instance->TSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 669 (((__FLAG__) >> 8U) == 2)? (((__HANDLE__)->Instance->RF0R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 670 (((__FLAG__) >> 8U) == 4)? (((__HANDLE__)->Instance->RF1R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \
jhon309 0:ac8863619623 671 (((__FLAG__) >> 8U) == 1)? (((__HANDLE__)->Instance->MSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0)
jhon309 0:ac8863619623 672
jhon309 0:ac8863619623 673
jhon309 0:ac8863619623 674 /** @brief Check if the specified CAN interrupt source is enabled or disabled.
jhon309 0:ac8863619623 675 * @param __HANDLE__: specifies the CAN Handle.
jhon309 0:ac8863619623 676 * @param __INTERRUPT__: specifies the CAN interrupt source to check.
jhon309 0:ac8863619623 677 * This parameter can be one of the following values:
jhon309 0:ac8863619623 678 * @arg CAN_IT_TME: Transmit mailbox empty interrupt enable
jhon309 0:ac8863619623 679 * @arg CAN_IT_FMP0: FIFO0 message pending interrupt enablev
jhon309 0:ac8863619623 680 * @arg CAN_IT_FMP1: FIFO1 message pending interrupt enable
jhon309 0:ac8863619623 681 * @retval The new state of __IT__ (TRUE or FALSE).
jhon309 0:ac8863619623 682 */
jhon309 0:ac8863619623 683 #define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
jhon309 0:ac8863619623 684
jhon309 0:ac8863619623 685 /**
jhon309 0:ac8863619623 686 * @brief Check the transmission status of a CAN Frame.
jhon309 0:ac8863619623 687 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 688 * @param __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
jhon309 0:ac8863619623 689 * @retval The new status of transmission (TRUE or FALSE).
jhon309 0:ac8863619623 690 */
jhon309 0:ac8863619623 691 #define __HAL_CAN_TRANSMIT_STATUS(__HANDLE__, __TRANSMITMAILBOX__)\
jhon309 0:ac8863619623 692 (((__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)) :\
jhon309 0:ac8863619623 693 ((__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)) :\
jhon309 0:ac8863619623 694 ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)) == (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)))
jhon309 0:ac8863619623 695
jhon309 0:ac8863619623 696
jhon309 0:ac8863619623 697
jhon309 0:ac8863619623 698 /**
jhon309 0:ac8863619623 699 * @brief Release the specified receive FIFO.
jhon309 0:ac8863619623 700 * @param __HANDLE__: CAN handle.
jhon309 0:ac8863619623 701 * @param __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
jhon309 0:ac8863619623 702 * @retval None
jhon309 0:ac8863619623 703 */
jhon309 0:ac8863619623 704 #define __HAL_CAN_FIFO_RELEASE(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \
jhon309 0:ac8863619623 705 ((__HANDLE__)->Instance->RF0R |= CAN_RF0R_RFOM0) : ((__HANDLE__)->Instance->RF1R |= CAN_RF1R_RFOM1))
jhon309 0:ac8863619623 706
jhon309 0:ac8863619623 707 /**
jhon309 0:ac8863619623 708 * @brief Cancel a transmit request.
jhon309 0:ac8863619623 709 * @param __HANDLE__: specifies the CAN Handle.
jhon309 0:ac8863619623 710 * @param __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission.
jhon309 0:ac8863619623 711 * @retval None
jhon309 0:ac8863619623 712 */
jhon309 0:ac8863619623 713 #define __HAL_CAN_CANCEL_TRANSMIT(__HANDLE__, __TRANSMITMAILBOX__)\
jhon309 0:ac8863619623 714 (((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ0) :\
jhon309 0:ac8863619623 715 ((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ1) :\
jhon309 0:ac8863619623 716 ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ2))
jhon309 0:ac8863619623 717
jhon309 0:ac8863619623 718 /**
jhon309 0:ac8863619623 719 * @brief Enable or disables the DBG Freeze for CAN.
jhon309 0:ac8863619623 720 * @param __HANDLE__: specifies the CAN Handle.
jhon309 0:ac8863619623 721 * @param __NEWSTATE__: new state of the CAN peripheral.
jhon309 0:ac8863619623 722 * This parameter can be: ENABLE (CAN reception/transmission is frozen
jhon309 0:ac8863619623 723 * during debug. Reception FIFOs can still be accessed/controlled normally)
jhon309 0:ac8863619623 724 * or DISABLE (CAN is working during debug).
jhon309 0:ac8863619623 725 * @retval None
jhon309 0:ac8863619623 726 */
jhon309 0:ac8863619623 727 #define __HAL_CAN_DBG_FREEZE(__HANDLE__, __NEWSTATE__) (((__NEWSTATE__) == ENABLE)? \
jhon309 0:ac8863619623 728 ((__HANDLE__)->Instance->MCR |= CAN_MCR_DBF) : ((__HANDLE__)->Instance->MCR &= ~CAN_MCR_DBF))
jhon309 0:ac8863619623 729
jhon309 0:ac8863619623 730 /**
jhon309 0:ac8863619623 731 * @}
jhon309 0:ac8863619623 732 */
jhon309 0:ac8863619623 733
jhon309 0:ac8863619623 734 /* Exported functions --------------------------------------------------------*/
jhon309 0:ac8863619623 735 /** @addtogroup CAN_Exported_Functions CAN Exported Functions
jhon309 0:ac8863619623 736 * @{
jhon309 0:ac8863619623 737 */
jhon309 0:ac8863619623 738
jhon309 0:ac8863619623 739 /** @addtogroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions
jhon309 0:ac8863619623 740 * @brief Initialization and Configuration functions
jhon309 0:ac8863619623 741 * @{
jhon309 0:ac8863619623 742 */
jhon309 0:ac8863619623 743
jhon309 0:ac8863619623 744 /* Initialization and de-initialization functions *****************************/
jhon309 0:ac8863619623 745 HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 746 HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig);
jhon309 0:ac8863619623 747 HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 748 void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 749 void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 750 /**
jhon309 0:ac8863619623 751 * @}
jhon309 0:ac8863619623 752 */
jhon309 0:ac8863619623 753
jhon309 0:ac8863619623 754 /** @addtogroup CAN_Exported_Functions_Group2 I/O operation functions
jhon309 0:ac8863619623 755 * @brief I/O operation functions
jhon309 0:ac8863619623 756 * @{
jhon309 0:ac8863619623 757 */
jhon309 0:ac8863619623 758
jhon309 0:ac8863619623 759 /* IO operation functions *****************************************************/
jhon309 0:ac8863619623 760 HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout);
jhon309 0:ac8863619623 761 HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef *hcan);
jhon309 0:ac8863619623 762 HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef *hcan, uint8_t FIFONumber, uint32_t Timeout);
jhon309 0:ac8863619623 763 HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef *hcan, uint8_t FIFONumber);
jhon309 0:ac8863619623 764 HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef *hcan);
jhon309 0:ac8863619623 765 HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan);
jhon309 0:ac8863619623 766
jhon309 0:ac8863619623 767 void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 768
jhon309 0:ac8863619623 769 void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 770 void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 771 void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan);
jhon309 0:ac8863619623 772 /**
jhon309 0:ac8863619623 773 * @}
jhon309 0:ac8863619623 774 */
jhon309 0:ac8863619623 775
jhon309 0:ac8863619623 776 /** @addtogroup CAN_Exported_Functions_Group3 Peripheral State and Error functions
jhon309 0:ac8863619623 777 * @brief CAN Peripheral State functions
jhon309 0:ac8863619623 778 * @{
jhon309 0:ac8863619623 779 */
jhon309 0:ac8863619623 780 /* Peripheral State and Error functions ***************************************/
jhon309 0:ac8863619623 781 uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan);
jhon309 0:ac8863619623 782 HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan);
jhon309 0:ac8863619623 783
jhon309 0:ac8863619623 784 /**
jhon309 0:ac8863619623 785 * @}
jhon309 0:ac8863619623 786 */
jhon309 0:ac8863619623 787
jhon309 0:ac8863619623 788 /**
jhon309 0:ac8863619623 789 * @}
jhon309 0:ac8863619623 790 */
jhon309 0:ac8863619623 791
jhon309 0:ac8863619623 792 /**
jhon309 0:ac8863619623 793 * @}
jhon309 0:ac8863619623 794 */
jhon309 0:ac8863619623 795
jhon309 0:ac8863619623 796 /**
jhon309 0:ac8863619623 797 * @}
jhon309 0:ac8863619623 798 */
jhon309 0:ac8863619623 799
jhon309 0:ac8863619623 800 #endif /* STM32F072xB || STM32F042x6 || STM32F048xx || STM32F078xx || STM32F091xC || STM32F098xx */
jhon309 0:ac8863619623 801
jhon309 0:ac8863619623 802 #ifdef __cplusplus
jhon309 0:ac8863619623 803 }
jhon309 0:ac8863619623 804 #endif
jhon309 0:ac8863619623 805
jhon309 0:ac8863619623 806 #endif /* __STM32F0xx_HAL_CAN_H */
jhon309 0:ac8863619623 807
jhon309 0:ac8863619623 808
jhon309 0:ac8863619623 809 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
jhon309 0:ac8863619623 810