Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more
stm32f30x_can.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f30x_can.h 00004 * @author MCD Application Team 00005 * @version V1.2.3 00006 * @date 10-July-2015 00007 * @brief This file contains all the functions prototypes for the CAN firmware 00008 * library. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Define to prevent recursive inclusion -------------------------------------*/ 00030 #ifndef __STM32F30x_CAN_H 00031 #define __STM32F30x_CAN_H 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f30x.h" 00039 00040 /** @addtogroup STM32F30x_StdPeriph_Driver 00041 * @{ 00042 */ 00043 00044 /** @addtogroup CAN 00045 * @{ 00046 */ 00047 00048 /* Exported types ------------------------------------------------------------*/ 00049 00050 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1)) 00051 00052 /** 00053 * @brief CAN init structure definition 00054 */ 00055 typedef struct 00056 { 00057 uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum. 00058 It ranges from 1 to 1024. */ 00059 00060 uint8_t CAN_Mode; /*!< Specifies the CAN operating mode. 00061 This parameter can be a value of @ref CAN_operating_mode */ 00062 00063 uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta 00064 the CAN hardware is allowed to lengthen or 00065 shorten a bit to perform resynchronization. 00066 This parameter can be a value of @ref CAN_synchronisation_jump_width */ 00067 00068 uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit 00069 Segment 1. This parameter can be a value of 00070 @ref CAN_time_quantum_in_bit_segment_1 */ 00071 00072 uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit Segment 2. 00073 This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */ 00074 00075 FunctionalState CAN_TTCM; /*!< Enable or disable the time triggered communication mode. 00076 This parameter can be set either to ENABLE or DISABLE. */ 00077 00078 FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off management. 00079 This parameter can be set either to ENABLE or DISABLE. */ 00080 00081 FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode. 00082 This parameter can be set either to ENABLE or DISABLE. */ 00083 00084 FunctionalState CAN_NART; /*!< Enable or disable the non-automatic retransmission mode. 00085 This parameter can be set either to ENABLE or DISABLE. */ 00086 00087 FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode. 00088 This parameter can be set either to ENABLE or DISABLE. */ 00089 00090 FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority. 00091 This parameter can be set either to ENABLE or DISABLE. */ 00092 } CAN_InitTypeDef; 00093 00094 /** 00095 * @brief CAN filter init structure definition 00096 */ 00097 typedef struct 00098 { 00099 uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit 00100 configuration, first one for a 16-bit configuration). 00101 This parameter can be a value between 0x0000 and 0xFFFF */ 00102 00103 uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit 00104 configuration, second one for a 16-bit configuration). 00105 This parameter can be a value between 0x0000 and 0xFFFF */ 00106 00107 uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number, 00108 according to the mode (MSBs for a 32-bit configuration, 00109 first one for a 16-bit configuration). 00110 This parameter can be a value between 0x0000 and 0xFFFF */ 00111 00112 uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number, 00113 according to the mode (LSBs for a 32-bit configuration, 00114 second one for a 16-bit configuration). 00115 This parameter can be a value between 0x0000 and 0xFFFF */ 00116 00117 uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter. 00118 This parameter can be a value of @ref CAN_filter_FIFO */ 00119 00120 uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */ 00121 00122 uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized. 00123 This parameter can be a value of @ref CAN_filter_mode */ 00124 00125 uint8_t CAN_FilterScale; /*!< Specifies the filter scale. 00126 This parameter can be a value of @ref CAN_filter_scale */ 00127 00128 FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter. 00129 This parameter can be set either to ENABLE or DISABLE. */ 00130 } CAN_FilterInitTypeDef; 00131 00132 /** 00133 * @brief CAN Tx message structure definition 00134 */ 00135 typedef struct 00136 { 00137 uint32_t StdId; /*!< Specifies the standard identifier. 00138 This parameter can be a value between 0 to 0x7FF. */ 00139 00140 uint32_t ExtId; /*!< Specifies the extended identifier. 00141 This parameter can be a value between 0 to 0x1FFFFFFF. */ 00142 00143 uint8_t IDE; /*!< Specifies the type of identifier for the message that 00144 will be transmitted. This parameter can be a value 00145 of @ref CAN_identifier_type */ 00146 00147 uint8_t RTR; /*!< Specifies the type of frame for the message that will 00148 be transmitted. This parameter can be a value of 00149 @ref CAN_remote_transmission_request */ 00150 00151 uint8_t DLC; /*!< Specifies the length of the frame that will be 00152 transmitted. This parameter can be a value between 00153 0 to 8 */ 00154 00155 uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0 00156 to 0xFF. */ 00157 } CanTxMsg; 00158 00159 /** 00160 * @brief CAN Rx message structure definition 00161 */ 00162 typedef struct 00163 { 00164 uint32_t StdId; /*!< Specifies the standard identifier. 00165 This parameter can be a value between 0 to 0x7FF. */ 00166 00167 uint32_t ExtId; /*!< Specifies the extended identifier. 00168 This parameter can be a value between 0 to 0x1FFFFFFF. */ 00169 00170 uint8_t IDE; /*!< Specifies the type of identifier for the message that 00171 will be received. This parameter can be a value of 00172 @ref CAN_identifier_type */ 00173 00174 uint8_t RTR; /*!< Specifies the type of frame for the received message. 00175 This parameter can be a value of 00176 @ref CAN_remote_transmission_request */ 00177 00178 uint8_t DLC; /*!< Specifies the length of the frame that will be received. 00179 This parameter can be a value between 0 to 8 */ 00180 00181 uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to 00182 0xFF. */ 00183 00184 uint8_t FMI; /*!< Specifies the index of the filter the message stored in 00185 the mailbox passes through. This parameter can be a 00186 value between 0 to 0xFF */ 00187 } CanRxMsg; 00188 00189 /* Exported constants --------------------------------------------------------*/ 00190 00191 /** @defgroup CAN_Exported_Constants 00192 * @{ 00193 */ 00194 00195 /** @defgroup CAN_InitStatus 00196 * @{ 00197 */ 00198 00199 #define CAN_InitStatus_Failed ((uint8_t)0x00) /*!< CAN initialization failed */ 00200 #define CAN_InitStatus_Success ((uint8_t)0x01) /*!< CAN initialization OK */ 00201 00202 00203 /* Legacy defines */ 00204 #define CANINITFAILED CAN_InitStatus_Failed 00205 #define CANINITOK CAN_InitStatus_Success 00206 /** 00207 * @} 00208 */ 00209 00210 /** @defgroup CAN_operating_mode 00211 * @{ 00212 */ 00213 00214 #define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */ 00215 #define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */ 00216 #define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */ 00217 #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */ 00218 00219 #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \ 00220 ((MODE) == CAN_Mode_LoopBack)|| \ 00221 ((MODE) == CAN_Mode_Silent) || \ 00222 ((MODE) == CAN_Mode_Silent_LoopBack)) 00223 /** 00224 * @} 00225 */ 00226 00227 00228 /** 00229 * @defgroup CAN_operating_mode 00230 * @{ 00231 */ 00232 #define CAN_OperatingMode_Initialization ((uint8_t)0x00) /*!< Initialization mode */ 00233 #define CAN_OperatingMode_Normal ((uint8_t)0x01) /*!< Normal mode */ 00234 #define CAN_OperatingMode_Sleep ((uint8_t)0x02) /*!< sleep mode */ 00235 00236 00237 #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\ 00238 ((MODE) == CAN_OperatingMode_Normal)|| \ 00239 ((MODE) == CAN_OperatingMode_Sleep)) 00240 /** 00241 * @} 00242 */ 00243 00244 /** 00245 * @defgroup CAN_operating_mode_status 00246 * @{ 00247 */ 00248 00249 #define CAN_ModeStatus_Failed ((uint8_t)0x00) /*!< CAN entering the specific mode failed */ 00250 #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed) /*!< CAN entering the specific mode Succeed */ 00251 /** 00252 * @} 00253 */ 00254 00255 /** @defgroup CAN_synchronisation_jump_width 00256 * @{ 00257 */ 00258 #define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */ 00259 #define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */ 00260 #define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */ 00261 #define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */ 00262 00263 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \ 00264 ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq)) 00265 /** 00266 * @} 00267 */ 00268 00269 /** @defgroup CAN_time_quantum_in_bit_segment_1 00270 * @{ 00271 */ 00272 #define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */ 00273 #define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */ 00274 #define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */ 00275 #define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */ 00276 #define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */ 00277 #define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */ 00278 #define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */ 00279 #define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */ 00280 #define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */ 00281 #define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */ 00282 #define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */ 00283 #define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */ 00284 #define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */ 00285 #define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */ 00286 #define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */ 00287 #define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */ 00288 00289 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq) 00290 /** 00291 * @} 00292 */ 00293 00294 /** @defgroup CAN_time_quantum_in_bit_segment_2 00295 * @{ 00296 */ 00297 #define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */ 00298 #define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */ 00299 #define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */ 00300 #define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */ 00301 #define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */ 00302 #define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */ 00303 #define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */ 00304 #define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */ 00305 00306 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq) 00307 /** 00308 * @} 00309 */ 00310 00311 /** @defgroup CAN_clock_prescaler 00312 * @{ 00313 */ 00314 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024)) 00315 /** 00316 * @} 00317 */ 00318 00319 /** @defgroup CAN_filter_number 00320 * @{ 00321 */ 00322 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27) 00323 /** 00324 * @} 00325 */ 00326 00327 /** @defgroup CAN_filter_mode 00328 * @{ 00329 */ 00330 #define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */ 00331 #define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */ 00332 00333 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \ 00334 ((MODE) == CAN_FilterMode_IdList)) 00335 /** 00336 * @} 00337 */ 00338 00339 /** @defgroup CAN_filter_scale 00340 * @{ 00341 */ 00342 #define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */ 00343 #define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */ 00344 00345 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \ 00346 ((SCALE) == CAN_FilterScale_32bit)) 00347 /** 00348 * @} 00349 */ 00350 00351 /** @defgroup CAN_filter_FIFO 00352 * @{ 00353 */ 00354 #define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */ 00355 #define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */ 00356 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \ 00357 ((FIFO) == CAN_FilterFIFO1)) 00358 00359 /* Legacy defines */ 00360 #define CAN_FilterFIFO0 CAN_Filter_FIFO0 00361 #define CAN_FilterFIFO1 CAN_Filter_FIFO1 00362 /** 00363 * @} 00364 */ 00365 00366 /** @defgroup CAN_Start_bank_filter_for_slave_CAN 00367 * @{ 00368 */ 00369 #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27)) 00370 /** 00371 * @} 00372 */ 00373 00374 /** @defgroup CAN_Tx 00375 * @{ 00376 */ 00377 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02)) 00378 #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF)) 00379 #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF)) 00380 #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08)) 00381 /** 00382 * @} 00383 */ 00384 00385 /** @defgroup CAN_identifier_type 00386 * @{ 00387 */ 00388 #define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */ 00389 #define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */ 00390 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \ 00391 ((IDTYPE) == CAN_Id_Extended)) 00392 00393 /* Legacy defines */ 00394 #define CAN_ID_STD CAN_Id_Standard 00395 #define CAN_ID_EXT CAN_Id_Extended 00396 /** 00397 * @} 00398 */ 00399 00400 /** @defgroup CAN_remote_transmission_request 00401 * @{ 00402 */ 00403 #define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */ 00404 #define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */ 00405 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote)) 00406 00407 /* Legacy defines */ 00408 #define CAN_RTR_DATA CAN_RTR_Data 00409 #define CAN_RTR_REMOTE CAN_RTR_Remote 00410 /** 00411 * @} 00412 */ 00413 00414 /** @defgroup CAN_transmit_constants 00415 * @{ 00416 */ 00417 #define CAN_TxStatus_Failed ((uint8_t)0x00)/*!< CAN transmission failed */ 00418 #define CAN_TxStatus_Ok ((uint8_t)0x01) /*!< CAN transmission succeeded */ 00419 #define CAN_TxStatus_Pending ((uint8_t)0x02) /*!< CAN transmission pending */ 00420 #define CAN_TxStatus_NoMailBox ((uint8_t)0x04) /*!< CAN cell did not provide 00421 an empty mailbox */ 00422 /* Legacy defines */ 00423 #define CANTXFAILED CAN_TxStatus_Failed 00424 #define CANTXOK CAN_TxStatus_Ok 00425 #define CANTXPENDING CAN_TxStatus_Pending 00426 #define CAN_NO_MB CAN_TxStatus_NoMailBox 00427 /** 00428 * @} 00429 */ 00430 00431 /** @defgroup CAN_receive_FIFO_number_constants 00432 * @{ 00433 */ 00434 #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */ 00435 #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */ 00436 00437 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1)) 00438 /** 00439 * @} 00440 */ 00441 00442 /** @defgroup CAN_sleep_constants 00443 * @{ 00444 */ 00445 #define CAN_Sleep_Failed ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */ 00446 #define CAN_Sleep_Ok ((uint8_t)0x01) /*!< CAN entered the sleep mode */ 00447 00448 /* Legacy defines */ 00449 #define CANSLEEPFAILED CAN_Sleep_Failed 00450 #define CANSLEEPOK CAN_Sleep_Ok 00451 /** 00452 * @} 00453 */ 00454 00455 /** @defgroup CAN_wake_up_constants 00456 * @{ 00457 */ 00458 #define CAN_WakeUp_Failed ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */ 00459 #define CAN_WakeUp_Ok ((uint8_t)0x01) /*!< CAN leaved the sleep mode */ 00460 00461 /* Legacy defines */ 00462 #define CANWAKEUPFAILED CAN_WakeUp_Failed 00463 #define CANWAKEUPOK CAN_WakeUp_Ok 00464 /** 00465 * @} 00466 */ 00467 00468 /** 00469 * @defgroup CAN_Error_Code_constants 00470 * @{ 00471 */ 00472 #define CAN_ErrorCode_NoErr ((uint8_t)0x00) /*!< No Error */ 00473 #define CAN_ErrorCode_StuffErr ((uint8_t)0x10) /*!< Stuff Error */ 00474 #define CAN_ErrorCode_FormErr ((uint8_t)0x20) /*!< Form Error */ 00475 #define CAN_ErrorCode_ACKErr ((uint8_t)0x30) /*!< Acknowledgment Error */ 00476 #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */ 00477 #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50) /*!< Bit Dominant Error */ 00478 #define CAN_ErrorCode_CRCErr ((uint8_t)0x60) /*!< CRC Error */ 00479 #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70) /*!< Software Set Error */ 00480 /** 00481 * @} 00482 */ 00483 00484 /** @defgroup CAN_flags 00485 * @{ 00486 */ 00487 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus() 00488 and CAN_ClearFlag() functions. */ 00489 /* If the flag is 0x1XXXXXXX, it means that it can only be used with 00490 CAN_GetFlagStatus() function. */ 00491 00492 /* Transmit Flags */ 00493 #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */ 00494 #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */ 00495 #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */ 00496 00497 /* Receive Flags */ 00498 #define CAN_FLAG_FMP0 ((uint32_t)0x12000003) /*!< FIFO 0 Message Pending Flag */ 00499 #define CAN_FLAG_FF0 ((uint32_t)0x32000008) /*!< FIFO 0 Full Flag */ 00500 #define CAN_FLAG_FOV0 ((uint32_t)0x32000010) /*!< FIFO 0 Overrun Flag */ 00501 #define CAN_FLAG_FMP1 ((uint32_t)0x14000003) /*!< FIFO 1 Message Pending Flag */ 00502 #define CAN_FLAG_FF1 ((uint32_t)0x34000008) /*!< FIFO 1 Full Flag */ 00503 #define CAN_FLAG_FOV1 ((uint32_t)0x34000010) /*!< FIFO 1 Overrun Flag */ 00504 00505 /* Operating Mode Flags */ 00506 #define CAN_FLAG_WKU ((uint32_t)0x31000008) /*!< Wake up Flag */ 00507 #define CAN_FLAG_SLAK ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */ 00508 /* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible. 00509 In this case the SLAK bit can be polled.*/ 00510 00511 /* Error Flags */ 00512 #define CAN_FLAG_EWG ((uint32_t)0x10F00001) /*!< Error Warning Flag */ 00513 #define CAN_FLAG_EPV ((uint32_t)0x10F00002) /*!< Error Passive Flag */ 00514 #define CAN_FLAG_BOF ((uint32_t)0x10F00004) /*!< Bus-Off Flag */ 00515 #define CAN_FLAG_LEC ((uint32_t)0x30F00070) /*!< Last error code Flag */ 00516 00517 #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \ 00518 ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \ 00519 ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \ 00520 ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \ 00521 ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \ 00522 ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \ 00523 ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \ 00524 ((FLAG) == CAN_FLAG_SLAK )) 00525 00526 #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \ 00527 ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \ 00528 ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\ 00529 ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \ 00530 ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK)) 00531 /** 00532 * @} 00533 */ 00534 00535 00536 /** @defgroup CAN_interrupts 00537 * @{ 00538 */ 00539 #define CAN_IT_TME ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/ 00540 00541 /* Receive Interrupts */ 00542 #define CAN_IT_FMP0 ((uint32_t)0x00000002) /*!< FIFO 0 message pending Interrupt*/ 00543 #define CAN_IT_FF0 ((uint32_t)0x00000004) /*!< FIFO 0 full Interrupt*/ 00544 #define CAN_IT_FOV0 ((uint32_t)0x00000008) /*!< FIFO 0 overrun Interrupt*/ 00545 #define CAN_IT_FMP1 ((uint32_t)0x00000010) /*!< FIFO 1 message pending Interrupt*/ 00546 #define CAN_IT_FF1 ((uint32_t)0x00000020) /*!< FIFO 1 full Interrupt*/ 00547 #define CAN_IT_FOV1 ((uint32_t)0x00000040) /*!< FIFO 1 overrun Interrupt*/ 00548 00549 /* Operating Mode Interrupts */ 00550 #define CAN_IT_WKU ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/ 00551 #define CAN_IT_SLK ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/ 00552 00553 /* Error Interrupts */ 00554 #define CAN_IT_EWG ((uint32_t)0x00000100) /*!< Error warning Interrupt*/ 00555 #define CAN_IT_EPV ((uint32_t)0x00000200) /*!< Error passive Interrupt*/ 00556 #define CAN_IT_BOF ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/ 00557 #define CAN_IT_LEC ((uint32_t)0x00000800) /*!< Last error code Interrupt*/ 00558 #define CAN_IT_ERR ((uint32_t)0x00008000) /*!< Error Interrupt*/ 00559 00560 /* Flags named as Interrupts : kept only for FW compatibility */ 00561 #define CAN_IT_RQCP0 CAN_IT_TME 00562 #define CAN_IT_RQCP1 CAN_IT_TME 00563 #define CAN_IT_RQCP2 CAN_IT_TME 00564 00565 00566 #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\ 00567 ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\ 00568 ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\ 00569 ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\ 00570 ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\ 00571 ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\ 00572 ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK)) 00573 00574 #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\ 00575 ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\ 00576 ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\ 00577 ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\ 00578 ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\ 00579 ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK)) 00580 /** 00581 * @} 00582 */ 00583 00584 /** 00585 * @} 00586 */ 00587 00588 /* Exported macro ------------------------------------------------------------*/ 00589 /* Exported functions --------------------------------------------------------*/ 00590 00591 /* Function used to set the CAN configuration to the default reset state *****/ 00592 void CAN_DeInit(CAN_TypeDef* CANx); 00593 00594 /* Initialization and Configuration functions *********************************/ 00595 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct); 00596 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct); 00597 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct); 00598 void CAN_SlaveStartBank(uint8_t CAN_BankNumber); 00599 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState); 00600 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState); 00601 00602 /* CAN Frames Transmission functions ******************************************/ 00603 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage); 00604 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox); 00605 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox); 00606 00607 /* CAN Frames Reception functions *********************************************/ 00608 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage); 00609 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber); 00610 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber); 00611 00612 /* Operation modes functions **************************************************/ 00613 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode); 00614 uint8_t CAN_Sleep(CAN_TypeDef* CANx); 00615 uint8_t CAN_WakeUp(CAN_TypeDef* CANx); 00616 00617 /* CAN Bus Error management functions *****************************************/ 00618 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx); 00619 uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx); 00620 uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx); 00621 00622 /* Interrupts and flags management functions **********************************/ 00623 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState); 00624 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG); 00625 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG); 00626 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT); 00627 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT); 00628 00629 #ifdef __cplusplus 00630 } 00631 #endif 00632 00633 #endif /* __STM32F30x_CAN_H */ 00634 00635 /** 00636 * @} 00637 */ 00638 00639 /** 00640 * @} 00641 */ 00642 00643 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:34:44 by
1.7.2