1 /** 2 ****************************************************************************** 3 * @file tae32f53xx_ll_can.h 4 * @author MCD Application Team 5 * @brief Header file for CAN LL module. 6 * 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2020 Tai-Action. 11 * All rights reserved.</center></h2> 12 * 13 * This software is licensed by Tai-Action under BSD 3-Clause license, 14 * the "License"; You may not use this file except in compliance with the 15 * License. You may obtain a copy of the License at: 16 * opensource.org/licenses/BSD-3-Clause 17 * 18 ****************************************************************************** 19 */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef _TAE32F53XX_LL_CAN_H_ 23 #define _TAE32F53XX_LL_CAN_H_ 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif /* __cplusplus */ 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "tae32f53xx_ll_def.h" 31 32 33 /** @addtogroup TAE32F53xx_LL_Driver 34 * @{ 35 */ 36 37 /** @addtogroup CAN_LL 38 * @{ 39 */ 40 41 42 /* Exported constants --------------------------------------------------------*/ 43 /* Exported types ------------------------------------------------------------*/ 44 /** @defgroup CAN_LL_Exported_Types CAN LL Exported Types 45 * @brief CAN LL Exported Types 46 * @{ 47 */ 48 49 /** 50 *@brief CAN RX buffer status enum type define 51 */ 52 typedef enum { 53 CAN_RX_BUF_STA_EMPTY = 0, /*!< CAN RX buffer empty */ 54 CAN_RX_BUF_STA_FEW, /*!< CAN RX buffer few */ 55 CAN_RX_BUF_STA_ALMOST_FULL, /*!< CAN RX buffer almost full */ 56 CAN_RX_BUF_STA_FULL, /*!< CAN RX buffer full */ 57 } CAN_RxBufStaETypeDef; 58 59 /** 60 * @brief CAN acceptance filter slot definition. 61 */ 62 typedef enum { 63 CAN_ACCEPT_FILT_SLOT_0 = 0, /*!< CAN acceptance filter slot 0 */ 64 CAN_ACCEPT_FILT_SLOT_1, /*!< CAN acceptance filter slot 1 */ 65 CAN_ACCEPT_FILT_SLOT_2, /*!< CAN acceptance filter slot 2 */ 66 CAN_ACCEPT_FILT_SLOT_3, /*!< CAN acceptance filter slot 3 */ 67 CAN_ACCEPT_FILT_SLOT_4, /*!< CAN acceptance filter slot 4 */ 68 CAN_ACCEPT_FILT_SLOT_5, /*!< CAN acceptance filter slot 5 */ 69 CAN_ACCEPT_FILT_SLOT_6, /*!< CAN acceptance filter slot 6 */ 70 CAN_ACCEPT_FILT_SLOT_7, /*!< CAN acceptance filter slot 7 */ 71 CAN_ACCEPT_FILT_SLOT_8, /*!< CAN acceptance filter slot 8 */ 72 CAN_ACCEPT_FILT_SLOT_9, /*!< CAN acceptance filter slot 9 */ 73 CAN_ACCEPT_FILT_SLOT_10, /*!< CAN acceptance filter slot 10 */ 74 CAN_ACCEPT_FILT_SLOT_11, /*!< CAN acceptance filter slot 11 */ 75 CAN_ACCEPT_FILT_SLOT_12, /*!< CAN acceptance filter slot 12 */ 76 CAN_ACCEPT_FILT_SLOT_13, /*!< CAN acceptance filter slot 13 */ 77 CAN_ACCEPT_FILT_SLOT_14, /*!< CAN acceptance filter slot 14 */ 78 CAN_ACCEPT_FILT_SLOT_15, /*!< CAN acceptance filter slot 15 */ 79 } CAN_AcceptFilSlotETypeDef; 80 81 /** 82 * @brief CAN RX buffer almost full warnning limit definition 83 */ 84 typedef enum { 85 CAN_RX_ALMOST_FULL_LIMIT_0 = 0, /*!< CAN RX buffer almost full warnning limit: 0 Byte */ 86 CAN_RX_ALMOST_FULL_LIMIT_1, /*!< CAN RX buffer almost full warnning limit: 1 Byte */ 87 CAN_RX_ALMOST_FULL_LIMIT_2, /*!< CAN RX buffer almost full warnning limit: 2 Byte */ 88 CAN_RX_ALMOST_FULL_LIMIT_3, /*!< CAN RX buffer almost full warnning limit: 3 Byte */ 89 CAN_RX_ALMOST_FULL_LIMIT_4, /*!< CAN RX buffer almost full warnning limit: 4 Byte */ 90 CAN_RX_ALMOST_FULL_LIMIT_5, /*!< CAN RX buffer almost full warnning limit: 5 Byte */ 91 CAN_RX_ALMOST_FULL_LIMIT_6, /*!< CAN RX buffer almost full warnning limit: 6 Byte */ 92 CAN_RX_ALMOST_FULL_LIMIT_7, /*!< CAN RX buffer almost full warnning limit: 7 Byte */ 93 CAN_RX_ALMOST_FULL_LIMIT_8, /*!< CAN RX buffer almost full warnning limit: 8 Byte */ 94 CAN_RX_ALMOST_FULL_LIMIT_9, /*!< CAN RX buffer almost full warnning limit: 9 Byte */ 95 CAN_RX_ALMOST_FULL_LIMIT_10, /*!< CAN RX buffer almost full warnning limit: 10 Byte */ 96 CAN_RX_ALMOST_FULL_LIMIT_11, /*!< CAN RX buffer almost full warnning limit: 11 Byte */ 97 CAN_RX_ALMOST_FULL_LIMIT_12, /*!< CAN RX buffer almost full warnning limit: 12 Byte */ 98 CAN_RX_ALMOST_FULL_LIMIT_13, /*!< CAN RX buffer almost full warnning limit: 13 Byte */ 99 CAN_RX_ALMOST_FULL_LIMIT_14, /*!< CAN RX buffer almost full warnning limit: 14 Byte */ 100 CAN_RX_ALMOST_FULL_LIMIT_15, /*!< CAN RX buffer almost full warnning limit: 15 Byte */ 101 } CAN_RxAlmostFullLimitETypeDef; 102 103 /** 104 * @brief CAN programmable error warning limit definition 105 */ 106 typedef enum { 107 CAN_ERR_WARN_LIMIT_8 = 0, /*!< CAN programmable error warning limit: 8 bytes */ 108 CAN_ERR_WARN_LIMIT_16, /*!< CAN programmable error warning limit: 16 bytes */ 109 CAN_ERR_WARN_LIMIT_24, /*!< CAN programmable error warning limit: 24 bytes */ 110 CAN_ERR_WARN_LIMIT_32, /*!< CAN programmable error warning limit: 32 bytes */ 111 CAN_ERR_WARN_LIMIT_40, /*!< CAN programmable error warning limit: 40 bytes */ 112 CAN_ERR_WARN_LIMIT_48, /*!< CAN programmable error warning limit: 48 bytes */ 113 CAN_ERR_WARN_LIMIT_56, /*!< CAN programmable error warning limit: 56 bytes */ 114 CAN_ERR_WARN_LIMIT_64, /*!< CAN programmable error warning limit: 64 bytes */ 115 CAN_ERR_WARN_LIMIT_72, /*!< CAN programmable error warning limit: 72 bytes */ 116 CAN_ERR_WARN_LIMIT_80, /*!< CAN programmable error warning limit: 80 bytes */ 117 CAN_ERR_WARN_LIMIT_88, /*!< CAN programmable error warning limit: 88 bytes */ 118 CAN_ERR_WARN_LIMIT_96, /*!< CAN programmable error warning limit: 96 bytes */ 119 CAN_ERR_WARN_LIMIT_104, /*!< CAN programmable error warning limit: 104 bytes */ 120 CAN_ERR_WARN_LIMIT_112, /*!< CAN programmable error warning limit: 112 bytes */ 121 CAN_ERR_WARN_LIMIT_120, /*!< CAN programmable error warning limit: 120 bytes */ 122 CAN_ERR_WARN_LIMIT_128, /*!< CAN programmable error warning limit: 128 bytes */ 123 } CAN_ErrWarnLimitETypeDef; 124 125 126 /** 127 * @brief CAN RX buffer format type definition 128 */ 129 typedef struct __CAN_RxBufFormatTypeDef { 130 /*! Standard/Extended iDentifier value 131 */ 132 uint32_t id : 29, 133 134 /*! Reserved bit. 135 */ 136 reserved1 : 2, 137 138 /*! Error State Indicator. This is a read-only status bit for RBUF and is not available 139 * in TBUF. The protocol machine automatically embeds the correct value of ESI into 140 * transmitted frames. ESI is only included in CAN FD frames and does not exist in CAN 141 * 2.0 frames. 142 */ 143 err_state_indicator : 1; 144 145 /*! The Data Length Code (DLC) in RBUF and TBUF defines the length of the payload(the 146 * number of payload bytes in a frame). 147 */ 148 uint32_t data_len_code : 4, 149 150 /*! Bit Rate Switch 151 * 0: nominal / slow bit rate for the complete frame. 152 * 1: switch to data / fast bit rate for the data payload and the CRC 153 * Only CAN FD frames can switch the bitrate. Therefore BRS is forced to 0 if EDL=0 154 */ 155 bit_rate_switch : 1, 156 157 /*! Extended Data Length 158 * 0: CAN 2.0 frame (up to 8 bytes payload) 159 * 1: CAN FD frame (up to 64 bytes payload) 160 */ 161 extended_data_len : 1, 162 163 /*! Remote Transmission Request 164 * 0: data frame 165 * 1: remote frame 166 * Only CAN 2.0 frames can be remote frames. There is no remote frame for CAN FD. 167 * Therefore RTR is forced to 0 if EDL=1 in the TBUF. 168 */ 169 remote_tx_req : 1, 170 171 /*! IDentifier Extension 172 * 0: Standard Format: ID(10:0) 173 * 1: Extended Format: ID(28:0) 174 */ 175 id_extension : 1, 176 177 /*! Reserved bit. 178 */ 179 reserved2 : 24; 180 } CAN_RxBufFormatTypeDef; 181 182 /** 183 * @brief CAN TX buffer format type definition 184 */ 185 typedef struct __CAN_TxBufFormatTypeDef { 186 /*! Standard/Extended iDentifier value 187 */ 188 uint32_t id : 29, 189 190 /*! Reserved bit. 191 */ 192 reserved1 : 3; 193 194 /*! The Data Length Code (DLC) in RBUF and TBUF defines the length of the payload(the 195 * number of payload bytes in a frame). 196 */ 197 uint32_t data_len_code : 4, 198 199 /*! Bit Rate Switch 200 * 0: nominal / slow bit rate for the complete frame. 201 * 1: switch to data / fast bit rate for the data payload and the CRC 202 * Only CAN FD frames can switch the bitrate. Therefore BRS is forced to 0 if EDL=0 203 */ 204 bit_rate_switch : 1, 205 206 /*! Extended Data Length 207 * 0: CAN 2.0 frame (up to 8 bytes payload) 208 * 1: CAN FD frame (up to 64 bytes payload) 209 */ 210 extended_data_len : 1, 211 212 /*! Remote Transmission Request 213 * 0: data frame 214 * 1: remote frame 215 * Only CAN 2.0 frames can be remote frames. There is no remote frame for CAN FD. 216 * Therefore RTR is forced to 0 if EDL=1 in the TBUF. 217 */ 218 remote_tx_req : 1, 219 220 /*! IDentifier Extension 221 * 0: Standard Format: ID(10:0) 222 * 1: Extended Format: ID(28:0) 223 */ 224 id_extension : 1, 225 226 /*! Reserved bit. 227 */ 228 reserved2 : 24; 229 } CAN_TxBufFormatTypeDef; 230 231 /** 232 * @brief CAN acceptance filter config type definition 233 */ 234 typedef struct __CAN_AcceptFilCfgTypeDef { 235 CAN_AcceptFilSlotETypeDef slot; /*!< acceptance filter slot number */ 236 uint32_t code_val; /*!< acceptance filter code value */ 237 uint32_t mask_val; /*!< acceptance filter mask value */ 238 } CAN_AcceptFilCfgTypeDef; 239 240 /** 241 * @brief CAN user config type definition 242 */ 243 typedef struct __CAN_UserCfgTypeDef { 244 uint32_t baudrate; /*!< baudrate */ 245 uint8_t bit_timing_seg1; /*!< bit timing segment1 */ 246 uint8_t bit_timing_seg2; /*!< bit timing degment2 */ 247 uint8_t bit_timing_sjw; /*!< bit timing synchronization jump width */ 248 CAN_RxAlmostFullLimitETypeDef rx_almost_full_limit; /*!< rx buffer almost full warning limit */ 249 CAN_ErrWarnLimitETypeDef err_limit; /*!< error warning limit */ 250 CAN_AcceptFilCfgTypeDef *accept_fil_cfg_ptr; /*!< acceptance filter config pointer */ 251 uint8_t accept_fil_cfg_num; /*!< acceptance filter config number */ 252 } CAN_UserCfgTypeDef; 253 254 /** 255 * @} 256 */ 257 258 /* Exported macro ------------------------------------------------------------*/ 259 /** @defgroup CAN_LL_Exported_Macros CAN LL Exported Macros 260 * @brief CAN LL Exported Macros 261 * @{ 262 */ 263 264 /** 265 * @brief CAN reset set 266 * @param __CAN__ Specifies CAN peripheral 267 * @return None 268 */ 269 #define __LL_CAN_Reset_Set(__CAN__) SET_BIT((__CAN__)->CFG_STAT, CAN_RESET_Msk) 270 271 /** 272 * @brief CAN reset clear 273 * @param __CAN__ Specifies CAN peripheral 274 * @return None 275 */ 276 #define __LL_CAN_Reset_Clr(__CAN__) CLEAR_BIT((__CAN__)->CFG_STAT, CAN_RESET_Msk) 277 278 /** 279 * @brief CAN reset status get 280 * @param __CAN__ Specifies CAN peripheral 281 * @retval 0 CAN reset has set 282 * @retval 1 CAN reset has clear 283 */ 284 #define __LL_CAN_ResetSta_Get(__CAN__) (READ_BIT((__CAN__)->CFG_STAT, CAN_RESET_Msk) >> CAN_RESET_Pos) 285 286 /** 287 * @brief CAN loop back mode external enable 288 * @param __CAN__ Specifies CAN peripheral 289 * @return None 290 */ 291 #define __LL_CAN_LoopBackModeExt_En(__CAN__) SET_BIT((__CAN__)->CFG_STAT, CAN_LOOP_BACK_EXTERNAL_Msk) 292 293 /** 294 * @brief CAN loop back mode external disable 295 * @param __CAN__ Specifies CAN peripheral 296 * @return None 297 */ 298 #define __LL_CAN_LoopBackModeExt_Dis(__CAN__) CLEAR_BIT((__CAN__)->CFG_STAT, CAN_LOOP_BACK_EXTERNAL_Msk) 299 300 /** 301 * @brief CAN loop back mode internal enable 302 * @param __CAN__ Specifies CAN peripheral 303 * @return None 304 */ 305 #define __LL_CAN_LoopBackModeInternal_En(__CAN__) SET_BIT((__CAN__)->CFG_STAT, CAN_LOOP_BACK_INTERNAL_Msk) 306 307 /** 308 * @brief CAN loop back mode internal disable 309 * @param __CAN__ Specifies CAN peripheral 310 * @return None 311 */ 312 #define __LL_CAN_LoopBackModeInternal_Dis(__CAN__) CLEAR_BIT((__CAN__)->CFG_STAT, CAN_LOOP_BACK_INTERNAL_Msk) 313 314 /** 315 * @brief CAN TX primary single shot enable 316 * @param __CAN__ Specifies CAN peripheral 317 * @return None 318 */ 319 #define __LL_CAN_TxPriSingleShot_En(__CAN__) SET_BIT((__CAN__)->CFG_STAT, CAN_TX_PRI_SINGLE_SHOT_Msk) 320 321 /** 322 * @brief CAN TX primary single shot disable 323 * @param __CAN__ Specifies CAN peripheral 324 * @return None 325 */ 326 #define __LL_CAN_TxPriSingleShot_Dis(__CAN__) CLEAR_BIT((__CAN__)->CFG_STAT, CAN_TX_PRI_SINGLE_SHOT_Msk) 327 328 /** 329 * @brief CAN TX secondary single shot enable 330 * @param __CAN__ Specifies CAN peripheral 331 * @return None 332 */ 333 #define __LL_CAN_TxSecSingleShot_En(__CAN__) SET_BIT((__CAN__)->CFG_STAT, CAN_TX_SEC_SINGLE_SHOT_Msk) 334 335 /** 336 * @brief CAN TX secondary single shot disable 337 * @param __CAN__ Specifies CAN peripheral 338 * @return None 339 */ 340 #define __LL_CAN_TxSecSingleShot_Dis(__CAN__) CLEAR_BIT((__CAN__)->CFG_STAT, CAN_TX_SEC_SINGLE_SHOT_Msk) 341 342 /** 343 * @brief Judge is RX active or not 344 * @param __CAN__ Specifies CAN peripheral 345 * @retval 0 Isn't RX active 346 * @retval 1 Is RX active 347 */ 348 #define __LL_CAN_IsRxActive(__CAN__) (READ_BIT((__CAN__)->CFG_STAT, CAN_RX_ACT_Msk) >> CAN_RX_ACT_Pos) 349 350 /** 351 * @brief Judge is TX active or not 352 * @param __CAN__ Specifies CAN peripheral 353 * @retval 0 Isn't TX active 354 * @retval 1 Is TX active 355 */ 356 #define __LL_CAN_IsTxActive(__CAN__) (READ_BIT((__CAN__)->CFG_STAT, CAN_TX_ACT_Msk) >> CAN_TX_ACT_Pos) 357 358 /** 359 * @brief Judge is bus off or not 360 * @param __CAN__ Specifies CAN peripheral 361 * @retval 0 Is bus on 362 * @retval 1 Is bus off 363 */ 364 #define __LL_CAN_IsBusOff(__CAN__) (READ_BIT((__CAN__)->CFG_STAT, CAN_BUS_OFF_Msk) >> CAN_BUS_OFF_Pos) 365 366 367 /** 368 * @brief TX buffer select PTB 369 * @param __CAN__ Specifies CAN peripheral 370 * @return None 371 */ 372 #define __LL_CAN_TxBufSel_PTB(__CAN__) CLEAR_BIT((__CAN__)->TCMD, CAN_TX_BUF_SEL_Msk) 373 374 /** 375 * @brief TX buffer select STB 376 * @param __CAN__ Specifies CAN peripheral 377 * @return None 378 */ 379 #define __LL_CAN_TxBufSel_STB(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_BUF_SEL_Msk) 380 381 /** 382 * @brief Listen only mode enable 383 * @param __CAN__ Specifies CAN peripheral 384 * @return None 385 */ 386 #define __LL_CAN_ListenOnlyMode_En(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_LISTEN_ONLY_Msk) 387 388 /** 389 * @brief Listen only mode disable 390 * @param __CAN__ Specifies CAN peripheral 391 * @return None 392 */ 393 #define __LL_CAN_ListenOnlyMode_Dis(__CAN__) CLEAR_BIT((__CAN__)->TCMD, CAN_LISTEN_ONLY_Msk) 394 395 /** 396 * @brief TX standby mode enalbe 397 * @param __CAN__ Specifies CAN peripheral 398 * @return None 399 */ 400 #define __LL_CAN_TxStandbyMode_En(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_STANDBY_Msk) 401 402 /** 403 * @brief TX standby mode disalbe 404 * @param __CAN__ Specifies CAN peripheral 405 * @return None 406 */ 407 #define __LL_CAN_TxStandbyMode_Dis(__CAN__) CLEAR_BIT((__CAN__)->TCMD, CAN_TX_STANDBY_Msk) 408 409 /** 410 * @brief TX primary enable set 411 * @param __CAN__ Specifies CAN peripheral 412 * @return None 413 */ 414 #define __LL_CAN_TxPriEn_Set(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_PRI_EN_Msk) 415 416 /** 417 * @brief TX primary enable get 418 * @param __CAN__ Specifies CAN peripheral 419 * @return TX primary enable status 420 */ 421 #define __LL_CAN_TxPriEn_Get(__CAN__) (READ_BIT((__CAN__)->TCMD, CAN_TX_PRI_EN_Msk) >> CAN_TX_PRI_EN_Pos) 422 423 /** 424 * @brief TX primary abort set 425 * @param __CAN__ Specifies CAN peripheral 426 * @return None 427 */ 428 #define __LL_CAN_TxPriAbort_Set(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_PRI_ABORT_Msk) 429 430 /** 431 * @brief TX secondary one set 432 * @param __CAN__ Specifies CAN peripheral 433 * @return None 434 */ 435 #define __LL_CAN_TxSecOne_Set(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_SEC_ONE_Msk) 436 437 /** 438 * @brief TX secondary one get 439 * @param __CAN__ Specifies CAN peripheral 440 * @return TX secondary one status 441 */ 442 #define __LL_CAN_TxSecOne_Get(__CAN__) (READ_BIT((__CAN__)->TCMD, CAN_TX_SEC_ONE_Msk) >> CAN_TX_SEC_ONE_Pos) 443 444 /** 445 * @brief TX secondary all set 446 * @param __CAN__ Specifies CAN peripheral 447 * @return None 448 */ 449 #define __LL_CAN_TxSecAll_Set(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_SEC_ALL_Msk) 450 451 /** 452 * @brief TX secondary all get 453 * @param __CAN__ Specifies CAN peripheral 454 * @return TX secondary send all status 455 */ 456 #define __LL_CAN_TxSecAll_Get(__CAN__) (READ_BIT((__CAN__)->TCMD, CAN_TX_SEC_ALL_Msk) >> CAN_TX_SEC_ALL_Pos) 457 458 /** 459 * @brief TX secondary abort set 460 * @param __CAN__ Specifies CAN peripheral 461 * @return None 462 */ 463 #define __LL_CAN_TxSecAbort_Set(__CAN__) SET_BIT((__CAN__)->TCMD, CAN_TX_SEC_ABORT_Msk) 464 465 466 /** 467 * @brief FD ISO enable 468 * @param __CAN__ Specifies CAN peripheral 469 * @return None 470 */ 471 #define __LL_CAN_FD_ISO_En(__CAN__) SET_BIT((__CAN__)->TCTRL, CAN_FD_ISO_Msk) 472 473 /** 474 * @brief FD ISO disable 475 * @param __CAN__ Specifies CAN peripheral 476 * @return None 477 */ 478 #define __LL_CAN_FD_ISO_Dis(__CAN__) CLEAR_BIT((__CAN__)->TCTRL, CAN_FD_ISO_Msk) 479 480 /** 481 * @brief TX secondary buffer next set 482 * @param __CAN__ Specifies CAN peripheral 483 * @return None 484 */ 485 #define __LL_CAN_TxSecNext_Set(__CAN__) SET_BIT((__CAN__)->TCTRL, CAN_TX_SEC_NEXT_Msk) 486 487 /** 488 * @brief TX secondary status get 489 * @param __CAN__ Specifies CAN peripheral 490 * @return Number of filled message secondary buffers 491 */ 492 #define __LL_CAN_TxSecSta_Get(__CAN__) (READ_BIT((__CAN__)->TCTRL, CAN_TX_SEC_STA_Msk) >> CAN_TX_SEC_STA_Pos) 493 494 495 /** 496 * @brief Judge is RX buffer overflow or not 497 * @param __CAN__ Specifies CAN peripheral 498 * @retval 0 Isn't RX buffer overflow 499 * @retval 1 Is RX buffer overflow 500 */ 501 #define __LL_CAN_IsRxBufOver(__CAN__) (READ_BIT((__CAN__)->RCTRL, CAN_RX_BUF_OVER_Msk) >> CAN_RX_BUF_OVER_Pos) 502 503 /** 504 * @brief RX buffer release 505 * @param __CAN__ Specifies CAN peripheral 506 * @return None 507 */ 508 #define __LL_CAN_RxBufRelease(__CAN__) SET_BIT((__CAN__)->RCTRL, CAN_RX_BUF_REL_Msk) 509 510 /** 511 * @brief RX buffer status get 512 * @param __CAN__ Specifies CAN peripheral 513 * @retval 0 RX buffer empty 514 * @retval 1 empty < RX buffer < almost full 515 * @retval 2 RX buffer >= almost full 516 * @retval 3 RX buffer full 517 */ 518 #define __LL_CAN_RxBufSta_Get(__CAN__) (READ_BIT((__CAN__)->RCTRL, CAN_RX_BUF_STA_Msk) >> CAN_RX_BUF_STA_Pos) 519 520 521 /** 522 * @brief RX interrupt enable 523 * @param __CAN__ Specifies CAN peripheral 524 * @return None 525 */ 526 #define __LL_CAN_Rx_INT_EN(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_RX_INT_EN_Msk) 527 528 /** 529 * @brief RX interrupt disable 530 * @param __CAN__ Specifies CAN peripheral 531 * @return None 532 */ 533 #define __LL_CAN_Rx_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_RX_INT_EN_Msk) 534 535 /** 536 * @brief RX buffer overrun interrupt enable 537 * @param __CAN__ Specifies CAN peripheral 538 * @return None 539 */ 540 #define __LL_CAN_RxBufOver_INT_EN(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_RX_BUF_OVER_INT_EN_Msk) 541 542 /** 543 * @brief RX buffer overrun interrupt disable 544 * @param __CAN__ Specifies CAN peripheral 545 * @return None 546 */ 547 #define __LL_CAN_RxBufOver_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_RX_BUF_OVER_INT_EN_Msk) 548 549 /** 550 * @brief RX buffer full interrupt enable 551 * @param __CAN__ Specifies CAN peripheral 552 * @return None 553 */ 554 #define __LL_CAN_RxBufFull_INT_EN(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_RX_BUF_FULL_INT_EN_Msk) 555 556 /** 557 * @brief RX buffer full interrupt disable 558 * @param __CAN__ Specifies CAN peripheral 559 * @return None 560 */ 561 #define __LL_CAN_RxBufFull_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_RX_BUF_FULL_INT_EN_Msk) 562 563 /** 564 * @brief RX buffer almost full interrupt enable 565 * @param __CAN__ Specifies CAN peripheral 566 * @return None 567 */ 568 #define __LL_CAN_RxBufAlmostFull_INT_EN(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_RX_BUF_ALMOST_FULL_INT_EN_Msk) 569 570 /** 571 * @brief RX buffer almost full interrupt disable 572 * @param __CAN__ Specifies CAN peripheral 573 * @return None 574 */ 575 #define __LL_CAN_RxBufAlmostFull_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_RX_BUF_ALMOST_FULL_INT_EN_Msk) 576 577 /** 578 * @brief TX primary interrupt enable 579 * @param __CAN__ Specifies CAN peripheral 580 * @return None 581 */ 582 #define __LL_CAN_TxPri_INT_En(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_TX_PRI_INT_EN_Msk) 583 584 /** 585 * @brief TX primary interrupt disable 586 * @param __CAN__ Specifies CAN peripheral 587 * @return None 588 */ 589 #define __LL_CAN_TxPri_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_TX_PRI_INT_EN_Msk) 590 591 /** 592 * @brief TX secondary interrupt enable 593 * @param __CAN__ Specifies CAN peripheral 594 * @return None 595 */ 596 #define __LL_CAN_TxSec_INT_En(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_TX_SEC_INT_EN_Msk) 597 598 /** 599 * @brief TX secondary interrupt disable 600 * @param __CAN__ Specifies CAN peripheral 601 * @return None 602 */ 603 #define __LL_CAN_TxSec_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_TX_SEC_INT_EN_Msk) 604 605 /** 606 * @brief Error interrupt enalbe 607 * @param __CAN__ Specifies CAN peripheral 608 * @return None 609 */ 610 #define __LL_CAN_Err_INT_En(__CAN__) SET_BIT((__CAN__)->RTIE, CAN_ERR_INT_EN_Msk) 611 612 /** 613 * @brief Error interrupt disalbe 614 * @param __CAN__ Specifies CAN peripheral 615 * @return None 616 */ 617 #define __LL_CAN_Err_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->RTIE, CAN_ERR_INT_EN_Msk) 618 619 /** 620 * @brief Judge is TX secondary buffer full or not 621 * @param __CAN__ Specifies CAN peripheral 622 * @retval 0 Isn't TX secondary buffer full 623 * @retval 1 Is TX secondary buffer full 624 */ 625 #define __LL_CAN_IsTxSecBufFull(__CAN__) (READ_BIT((__CAN__)->RTIE, CAN_TX_SEC_BUF_FULL_Msk) >> CAN_TX_SEC_BUF_FULL_Pos) 626 627 628 /** 629 * @brief Interrupt status get 630 * @param __CAN__ Specifies CAN peripheral 631 * @return Interrupt status 632 */ 633 #define __LL_CAN_IntSta_Get(__CAN__) READ_REG((__CAN__)->RTIF) 634 635 636 /** 637 * @brief Judge is error warning limit reached or not 638 * @param __CAN__ Specifies CAN peripheral 639 * @retval 0 Isn't error warning limit reached 640 * @retval 1 Is error warning limit reached 641 */ 642 #define __LL_CAN_IsErrWarnLimitReached(__CAN__) \ 643 (READ_BIT((__CAN__)ERRINT, CAN_ERR_WARN_LIMIT_REACHED_Msk) >> CAN_ERR_WARN_LIMIT_REACHED_Pos) 644 645 /** 646 * @brief Judge is error passive mode active or not 647 * @param __CAN__ Specifies CAN peripheral 648 * @retval 0 Error passive mode isn't active 649 * @retval 1 Error passive mode is active 650 */ 651 #define __LL_CAN_IsErrPassiveModeActive(__CAN__) (READ_BIT((__CAN__)->ERRINT, CAN_ERR_PASS_ACT_Msk) >> CAN_ERR_PASS_ACT_Pos) 652 653 /** 654 * @brief Error passive interrupt enable 655 * @param __CAN__ Specifies CAN peripheral 656 * @return None 657 */ 658 #define __LL_CAN_ErrPassive_INT_En(__CAN__) SET_BIT((__CAN__)->ERRINT, CAN_ERR_PASS_INT_EN_Msk) 659 660 /** 661 * @brief Error passive interrupt disable 662 * @param __CAN__ Specifies CAN peripheral 663 * @return None 664 */ 665 #define __LL_CAN_ErrPassive_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->ERRINT, CAN_ERR_PASS_INT_EN_Msk) 666 667 /** 668 * @brief Arbitration lost interrupt enable 669 * @param __CAN__ Specifies CAN peripheral 670 * @return None 671 */ 672 #define __LL_CAN_ArbLost_INT_En(__CAN__) SET_BIT((__CAN__)->ERRINT, CAN_ARB_LOST_INT_EN_Msk) 673 674 /** 675 * @brief Arbitration lost interrupt disable 676 * @param __CAN__ Specifies CAN peripheral 677 * @return None 678 */ 679 #define __LL_CAN_ArbLost_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->ERRINT, CAN_ARB_LOST_INT_EN_Msk) 680 681 /** 682 * @brief Bus error interrupt enable 683 * @param __CAN__ Specifies CAN peripheral 684 * @return None 685 */ 686 #define __LL_CAN_BusErr_INT_En(__CAN__) SET_BIT((__CAN__)->ERRINT, CAN_BUS_ERR_INT_EN_Msk) 687 688 /** 689 * @brief Bus error interrupt disable 690 * @param __CAN__ Specifies CAN peripheral 691 * @return None 692 */ 693 #define __LL_CAN_BusErr_INT_Dis(__CAN__) CLEAR_BIT((__CAN__)->ERRINT, CAN_BUS_ERR_INT_EN_Msk) 694 695 /** 696 * @brief Error interrupt status get 697 * @param __CAN__ Specifies CAN peripheral 698 * @return Error interrupt status 699 */ 700 #define __LL_CAN_ErrIntSta_Get(__CAN__) \ 701 (READ_BIT((__CAN__)->ERRINT, (CAN_ERR_PASS_INT_STA_Msk | CAN_ARB_LOST_INT_STA_Msk | CAN_BUS_ERR_INT_STA_Msk))) 702 703 704 /** 705 * @brief RX buffer almost full warning limit set 706 * @param __CAN__ Specifies CAN peripheral 707 * @param val set value 708 * @return None 709 */ 710 #define __LL_CAN_RxBufAlmostFullLimit_Set(__CAN__,val) \ 711 MODIFY_REG((__CAN__)->LIMIT, CAN_RX_BUF_ALMOST_FULL_LIMIT_Msk, ((val & 0xfUL) << CAN_RX_BUF_ALMOST_FULL_LIMIT_Pos)) 712 713 /** 714 * @brief Error warning limit set 715 * @param __CAN__ Specifies CAN peripheral 716 * @param val set value 717 * @return None 718 */ 719 #define __LL_CAN_ErrWarnLimit_Set(__CAN__,val) \ 720 MODIFY_REG((__CAN__)->LIMIT, CAN_ERR_WARN_LIMIT_Msk, ((val & 0xfUL) << CAN_ERR_WARN_LIMIT_Pos)) 721 722 723 /** 724 * @brief Fast speed synchronization jump width set 725 * @param __CAN__ Specifies CAN peripheral 726 * @param val set value 727 * @return None 728 */ 729 #define __LL_CAN_FS_SyncJumpWidth_Set(__CAN__,val) \ 730 MODIFY_REG((__CAN__)->BITTIME0, CAN_FS_SYNC_JUMP_WIDTH_Msk, ((val & 0x3UL) << CAN_FS_SYNC_JUMP_WIDTH_Pos)) 731 732 /** 733 * @brief Slow speed bit timing segment1 set 734 * @param __CAN__ Specifies CAN peripheral 735 * @param val set value 736 * @return None 737 */ 738 #define __LL_CAN_SS_BitTimingSeg1_Set(__CAN__,val) \ 739 MODIFY_REG((__CAN__)->BITTIME0, CAN_SS_SEG1_Msk, ((val & 0x3fUL) << CAN_SS_SEG1_Pos)) 740 741 742 /** 743 * @brief Fast speed bit timing segment2 set 744 * @param __CAN__ Specifies CAN peripheral 745 * @param val set value 746 * @return None 747 */ 748 #define __LL_CAN_FS_BitTimingSeg2_Set(__CAN__,val) \ 749 MODIFY_REG((__CAN__)->BITTIME1, CAN_FS_SEG2_Msk, ((val & 0x7UL) << CAN_FS_SEG2_Pos)) 750 751 /** 752 * @brief Slow speed bit timing segment2 set 753 * @param __CAN__ Specifies CAN peripheral 754 * @param val set value 755 * @return None 756 */ 757 #define __LL_CAN_SS_BitTimingSeg2_Set(__CAN__,val) \ 758 MODIFY_REG((__CAN__)->BITTIME1, CAN_SS_SEG2_Msk, ((val & 0x1fUL) << CAN_SS_SEG2_Pos)) 759 760 761 /** 762 * @brief Fast speed bit timing segment1 set 763 * @param __CAN__ Specifies CAN peripheral 764 * @param val set value 765 * @return None 766 */ 767 #define __LL_CAN_FS_BitTimingSeg1_Set(__CAN__,val) \ 768 MODIFY_REG((__CAN__)->BITTIME2, CAN_FS_SEG1_Msk, ((val & 0xfUL) << CAN_FS_SEG1_Pos)) 769 770 /** 771 * @brief Slow speed synchronization jump width set 772 * @param __CAN__ Specifies CAN peripheral 773 * @param val set value 774 * @return None 775 */ 776 #define __LL_CAN_SS_SyncJumpWidth_Set(__CAN__,val) \ 777 MODIFY_REG((__CAN__)->BITTIME2, CAN_SS_SYNC_JUMP_WIDTH_Msk, ((val & 0xfUL) << CAN_SS_SYNC_JUMP_WIDTH_Pos)) 778 779 780 /** 781 * @brief Slow speed prescaler set 782 * @param __CAN__ Specifies CAN peripheral 783 * @param val set value 784 * @return None 785 */ 786 #define __LL_CAN_SS_Prescaler_Set(__CAN__,val) WRITE_REG((__CAN__)->S_PRESC, ((val) & CAN_SS_PRESCALER_Msk)) 787 788 789 /** 790 * @brief Fast speed prescaler set 791 * @param __CAN__ Specifies CAN peripheral 792 * @param val set value 793 * @return None 794 */ 795 #define __LL_CAN_FS_Prescaler_Set(__CAN__,val) WRITE_REG((__CAN__)->F_PRESC, ((val) & CAN_FS_PRESCALER_Msk)) 796 797 798 /** 799 * @brief TX delay compensation enable 800 * @param __CAN__ Specifies CAN peripheral 801 * @return None 802 */ 803 #define __LL_CAN_TxDelayComp_En(__CAN__) SET_BIT((__CAN__)->TDC, CAN_TX_DELAY_COMP_EN_Msk) 804 805 /** 806 * @brief TX delay compensation disable 807 * @param __CAN__ Specifies CAN peripheral 808 * @return None 809 */ 810 #define __LL_CAN_TxDelayComp_Dis(__CAN__) CLEAR_BIT((__CAN__)->TDC, CAN_TX_DELAY_COMP_EN_Msk) 811 812 /** 813 * @brief Secondary sample point offset set 814 * @param __CAN__ Specifies CAN peripheral 815 * @param val set value 816 * @return None 817 */ 818 #define __LL_CAN_SecSamplePointOffset_Set(__CAN__,val) \ 819 MODIFY_REG((__CAN__)->TDC, CAN_SEC_SAMPLE_POINT_OFFSET_Msk, ((val & 0x1f) << CAN_SEC_SAMPLE_POINT_OFFSET_Pos)) 820 821 822 /** 823 * @brief Error code get 824 * @param __CAN__ Specifies CAN peripheral 825 * @retval 0 no error 826 * @retval 1 bit error 827 * @retval 2 form error 828 * @retval 3 stuff error 829 * @retval 4 acknowledgement error 830 * @retval 5 CRC error 831 * @retval 6 other error 832 * @retval 7 not used 833 */ 834 #define __LL_CAN_ErrCode_Get(__CAN__) (READ_BIT((__CAN__)->EALCAP, CAN_ERR_CODE_Msk) >> CAN_ERR_CODE_Pos) 835 836 /** 837 * @brief Arbitration lost capture get 838 * @param __CAN__ Specifies CAN peripheral 839 * @return bit position in the frame where the arbitration has been lost 840 */ 841 #define __LL_CAN_ArbLostCapture_Get(__CAN__) (READ_BIT((__CAN__)->EALCAP, CAN_ARB_LOST_CAPTURE_Msk) >> CAN_ARB_LOST_CAPTURE_Pos) 842 843 844 /** 845 * @brief RX error count get 846 * @param __CAN__ Specifies CAN peripheral 847 * @return RX error count 848 */ 849 #define __LL_CAN_RxErrCnt_Get(__CAN__) READ_REG((__CAN__)->RECNT) 850 851 852 /** 853 * @brief TX error count get 854 * @param __CAN__ Specifies CAN peripheral 855 * @return TX error count 856 */ 857 #define __LL_CAN_TxErrCnt_Get(__CAN__) READ_REG((__CAN__)->TECNT) 858 859 860 /** 861 * @brief Acceptance filter content select mask 862 * @param __CAN__ Specifies CAN peripheral 863 * @return None 864 */ 865 #define __LL_CAN_AcceptFilContentSel_Mask(__CAN__) SET_BIT((__CAN__)->ACFCTRL, CAN_ACPT_FIL_CONTENT_SEL_Msk) 866 867 /** 868 * @brief Acceptance filter content select code 869 * @param __CAN__ Specifies CAN peripheral 870 * @return None 871 */ 872 #define __LL_CAN_AcceptFilContentSel_Code(__CAN__) CLEAR_BIT((__CAN__)->ACFCTRL, CAN_ACPT_FIL_CONTENT_SEL_Msk) 873 874 /** 875 * @brief Acceptance filter address set 876 * @param __CAN__ Specifies CAN peripheral 877 * @param val set value 878 * @return None 879 */ 880 #define __LL_CAN_AcceptFilAddr_Set(__CAN__, val) \ 881 MODIFY_REG((__CAN__)->ACFCTRL, CAN_ACPT_FIL_ADDR_Msk, ((val & 0xfUL) << CAN_ACPT_FIL_ADDR_Pos)) 882 883 884 /** 885 * @brief Acceptance filter enable 886 * @param __CAN__ Specifies CAN peripheral 887 * @param fil_num Acceptance filter slot number 888 * @note fil_num value range [0, 15] 889 * @return None 890 */ 891 #define __LL_CAN_AcceptFil_En(__CAN__, fil_num) \ 892 do { \ 893 if(fil_num < 8) { \ 894 MODIFY_REG((__CAN__)->ACF_EN_0, (0x1UL<<fil_num), (0x1UL<<fil_num)); \ 895 } else if(fil_num < 16) { \ 896 MODIFY_REG((__CAN__)->ACF_EN_1, (0x1UL<<(fil_num-8)), (0x1UL<<(fil_num-8))); \ 897 } \ 898 } while(0) 899 900 901 /** 902 * @brief Acceptance mask IDE bit check enable 903 * @param __CAN__ Specifies CAN peripheral 904 * @return None 905 */ 906 #define __LL_CAN_AcceptFilMaskIDE_En(__CAN__) SET_BIT((__CAN__)->ACF, CAN_ACPT_MASK_IDE_CHK_EN_Msk) 907 908 /** 909 * @brief Acceptance mask IDE bit check disable 910 * @param __CAN__ Specifies CAN peripheral 911 * @return None 912 */ 913 #define __LL_CAN_AcceptFilMaskIDE_Dis(__CAN__) CLEAR_BIT((__CAN__)->ACF, CAN_ACPT_MASK_IDE_CHK_EN_Msk) 914 915 /** 916 * @brief Acceptance filter accepts only extended frames 917 * @param __CAN__ Specifies CAN peripheral 918 * @return None 919 */ 920 #define __LL_CAN_AcceptFilMaskIDESel_Ext(__CAN__) SET_BIT((__CAN__)->ACF, CAN_ACPT_MASK_IDE_BIT_VAL_Msk) 921 922 /** 923 * @brief Acceptance filter accepts only standard frames 924 * @param __CAN__ Specifies CAN peripheral 925 * @return None 926 */ 927 #define __LL_CAN_AcceptFilMaskIDESel_Std(__CAN__) CLEAR_BIT((__CAN__)->ACF, CAN_ACPT_MASK_IDE_BIT_VAL_Msk) 928 929 /** 930 * @brief Acceptance filter code or mask set 931 * @param __CAN__ Specifies CAN peripheral 932 * @param val set value 933 * @return None 934 */ 935 #define __LL_CAN_AcceptFilCodeOrMaskVal_Set(__CAN__, val) \ 936 MODIFY_REG((__CAN__)->ACF, CAN_ACPT_CODE_OR_MASK_Msk, ((val & 0x1fffffffUL) << CAN_ACPT_CODE_OR_MASK_Pos)) 937 938 939 940 /** 941 * @brief CAN frame ID format to 11 bits 942 */ 943 #define __LL_CAN_FrameIDFormat_11Bits(n) ((n) & 0x7FFUL) 944 945 /** 946 * @brief CAN frame ID format to 29 bits 947 */ 948 #define __LL_CAN_FrameIDFormat_29Bits(n) ((n) & 0x1FFFFFFFUL) 949 950 /** 951 * @} 952 */ 953 954 /* Exported functions --------------------------------------------------------*/ 955 /** @addtogroup CAN_LL_Exported_Functions 956 * @{ 957 */ 958 959 /** @addtogroup CAN_LL_Exported_Functions_Group1 960 * @{ 961 */ 962 LL_StatusETypeDef LL_CAN_Init(CAN_TypeDef *Instance, CAN_UserCfgTypeDef *user_cfg); 963 LL_StatusETypeDef LL_CAN_DeInit(CAN_TypeDef *Instance); 964 void LL_CAN_MspInit(CAN_TypeDef *Instance); 965 void LL_CAN_MspDeInit(CAN_TypeDef *Instance); 966 /** 967 * @} 968 */ 969 970 /** @addtogroup CAN_LL_Exported_Functions_Group2 971 * @{ 972 */ 973 uint32_t LL_CAN_SendStandard_PTB(CAN_TypeDef *Instance, CAN_TxBufFormatTypeDef *buf_fmt, uint32_t *buf); 974 uint32_t LL_CAN_SendStandard_STB(CAN_TypeDef *Instance, CAN_TxBufFormatTypeDef *buf_fmt, uint32_t *buf); 975 uint32_t LL_CAN_SendStandard_STB_Multi(CAN_TypeDef *Instance, CAN_TxBufFormatTypeDef *buf_fmt, 976 uint32_t *buf, uint32_t send_cnt); 977 /** 978 * @} 979 */ 980 981 /** @addtogroup CAN_LL_Exported_Functions_Interrupt 982 * @{ 983 */ 984 void LL_CAN_IRQHandler(CAN_TypeDef *Instance); 985 986 void LL_CAN_RxCallback(CAN_TypeDef *Instance); 987 void LL_CAN_RxOverCallback(CAN_TypeDef *Instance); 988 void LL_CAN_RxFullCallback(CAN_TypeDef *Instance); 989 void LL_CAN_RxAlmostFullCallback(CAN_TypeDef *Instance); 990 void LL_CAN_TxPriCallback(CAN_TypeDef *Instance); 991 void LL_CAN_TxSecCallback(CAN_TypeDef *Instance); 992 void LL_CAN_ErrCallback(CAN_TypeDef *Instance); 993 void LL_CAN_AbortCallback(CAN_TypeDef *Instance); 994 995 void LL_CAN_ErrPassiveCallback(CAN_TypeDef *Instance); 996 void LL_CAN_ArbLostCallback(CAN_TypeDef *Instance); 997 void LL_CAN_BusErrCallback(CAN_TypeDef *Instance); 998 /** 999 * @} 1000 */ 1001 1002 /** 1003 * @} 1004 */ 1005 1006 /* Private constants ---------------------------------------------------------*/ 1007 /* Private variables ---------------------------------------------------------*/ 1008 /* Private types -------------------------------------------------------------*/ 1009 /* Private macros ------------------------------------------------------------*/ 1010 /* Private functions ---------------------------------------------------------*/ 1011 1012 /** 1013 * @} 1014 */ 1015 1016 /** 1017 * @} 1018 */ 1019 1020 1021 #ifdef __cplusplus 1022 } 1023 #endif /* __cplusplus */ 1024 1025 1026 #endif /* _TAE32F53XX_LL_CAN_H_ */ 1027 1028 1029 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/ 1030 1031