A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

699 lines
27 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_can.h
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file contains all the functions prototypes for the CAN firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F10x_CAN_H
  24. #define __STM32F10x_CAN_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f10x.h"
  30. #include "stm32f10x_assert.h"
  31. /** @addtogroup STM32F10x_StdPeriph_Driver
  32. * @{
  33. */
  34. /** @addtogroup CAN
  35. * @{
  36. */
  37. /** @defgroup CAN_Exported_Types
  38. * @{
  39. */
  40. #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
  41. ((PERIPH) == CAN2))
  42. /**
  43. * @brief CAN init structure definition
  44. */
  45. typedef struct
  46. {
  47. uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum.
  48. It ranges from 1 to 1024. */
  49. uint8_t CAN_Mode; /*!< Specifies the CAN operating mode.
  50. This parameter can be a value of
  51. @ref CAN_operating_mode */
  52. uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta
  53. the CAN hardware is allowed to lengthen or
  54. shorten a bit to perform resynchronization.
  55. This parameter can be a value of
  56. @ref CAN_synchronisation_jump_width */
  57. uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit
  58. Segment 1. This parameter can be a value of
  59. @ref CAN_time_quantum_in_bit_segment_1 */
  60. uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit
  61. Segment 2.
  62. This parameter can be a value of
  63. @ref CAN_time_quantum_in_bit_segment_2 */
  64. FunctionalState CAN_TTCM; /*!< Enable or disable the time triggered
  65. communication mode. This parameter can be set
  66. either to ENABLE or DISABLE. */
  67. FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off
  68. management. This parameter can be set either
  69. to ENABLE or DISABLE. */
  70. FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode.
  71. This parameter can be set either to ENABLE or
  72. DISABLE. */
  73. FunctionalState CAN_NART; /*!< Enable or disable the no-automatic
  74. retransmission mode. This parameter can be
  75. set either to ENABLE or DISABLE. */
  76. FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode.
  77. This parameter can be set either to ENABLE
  78. or DISABLE. */
  79. FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority.
  80. This parameter can be set either to ENABLE
  81. or DISABLE. */
  82. } CAN_InitTypeDef;
  83. /**
  84. * @brief CAN filter init structure definition
  85. */
  86. typedef struct
  87. {
  88. uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit
  89. configuration, first one for a 16-bit configuration).
  90. This parameter can be a value between 0x0000 and 0xFFFF */
  91. uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit
  92. configuration, second one for a 16-bit configuration).
  93. This parameter can be a value between 0x0000 and 0xFFFF */
  94. uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,
  95. according to the mode (MSBs for a 32-bit configuration,
  96. first one for a 16-bit configuration).
  97. This parameter can be a value between 0x0000 and 0xFFFF */
  98. uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,
  99. according to the mode (LSBs for a 32-bit configuration,
  100. second one for a 16-bit configuration).
  101. This parameter can be a value between 0x0000 and 0xFFFF */
  102. uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
  103. This parameter can be a value of @ref CAN_filter_FIFO */
  104. uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */
  105. uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized.
  106. This parameter can be a value of @ref CAN_filter_mode */
  107. uint8_t CAN_FilterScale; /*!< Specifies the filter scale.
  108. This parameter can be a value of @ref CAN_filter_scale */
  109. FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.
  110. This parameter can be set either to ENABLE or DISABLE. */
  111. } CAN_FilterInitTypeDef;
  112. /**
  113. * @brief CAN Tx message structure definition
  114. */
  115. typedef struct
  116. {
  117. uint32_t StdId; /*!< Specifies the standard identifier.
  118. This parameter can be a value between 0 to 0x7FF. */
  119. uint32_t ExtId; /*!< Specifies the extended identifier.
  120. This parameter can be a value between 0 to 0x1FFFFFFF. */
  121. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  122. will be transmitted. This parameter can be a value
  123. of @ref CAN_identifier_type */
  124. uint8_t RTR; /*!< Specifies the type of frame for the message that will
  125. be transmitted. This parameter can be a value of
  126. @ref CAN_remote_transmission_request */
  127. uint8_t DLC; /*!< Specifies the length of the frame that will be
  128. transmitted. This parameter can be a value between
  129. 0 to 8 */
  130. uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0
  131. to 0xFF. */
  132. } CanTxMsg;
  133. /**
  134. * @brief CAN Rx message structure definition
  135. */
  136. typedef struct
  137. {
  138. uint32_t StdId; /*!< Specifies the standard identifier.
  139. This parameter can be a value between 0 to 0x7FF. */
  140. uint32_t ExtId; /*!< Specifies the extended identifier.
  141. This parameter can be a value between 0 to 0x1FFFFFFF. */
  142. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  143. will be received. This parameter can be a value of
  144. @ref CAN_identifier_type */
  145. uint8_t RTR; /*!< Specifies the type of frame for the received message.
  146. This parameter can be a value of
  147. @ref CAN_remote_transmission_request */
  148. uint8_t DLC; /*!< Specifies the length of the frame that will be received.
  149. This parameter can be a value between 0 to 8 */
  150. uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to
  151. 0xFF. */
  152. uint8_t FMI; /*!< Specifies the index of the filter the message stored in
  153. the mailbox passes through. This parameter can be a
  154. value between 0 to 0xFF */
  155. } CanRxMsg;
  156. /**
  157. * @}
  158. */
  159. /** @defgroup CAN_Exported_Constants
  160. * @{
  161. */
  162. /** @defgroup CAN_sleep_constants
  163. * @{
  164. */
  165. #define CAN_InitStatus_Failed ((uint8_t)0x00) /*!< CAN initialization failed */
  166. #define CAN_InitStatus_Success ((uint8_t)0x01) /*!< CAN initialization OK */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup CAN_Mode
  171. * @{
  172. */
  173. #define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */
  174. #define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */
  175. #define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */
  176. #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */
  177. #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
  178. ((MODE) == CAN_Mode_LoopBack)|| \
  179. ((MODE) == CAN_Mode_Silent) || \
  180. ((MODE) == CAN_Mode_Silent_LoopBack))
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @defgroup CAN_Operating_Mode
  186. * @{
  187. */
  188. #define CAN_OperatingMode_Initialization ((uint8_t)0x00) /*!< Initialization mode */
  189. #define CAN_OperatingMode_Normal ((uint8_t)0x01) /*!< Normal mode */
  190. #define CAN_OperatingMode_Sleep ((uint8_t)0x02) /*!< sleep mode */
  191. #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
  192. ((MODE) == CAN_OperatingMode_Normal)|| \
  193. ((MODE) == CAN_OperatingMode_Sleep))
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @defgroup CAN_Mode_Status
  199. * @{
  200. */
  201. #define CAN_ModeStatus_Failed ((uint8_t)0x00) /*!< CAN entering the specific mode failed */
  202. #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed) /*!< CAN entering the specific mode Succeed */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup CAN_synchronisation_jump_width
  207. * @{
  208. */
  209. #define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  210. #define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  211. #define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  212. #define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  213. #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
  214. ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
  215. /**
  216. * @}
  217. */
  218. /** @defgroup CAN_time_quantum_in_bit_segment_1
  219. * @{
  220. */
  221. #define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  222. #define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  223. #define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  224. #define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  225. #define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  226. #define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  227. #define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  228. #define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  229. #define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
  230. #define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
  231. #define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
  232. #define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
  233. #define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
  234. #define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
  235. #define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
  236. #define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */
  237. #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
  238. /**
  239. * @}
  240. */
  241. /** @defgroup CAN_time_quantum_in_bit_segment_2
  242. * @{
  243. */
  244. #define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  245. #define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  246. #define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  247. #define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  248. #define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  249. #define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  250. #define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  251. #define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  252. #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
  253. /**
  254. * @}
  255. */
  256. /** @defgroup CAN_clock_prescaler
  257. * @{
  258. */
  259. #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
  260. /**
  261. * @}
  262. */
  263. /** @defgroup CAN_filter_number
  264. * @{
  265. */
  266. #ifndef STM32F10X_CL
  267. #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13)
  268. #else
  269. #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
  270. #endif /* STM32F10X_CL */
  271. /**
  272. * @}
  273. */
  274. /** @defgroup CAN_filter_mode
  275. * @{
  276. */
  277. #define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */
  278. #define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */
  279. #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
  280. ((MODE) == CAN_FilterMode_IdList))
  281. /**
  282. * @}
  283. */
  284. /** @defgroup CAN_filter_scale
  285. * @{
  286. */
  287. #define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */
  288. #define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */
  289. #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
  290. ((SCALE) == CAN_FilterScale_32bit))
  291. /**
  292. * @}
  293. */
  294. /** @defgroup CAN_filter_FIFO
  295. * @{
  296. */
  297. #define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
  298. #define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */
  299. #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
  300. ((FIFO) == CAN_FilterFIFO1))
  301. /**
  302. * @}
  303. */
  304. /** @defgroup Start_bank_filter_for_slave_CAN
  305. * @{
  306. */
  307. #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
  308. /**
  309. * @}
  310. */
  311. /** @defgroup CAN_Tx
  312. * @{
  313. */
  314. #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
  315. #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
  316. #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
  317. #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
  318. /**
  319. * @}
  320. */
  321. /** @defgroup CAN_identifier_type
  322. * @{
  323. */
  324. #define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */
  325. #define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */
  326. #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
  327. ((IDTYPE) == CAN_Id_Extended))
  328. /**
  329. * @}
  330. */
  331. /** @defgroup CAN_remote_transmission_request
  332. * @{
  333. */
  334. #define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */
  335. #define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */
  336. #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
  337. /**
  338. * @}
  339. */
  340. /** @defgroup CAN_transmit_constants
  341. * @{
  342. */
  343. #define CAN_TxStatus_Failed ((uint8_t)0x00)/*!< CAN transmission failed */
  344. #define CAN_TxStatus_Ok ((uint8_t)0x01) /*!< CAN transmission succeeded */
  345. #define CAN_TxStatus_Pending ((uint8_t)0x02) /*!< CAN transmission pending */
  346. #define CAN_TxStatus_NoMailBox ((uint8_t)0x04) /*!< CAN cell did not provide an empty mailbox */
  347. /**
  348. * @}
  349. */
  350. /** @defgroup CAN_receive_FIFO_number_constants
  351. * @{
  352. */
  353. #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */
  354. #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */
  355. #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
  356. /**
  357. * @}
  358. */
  359. /** @defgroup CAN_sleep_constants
  360. * @{
  361. */
  362. #define CAN_Sleep_Failed ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */
  363. #define CAN_Sleep_Ok ((uint8_t)0x01) /*!< CAN entered the sleep mode */
  364. /**
  365. * @}
  366. */
  367. /** @defgroup CAN_wake_up_constants
  368. * @{
  369. */
  370. #define CAN_WakeUp_Failed ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */
  371. #define CAN_WakeUp_Ok ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
  372. /**
  373. * @}
  374. */
  375. /**
  376. * @defgroup CAN_Error_Code_constants
  377. * @{
  378. */
  379. #define CAN_ErrorCode_NoErr ((uint8_t)0x00) /*!< No Error */
  380. #define CAN_ErrorCode_StuffErr ((uint8_t)0x10) /*!< Stuff Error */
  381. #define CAN_ErrorCode_FormErr ((uint8_t)0x20) /*!< Form Error */
  382. #define CAN_ErrorCode_ACKErr ((uint8_t)0x30) /*!< Acknowledgment Error */
  383. #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */
  384. #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50) /*!< Bit Dominant Error */
  385. #define CAN_ErrorCode_CRCErr ((uint8_t)0x60) /*!< CRC Error */
  386. #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70) /*!< Software Set Error */
  387. /**
  388. * @}
  389. */
  390. /** @defgroup CAN_flags
  391. * @{
  392. */
  393. /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
  394. and CAN_ClearFlag() functions. */
  395. /* If the flag is 0x1XXXXXXX, it means that it can only be used with CAN_GetFlagStatus() function. */
  396. /* Transmit Flags */
  397. #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */
  398. #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */
  399. #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */
  400. /* Receive Flags */
  401. #define CAN_FLAG_FMP0 ((uint32_t)0x12000003) /*!< FIFO 0 Message Pending Flag */
  402. #define CAN_FLAG_FF0 ((uint32_t)0x32000008) /*!< FIFO 0 Full Flag */
  403. #define CAN_FLAG_FOV0 ((uint32_t)0x32000010) /*!< FIFO 0 Overrun Flag */
  404. #define CAN_FLAG_FMP1 ((uint32_t)0x14000003) /*!< FIFO 1 Message Pending Flag */
  405. #define CAN_FLAG_FF1 ((uint32_t)0x34000008) /*!< FIFO 1 Full Flag */
  406. #define CAN_FLAG_FOV1 ((uint32_t)0x34000010) /*!< FIFO 1 Overrun Flag */
  407. /* Operating Mode Flags */
  408. #define CAN_FLAG_WKU ((uint32_t)0x31000008) /*!< Wake up Flag */
  409. #define CAN_FLAG_SLAK ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */
  410. /* Note: When SLAK intterupt is disabled (SLKIE=0), no polling on SLAKI is possible.
  411. In this case the SLAK bit can be polled.*/
  412. /* Error Flags */
  413. #define CAN_FLAG_EWG ((uint32_t)0x10F00001) /*!< Error Warning Flag */
  414. #define CAN_FLAG_EPV ((uint32_t)0x10F00002) /*!< Error Passive Flag */
  415. #define CAN_FLAG_BOF ((uint32_t)0x10F00004) /*!< Bus-Off Flag */
  416. #define CAN_FLAG_LEC ((uint32_t)0x30F00070) /*!< Last error code Flag */
  417. #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \
  418. ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \
  419. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \
  420. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \
  421. ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \
  422. ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
  423. ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
  424. ((FLAG) == CAN_FLAG_SLAK ))
  425. #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
  426. ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \
  427. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\
  428. ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
  429. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
  430. /**
  431. * @}
  432. */
  433. /** @defgroup CAN_interrupts
  434. * @{
  435. */
  436. #define CAN_IT_TME ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/
  437. /* Receive Interrupts */
  438. #define CAN_IT_FMP0 ((uint32_t)0x00000002) /*!< FIFO 0 message pending Interrupt*/
  439. #define CAN_IT_FF0 ((uint32_t)0x00000004) /*!< FIFO 0 full Interrupt*/
  440. #define CAN_IT_FOV0 ((uint32_t)0x00000008) /*!< FIFO 0 overrun Interrupt*/
  441. #define CAN_IT_FMP1 ((uint32_t)0x00000010) /*!< FIFO 1 message pending Interrupt*/
  442. #define CAN_IT_FF1 ((uint32_t)0x00000020) /*!< FIFO 1 full Interrupt*/
  443. #define CAN_IT_FOV1 ((uint32_t)0x00000040) /*!< FIFO 1 overrun Interrupt*/
  444. /* Operating Mode Interrupts */
  445. #define CAN_IT_WKU ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/
  446. #define CAN_IT_SLK ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/
  447. /* Error Interrupts */
  448. #define CAN_IT_EWG ((uint32_t)0x00000100) /*!< Error warning Interrupt*/
  449. #define CAN_IT_EPV ((uint32_t)0x00000200) /*!< Error passive Interrupt*/
  450. #define CAN_IT_BOF ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/
  451. #define CAN_IT_LEC ((uint32_t)0x00000800) /*!< Last error code Interrupt*/
  452. #define CAN_IT_ERR ((uint32_t)0x00008000) /*!< Error Interrupt*/
  453. /* Flags named as Interrupts : kept only for FW compatibility */
  454. #define CAN_IT_RQCP0 CAN_IT_TME
  455. #define CAN_IT_RQCP1 CAN_IT_TME
  456. #define CAN_IT_RQCP2 CAN_IT_TME
  457. #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\
  458. ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\
  459. ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\
  460. ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\
  461. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  462. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  463. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  464. #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\
  465. ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\
  466. ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\
  467. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  468. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  469. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  470. /**
  471. * @}
  472. */
  473. /** @defgroup CAN_Legacy
  474. * @{
  475. */
  476. #define CANINITFAILED CAN_InitStatus_Failed
  477. #define CANINITOK CAN_InitStatus_Success
  478. #define CAN_FilterFIFO0 CAN_Filter_FIFO0
  479. #define CAN_FilterFIFO1 CAN_Filter_FIFO1
  480. #define CAN_ID_STD CAN_Id_Standard
  481. #define CAN_ID_EXT CAN_Id_Extended
  482. #define CAN_RTR_DATA CAN_RTR_Data
  483. #define CAN_RTR_REMOTE CAN_RTR_Remote
  484. #define CANTXFAILE CAN_TxStatus_Failed
  485. #define CANTXOK CAN_TxStatus_Ok
  486. #define CANTXPENDING CAN_TxStatus_Pending
  487. #define CAN_NO_MB CAN_TxStatus_NoMailBox
  488. #define CANSLEEPFAILED CAN_Sleep_Failed
  489. #define CANSLEEPOK CAN_Sleep_Ok
  490. #define CANWAKEUPFAILED CAN_WakeUp_Failed
  491. #define CANWAKEUPOK CAN_WakeUp_Ok
  492. /**
  493. * @}
  494. */
  495. /**
  496. * @}
  497. */
  498. /** @defgroup CAN_Exported_Macros
  499. * @{
  500. */
  501. /**
  502. * @}
  503. */
  504. /** @defgroup CAN_Exported_Functions
  505. * @{
  506. */
  507. /* Function used to set the CAN configuration to the default reset state *****/
  508. void CAN_DeInit(CAN_TypeDef* CANx);
  509. /* Initialization and Configuration functions *********************************/
  510. uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
  511. void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
  512. void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
  513. void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
  514. void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
  515. void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
  516. /* Transmit functions *********************************************************/
  517. uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
  518. uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
  519. void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
  520. /* Receive functions **********************************************************/
  521. void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
  522. void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
  523. uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
  524. /* Operation modes functions **************************************************/
  525. uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
  526. uint8_t CAN_Sleep(CAN_TypeDef* CANx);
  527. uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
  528. /* Error management functions *************************************************/
  529. uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
  530. uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx);
  531. uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx);
  532. /* Interrupts and flags management functions **********************************/
  533. void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
  534. FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  535. void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  536. ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
  537. void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
  538. #ifdef __cplusplus
  539. }
  540. #endif
  541. #endif /* __STM32F10x_CAN_H */
  542. /**
  543. * @}
  544. */
  545. /**
  546. * @}
  547. */
  548. /**
  549. * @}
  550. */
  551. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/