at32f413_can.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. /**
  2. **************************************************************************
  3. * @file at32f413_can.h
  4. * @version v2.0.5
  5. * @date 2022-05-20
  6. * @brief at32f413 can header file
  7. **************************************************************************
  8. * Copyright notice & Disclaimer
  9. *
  10. * The software Board Support Package (BSP) that is made available to
  11. * download from Artery official website is the copyrighted work of Artery.
  12. * Artery authorizes customers to use, copy, and distribute the BSP
  13. * software and its related documentation for the purpose of design and
  14. * development in conjunction with Artery microcontrollers. Use of the
  15. * software is governed by this copyright notice and the following disclaimer.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  18. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  19. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  20. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  21. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  23. *
  24. **************************************************************************
  25. */
  26. /* define to prevent recursive inclusion -------------------------------------*/
  27. #ifndef __AT32F413_CAN_H
  28. #define __AT32F413_CAN_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* includes ------------------------------------------------------------------*/
  33. #include "at32f413.h"
  34. /** @addtogroup AT32F413_periph_driver
  35. * @{
  36. */
  37. /** @addtogroup CAN
  38. * @{
  39. */
  40. /** @defgroup CAN_timeout_count
  41. * @{
  42. */
  43. #define FZC_TIMEOUT ((uint32_t)0x0000FFFF) /*!< time out for fzc bit */
  44. #define DZC_TIMEOUT ((uint32_t)0x0000FFFF) /*!< time out for dzc bit */
  45. /**
  46. * @}
  47. */
  48. /** @defgroup CAN_flags_definition
  49. * @brief can flag
  50. * @{
  51. */
  52. #define CAN_EAF_FLAG ((uint32_t)0x01) /*!< error active flag */
  53. #define CAN_EPF_FLAG ((uint32_t)0x02) /*!< error passive flag */
  54. #define CAN_BOF_FLAG ((uint32_t)0x03) /*!< bus-off flag */
  55. #define CAN_ETR_FLAG ((uint32_t)0x04) /*!< error type record flag */
  56. #define CAN_EOIF_FLAG ((uint32_t)0x05) /*!< error occur interrupt flag */
  57. #define CAN_TM0TCF_FLAG ((uint32_t)0x06) /*!< transmit mailbox 0 transmission completed flag */
  58. #define CAN_TM1TCF_FLAG ((uint32_t)0x07) /*!< transmit mailbox 1 transmission completed flag */
  59. #define CAN_TM2TCF_FLAG ((uint32_t)0x08) /*!< transmit mailbox 2 transmission completed flag */
  60. #define CAN_RF0MN_FLAG ((uint32_t)0x09) /*!< receive fifo 0 message num flag */
  61. #define CAN_RF0FF_FLAG ((uint32_t)0x0A) /*!< receive fifo 0 full flag */
  62. #define CAN_RF0OF_FLAG ((uint32_t)0x0B) /*!< receive fifo 0 overflow flag */
  63. #define CAN_RF1MN_FLAG ((uint32_t)0x0C) /*!< receive fifo 1 message num flag */
  64. #define CAN_RF1FF_FLAG ((uint32_t)0x0D) /*!< receive fifo 1 full flag */
  65. #define CAN_RF1OF_FLAG ((uint32_t)0x0E) /*!< receive fifo 1 overflow flag */
  66. #define CAN_QDZIF_FLAG ((uint32_t)0x0F) /*!< quit doze mode interrupt flag */
  67. #define CAN_EDZC_FLAG ((uint32_t)0x10) /*!< enter doze mode confirm flag */
  68. #define CAN_TMEF_FLAG ((uint32_t)0x11) /*!< transmit mailbox empty flag */
  69. /**
  70. * @}
  71. */
  72. /** @defgroup CAN_interrupts_definition
  73. * @brief can interrupt
  74. * @{
  75. */
  76. #define CAN_TCIEN_INT ((uint32_t)0x00000001) /*!< transmission complete interrupt */
  77. #define CAN_RF0MIEN_INT ((uint32_t)0x00000002) /*!< receive fifo 0 message interrupt */
  78. #define CAN_RF0FIEN_INT ((uint32_t)0x00000004) /*!< receive fifo 0 full interrupt */
  79. #define CAN_RF0OIEN_INT ((uint32_t)0x00000008) /*!< receive fifo 0 overflow interrupt */
  80. #define CAN_RF1MIEN_INT ((uint32_t)0x00000010) /*!< receive fifo 1 message interrupt */
  81. #define CAN_RF1FIEN_INT ((uint32_t)0x00000020) /*!< receive fifo 1 full interrupt */
  82. #define CAN_RF1OIEN_INT ((uint32_t)0x00000040) /*!< receive fifo 1 overflow interrupt */
  83. #define CAN_EAIEN_INT ((uint32_t)0x00000100) /*!< error active interrupt */
  84. #define CAN_EPIEN_INT ((uint32_t)0x00000200) /*!< error passive interrupt */
  85. #define CAN_BOIEN_INT ((uint32_t)0x00000400) /*!< bus-off interrupt */
  86. #define CAN_ETRIEN_INT ((uint32_t)0x00000800) /*!< error type record interrupt */
  87. #define CAN_EOIEN_INT ((uint32_t)0x00008000) /*!< error occur interrupt */
  88. #define CAN_QDZIEN_INT ((uint32_t)0x00010000) /*!< quit doze mode interrupt */
  89. #define CAN_EDZIEN_INT ((uint32_t)0x00020000) /*!< enter doze mode confirm interrupt */
  90. /**
  91. * @}
  92. */
  93. /**
  94. * @brief can flag clear operation macro definition val
  95. */
  96. #define CAN_MSTS_EOIF_VAL ((uint32_t)0x00000004) /*!< eoif bit value, it clear by writing 1 */
  97. #define CAN_MSTS_QDZIF_VAL ((uint32_t)0x00000008) /*!< qdzif bit value, it clear by writing 1 */
  98. #define CAN_MSTS_EDZIF_VAL ((uint32_t)0x00000010) /*!< edzif bit value, it clear by writing 1 */
  99. #define CAN_TSTS_TM0TCF_VAL ((uint32_t)0x00000001) /*!< tm0tcf bit value, it clear by writing 1 */
  100. #define CAN_TSTS_TM1TCF_VAL ((uint32_t)0x00000100) /*!< tm1tcf bit value, it clear by writing 1 */
  101. #define CAN_TSTS_TM2TCF_VAL ((uint32_t)0x00010000) /*!< tm2tcf bit value, it clear by writing 1 */
  102. #define CAN_TSTS_TM0CT_VAL ((uint32_t)0x00000080) /*!< tm0ct bit value, it clear by writing 1 */
  103. #define CAN_TSTS_TM1CT_VAL ((uint32_t)0x00008000) /*!< tm1ct bit value, it clear by writing 1 */
  104. #define CAN_TSTS_TM2CT_VAL ((uint32_t)0x00800000) /*!< tm2ct bit value, it clear by writing 1 */
  105. #define CAN_RF0_RF0FF_VAL ((uint32_t)0x00000008) /*!< rf0ff bit value, it clear by writing 1 */
  106. #define CAN_RF0_RF0OF_VAL ((uint32_t)0x00000010) /*!< rf0of bit value, it clear by writing 1 */
  107. #define CAN_RF0_RF0R_VAL ((uint32_t)0x00000020) /*!< rf0r bit value, it clear by writing 1 */
  108. #define CAN_RF1_RF1FF_VAL ((uint32_t)0x00000008) /*!< rf1ff bit value, it clear by writing 1 */
  109. #define CAN_RF1_RF1OF_VAL ((uint32_t)0x00000010) /*!< rf1of bit value, it clear by writing 1 */
  110. #define CAN_RF1_RF1R_VAL ((uint32_t)0x00000020) /*!< rf1r bit value, it clear by writing 1 */
  111. /** @defgroup CAN_exported_types
  112. * @{
  113. */
  114. /**
  115. * @brief can filter fifo
  116. */
  117. typedef enum
  118. {
  119. CAN_FILTER_FIFO0 = 0x00, /*!< filter fifo 0 assignment for filter x */
  120. CAN_FILTER_FIFO1 = 0x01 /*!< filter fifo 1 assignment for filter x */
  121. } can_filter_fifo_type;
  122. /**
  123. * @brief can filter mode
  124. */
  125. typedef enum
  126. {
  127. CAN_FILTER_MODE_ID_MASK = 0x00, /*!< identifier mask mode */
  128. CAN_FILTER_MODE_ID_LIST = 0x01 /*!< identifier list mode */
  129. } can_filter_mode_type;
  130. /**
  131. * @brief can filter bit width select
  132. */
  133. typedef enum
  134. {
  135. CAN_FILTER_16BIT = 0x00, /*!< two 16-bit filters */
  136. CAN_FILTER_32BIT = 0x01 /*!< one 32-bit filter */
  137. } can_filter_bit_width_type;
  138. /**
  139. * @brief can mode
  140. */
  141. typedef enum
  142. {
  143. CAN_MODE_COMMUNICATE = 0x00, /*!< communication mode */
  144. CAN_MODE_LOOPBACK = 0x01, /*!< loopback mode */
  145. CAN_MODE_LISTENONLY = 0x02, /*!< listen-only mode */
  146. CAN_MODE_LISTENONLY_LOOPBACK = 0x03 /*!< loopback combined with listen-only mode */
  147. } can_mode_type;
  148. /**
  149. * @brief can operating mode
  150. */
  151. typedef enum
  152. {
  153. CAN_OPERATINGMODE_FREEZE = 0x00, /*!< freeze mode */
  154. CAN_OPERATINGMODE_DOZE = 0x01, /*!< doze mode */
  155. CAN_OPERATINGMODE_COMMUNICATE = 0x02 /*!< communication mode */
  156. } can_operating_mode_type;
  157. /**
  158. * @brief can resynchronization adjust width
  159. */
  160. typedef enum
  161. {
  162. CAN_RSAW_1TQ = 0x00, /*!< 1 time quantum */
  163. CAN_RSAW_2TQ = 0x01, /*!< 2 time quantum */
  164. CAN_RSAW_3TQ = 0x02, /*!< 3 time quantum */
  165. CAN_RSAW_4TQ = 0x03 /*!< 4 time quantum */
  166. } can_rsaw_type;
  167. /**
  168. * @brief can bit time segment 1
  169. */
  170. typedef enum
  171. {
  172. CAN_BTS1_1TQ = 0x00, /*!< 1 time quantum */
  173. CAN_BTS1_2TQ = 0x01, /*!< 2 time quantum */
  174. CAN_BTS1_3TQ = 0x02, /*!< 3 time quantum */
  175. CAN_BTS1_4TQ = 0x03, /*!< 4 time quantum */
  176. CAN_BTS1_5TQ = 0x04, /*!< 5 time quantum */
  177. CAN_BTS1_6TQ = 0x05, /*!< 6 time quantum */
  178. CAN_BTS1_7TQ = 0x06, /*!< 7 time quantum */
  179. CAN_BTS1_8TQ = 0x07, /*!< 8 time quantum */
  180. CAN_BTS1_9TQ = 0x08, /*!< 9 time quantum */
  181. CAN_BTS1_10TQ = 0x09, /*!< 10 time quantum */
  182. CAN_BTS1_11TQ = 0x0A, /*!< 11 time quantum */
  183. CAN_BTS1_12TQ = 0x0B, /*!< 12 time quantum */
  184. CAN_BTS1_13TQ = 0x0C, /*!< 13 time quantum */
  185. CAN_BTS1_14TQ = 0x0D, /*!< 14 time quantum */
  186. CAN_BTS1_15TQ = 0x0E, /*!< 15 time quantum */
  187. CAN_BTS1_16TQ = 0x0F /*!< 16 time quantum */
  188. } can_bts1_type;
  189. /**
  190. * @brief can bit time segment 2
  191. */
  192. typedef enum
  193. {
  194. CAN_BTS2_1TQ = 0x00, /*!< 1 time quantum */
  195. CAN_BTS2_2TQ = 0x01, /*!< 2 time quantum */
  196. CAN_BTS2_3TQ = 0x02, /*!< 3 time quantum */
  197. CAN_BTS2_4TQ = 0x03, /*!< 4 time quantum */
  198. CAN_BTS2_5TQ = 0x04, /*!< 5 time quantum */
  199. CAN_BTS2_6TQ = 0x05, /*!< 6 time quantum */
  200. CAN_BTS2_7TQ = 0x06, /*!< 7 time quantum */
  201. CAN_BTS2_8TQ = 0x07 /*!< 8 time quantum */
  202. } can_bts2_type;
  203. /**
  204. * @brief can identifier type
  205. */
  206. typedef enum
  207. {
  208. CAN_ID_STANDARD = 0x00, /*!< standard Id */
  209. CAN_ID_EXTENDED = 0x01 /*!< extended Id */
  210. } can_identifier_type;
  211. /**
  212. * @brief can transmission frame type
  213. */
  214. typedef enum
  215. {
  216. CAN_TFT_DATA = 0x00, /*!< data frame */
  217. CAN_TFT_REMOTE = 0x01 /*!< remote frame */
  218. } can_trans_frame_type;
  219. /**
  220. * @brief can tx mailboxes
  221. */
  222. typedef enum
  223. {
  224. CAN_TX_MAILBOX0 = 0x00, /*!< can tx mailbox 0 */
  225. CAN_TX_MAILBOX1 = 0x01, /*!< can tx mailbox 1 */
  226. CAN_TX_MAILBOX2 = 0x02 /*!< can tx mailbox 2 */
  227. } can_tx_mailbox_num_type;
  228. /**
  229. * @brief can receive fifo
  230. */
  231. typedef enum
  232. {
  233. CAN_RX_FIFO0 = 0x00, /*!< can fifo 0 used to receive */
  234. CAN_RX_FIFO1 = 0x01 /*!< can fifo 1 used to receive */
  235. } can_rx_fifo_num_type;
  236. /**
  237. * @brief can transmit status
  238. */
  239. typedef enum
  240. {
  241. CAN_TX_STATUS_FAILED = 0x00, /*!< can transmission failed */
  242. CAN_TX_STATUS_SUCCESSFUL = 0x01, /*!< can transmission successful */
  243. CAN_TX_STATUS_PENDING = 0x02, /*!< can transmission pending */
  244. CAN_TX_STATUS_NO_EMPTY = 0x04 /*!< can transmission no empty mailbox */
  245. } can_transmit_status_type;
  246. /**
  247. * @brief can enter doze mode status
  248. */
  249. typedef enum
  250. {
  251. CAN_ENTER_DOZE_FAILED = 0x00, /*!< can enter the doze mode failed */
  252. CAN_ENTER_DOZE_SUCCESSFUL = 0x01 /*!< can enter the doze mode successful */
  253. } can_enter_doze_status_type;
  254. /**
  255. * @brief can quit doze mode status
  256. */
  257. typedef enum
  258. {
  259. CAN_QUIT_DOZE_FAILED = 0x00, /*!< can quit doze mode failed */
  260. CAN_QUIT_DOZE_SUCCESSFUL = 0x01 /*!< can quit doze mode successful */
  261. } can_quit_doze_status_type;
  262. /**
  263. * @brief can message discarding rule select when overflow
  264. */
  265. typedef enum
  266. {
  267. CAN_DISCARDING_FIRST_RECEIVED = 0x00, /*!< can discarding the first received message */
  268. CAN_DISCARDING_LAST_RECEIVED = 0x01 /*!< can discarding the last received message */
  269. } can_msg_discarding_rule_type;
  270. /**
  271. * @brief can multiple message sending sequence rule
  272. */
  273. typedef enum
  274. {
  275. CAN_SENDING_BY_ID = 0x00, /*!< can sending the minimum id message first*/
  276. CAN_SENDING_BY_REQUEST = 0x01 /*!< can sending the first request message first */
  277. } can_msg_sending_rule_type;
  278. /**
  279. * @brief can error type record
  280. */
  281. typedef enum
  282. {
  283. CAN_ERRORRECORD_NOERR = 0x00, /*!< no error */
  284. CAN_ERRORRECORD_STUFFERR = 0x01, /*!< stuff error */
  285. CAN_ERRORRECORD_FORMERR = 0x02, /*!< form error */
  286. CAN_ERRORRECORD_ACKERR = 0x03, /*!< acknowledgment error */
  287. CAN_ERRORRECORD_BITRECESSIVEERR = 0x04, /*!< bit recessive error */
  288. CAN_ERRORRECORD_BITDOMINANTERR = 0x05, /*!< bit dominant error */
  289. CAN_ERRORRECORD_CRCERR = 0x06, /*!< crc error */
  290. CAN_ERRORRECORD_SOFTWARESETERR = 0x07 /*!< software set error */
  291. } can_error_record_type;
  292. /**
  293. * @brief can init structure definition
  294. */
  295. typedef struct
  296. {
  297. can_mode_type mode_selection; /*!< specifies the can mode.*/
  298. confirm_state ttc_enable; /*!< time triggered communication mode enable */
  299. confirm_state aebo_enable; /*!< automatic exit bus-off enable */
  300. confirm_state aed_enable; /*!< automatic exit doze mode enable */
  301. confirm_state prsf_enable; /*!< prohibit retransmission when sending fails enable */
  302. can_msg_discarding_rule_type mdrsel_selection; /*!< message discarding rule select when overflow */
  303. can_msg_sending_rule_type mmssr_selection; /*!< multiple message sending sequence rule */
  304. } can_base_type;
  305. /**
  306. * @brief can baudrate structure definition
  307. */
  308. typedef struct
  309. {
  310. uint16_t baudrate_div; /*!< baudrate division,this parameter can be 0x001~0x400.*/
  311. can_rsaw_type rsaw_size; /*!< resynchronization adjust width */
  312. can_bts1_type bts1_size; /*!< bit time segment 1 */
  313. can_bts2_type bts2_size; /*!< bit time segment 2 */
  314. } can_baudrate_type;
  315. /**
  316. * @brief can filter init structure definition
  317. */
  318. typedef struct
  319. {
  320. confirm_state filter_activate_enable; /*!< enable or disable the filter activate.*/
  321. can_filter_mode_type filter_mode; /*!< config the filter mode mask or list.*/
  322. can_filter_fifo_type filter_fifo; /*!< config the fifo which will be assigned to the filter. */
  323. uint8_t filter_number; /*!< config the filter number, parameter ranges from 0 to 13. */
  324. can_filter_bit_width_type filter_bit; /*!< config the filter bit width 16bit or 32bit.*/
  325. uint16_t filter_id_high; /*!< config the filter identification, for 32-bit configuration
  326. it's high 16 bits, for 16-bit configuration it's first. */
  327. uint16_t filter_id_low; /*!< config the filter identification, for 32-bit configuration
  328. it's low 16 bits, for 16-bit configuration it's second. */
  329. uint16_t filter_mask_high; /*!< config the filter mask or identification, according to the filtering mode,
  330. for 32-bit configuration it's high 16 bits, for 16-bit configuration it's first. */
  331. uint16_t filter_mask_low; /*!< config the filter mask or identification, according to the filtering mode,
  332. for 32-bit configuration it's low 16 bits, for 16-bit configuration it's second. */
  333. } can_filter_init_type;
  334. /**
  335. * @brief can tx message structure definition
  336. */
  337. typedef struct
  338. {
  339. uint32_t standard_id; /*!< specifies the 11 bits standard identifier.
  340. this parameter can be a value between 0 to 0x7FF. */
  341. uint32_t extended_id; /*!< specifies the 29 bits extended identifier.
  342. this parameter can be a value between 0 to 0x1FFFFFFF. */
  343. can_identifier_type id_type; /*!< specifies identifier type for the transmit message.*/
  344. can_trans_frame_type frame_type; /*!< specifies frame type for the transmit message.*/
  345. uint8_t dlc; /*!< specifies frame data length that will be transmitted.
  346. this parameter can be a value between 0 to 8 */
  347. uint8_t data[8]; /*!< contains the transmit data. it ranges from 0 to 0xFF. */
  348. } can_tx_message_type;
  349. /**
  350. * @brief can rx message structure definition
  351. */
  352. typedef struct
  353. {
  354. uint32_t standard_id; /*!< specifies the 11 bits standard identifier
  355. this parameter can be a value between 0 to 0x7FF. */
  356. uint32_t extended_id; /*!< specifies the 29 bits extended identifier.
  357. this parameter can be a value between 0 to 0x1FFFFFFF. */
  358. can_identifier_type id_type; /*!< specifies identifier type for the receive message.*/
  359. can_trans_frame_type frame_type; /*!< specifies frame type for the receive message.*/
  360. uint8_t dlc; /*!< specifies the frame data length that will be received.
  361. this parameter can be a value between 0 to 8 */
  362. uint8_t data[8]; /*!< contains the receive data. it ranges from 0 to 0xFF.*/
  363. uint8_t filter_index; /*!< specifies the message stored in which filter
  364. this parameter can be a value between 0 to 0xFF */
  365. } can_rx_message_type;
  366. /**
  367. * @brief can controller area network tx mailbox
  368. */
  369. typedef struct
  370. {
  371. /**
  372. * @brief can tmi register
  373. */
  374. union
  375. {
  376. __IO uint32_t tmi;
  377. struct
  378. {
  379. __IO uint32_t tmsr : 1; /* [0] */
  380. __IO uint32_t tmfrsel : 1; /* [1] */
  381. __IO uint32_t tmidsel : 1; /* [2] */
  382. __IO uint32_t tmeid : 18;/* [20:3] */
  383. __IO uint32_t tmsid : 11;/* [31:21] */
  384. } tmi_bit;
  385. };
  386. /**
  387. * @brief can tmc register
  388. */
  389. union
  390. {
  391. __IO uint32_t tmc;
  392. struct
  393. {
  394. __IO uint32_t tmdtbl : 4; /* [3:0] */
  395. __IO uint32_t reserved1 : 4; /* [7:4] */
  396. __IO uint32_t tmtsten : 1; /* [8] */
  397. __IO uint32_t reserved2 : 7; /* [15:9] */
  398. __IO uint32_t tmts : 16;/* [31:16] */
  399. } tmc_bit;
  400. };
  401. /**
  402. * @brief can tmdtl register
  403. */
  404. union
  405. {
  406. __IO uint32_t tmdtl;
  407. struct
  408. {
  409. __IO uint32_t tmdt0 : 8; /* [7:0] */
  410. __IO uint32_t tmdt1 : 8; /* [15:8] */
  411. __IO uint32_t tmdt2 : 8; /* [23:16] */
  412. __IO uint32_t tmdt3 : 8; /* [31:24] */
  413. } tmdtl_bit;
  414. };
  415. /**
  416. * @brief can tmdth register
  417. */
  418. union
  419. {
  420. __IO uint32_t tmdth;
  421. struct
  422. {
  423. __IO uint32_t tmdt4 : 8; /* [7:0] */
  424. __IO uint32_t tmdt5 : 8; /* [15:8] */
  425. __IO uint32_t tmdt6 : 8; /* [23:16] */
  426. __IO uint32_t tmdt7 : 8; /* [31:24] */
  427. } tmdth_bit;
  428. };
  429. } can_tx_mailbox_type;
  430. /**
  431. * @brief can controller area network fifo mailbox
  432. */
  433. typedef struct
  434. {
  435. /**
  436. * @brief can rfi register
  437. */
  438. union
  439. {
  440. __IO uint32_t rfi;
  441. struct
  442. {
  443. __IO uint32_t reserved1 : 1; /* [0] */
  444. __IO uint32_t rffri : 1; /* [1] */
  445. __IO uint32_t rfidi : 1; /* [2] */
  446. __IO uint32_t rfeid : 18;/* [20:3] */
  447. __IO uint32_t rfsid : 11;/* [31:21] */
  448. } rfi_bit;
  449. };
  450. /**
  451. * @brief can rfc register
  452. */
  453. union
  454. {
  455. __IO uint32_t rfc;
  456. struct
  457. {
  458. __IO uint32_t rfdtl : 4; /* [3:0] */
  459. __IO uint32_t reserved1 : 4; /* [7:4] */
  460. __IO uint32_t rffmn : 8; /* [15:8] */
  461. __IO uint32_t rfts : 16;/* [31:16] */
  462. } rfc_bit;
  463. };
  464. /**
  465. * @brief can rfdtl register
  466. */
  467. union
  468. {
  469. __IO uint32_t rfdtl;
  470. struct
  471. {
  472. __IO uint32_t rfdt0 : 8; /* [7:0] */
  473. __IO uint32_t rfdt1 : 8; /* [15:8] */
  474. __IO uint32_t rfdt2 : 8; /* [23:16] */
  475. __IO uint32_t rfdt3 : 8; /* [31:24] */
  476. } rfdtl_bit;
  477. };
  478. /**
  479. * @brief can rfdth register
  480. */
  481. union
  482. {
  483. __IO uint32_t rfdth;
  484. struct
  485. {
  486. __IO uint32_t rfdt4 : 8; /* [7:0] */
  487. __IO uint32_t rfdt5 : 8; /* [15:8] */
  488. __IO uint32_t rfdt6 : 8; /* [23:16] */
  489. __IO uint32_t rfdt7 : 8; /* [31:24] */
  490. } rfdth_bit;
  491. };
  492. } can_fifo_mailbox_type;
  493. /**
  494. * @brief can controller area network filter bit register
  495. */
  496. typedef struct
  497. {
  498. __IO uint32_t ffdb1;
  499. __IO uint32_t ffdb2;
  500. } can_filter_register_type;
  501. /**
  502. * @brief type define can register all
  503. */
  504. typedef struct
  505. {
  506. /**
  507. * @brief can mctrl register, offset:0x00
  508. */
  509. union
  510. {
  511. __IO uint32_t mctrl;
  512. struct
  513. {
  514. __IO uint32_t fzen : 1; /* [0] */
  515. __IO uint32_t dzen : 1; /* [1] */
  516. __IO uint32_t mmssr : 1; /* [2] */
  517. __IO uint32_t mdrsel : 1; /* [3] */
  518. __IO uint32_t prsfen : 1; /* [4] */
  519. __IO uint32_t aeden : 1; /* [5] */
  520. __IO uint32_t aeboen : 1; /* [6] */
  521. __IO uint32_t ttcen : 1; /* [7] */
  522. __IO uint32_t reserved1 : 7; /* [14:8] */
  523. __IO uint32_t sprst : 1; /* [15] */
  524. __IO uint32_t ptd : 1; /* [16] */
  525. __IO uint32_t reserved2 : 15;/*[31:17] */
  526. } mctrl_bit;
  527. };
  528. /**
  529. * @brief can msts register, offset:0x04
  530. */
  531. union
  532. {
  533. __IO uint32_t msts;
  534. struct
  535. {
  536. __IO uint32_t fzc : 1; /* [0] */
  537. __IO uint32_t dzc : 1; /* [1] */
  538. __IO uint32_t eoif : 1; /* [2] */
  539. __IO uint32_t qdzif : 1; /* [3] */
  540. __IO uint32_t edzif : 1; /* [4] */
  541. __IO uint32_t reserved1 : 3; /* [7:5] */
  542. __IO uint32_t cuss : 1; /* [8] */
  543. __IO uint32_t curs : 1; /* [9] */
  544. __IO uint32_t lsamprx : 1; /* [10] */
  545. __IO uint32_t realrx : 1; /* [11] */
  546. __IO uint32_t reserved2 : 20;/*[31:12] */
  547. } msts_bit;
  548. };
  549. /**
  550. * @brief can tsts register, offset:0x08
  551. */
  552. union
  553. {
  554. __IO uint32_t tsts;
  555. struct
  556. {
  557. __IO uint32_t tm0tcf : 1; /* [0] */
  558. __IO uint32_t tm0tsf : 1; /* [1] */
  559. __IO uint32_t tm0alf : 1; /* [2] */
  560. __IO uint32_t tm0tef : 1; /* [3] */
  561. __IO uint32_t reserved1 : 3; /* [6:4] */
  562. __IO uint32_t tm0ct : 1; /* [7] */
  563. __IO uint32_t tm1tcf : 1; /* [8] */
  564. __IO uint32_t tm1tsf : 1; /* [9] */
  565. __IO uint32_t tm1alf : 1; /* [10] */
  566. __IO uint32_t tm1tef : 1; /* [11] */
  567. __IO uint32_t reserved2 : 3; /* [14:12] */
  568. __IO uint32_t tm1ct : 1; /* [15] */
  569. __IO uint32_t tm2tcf : 1; /* [16] */
  570. __IO uint32_t tm2tsf : 1; /* [17] */
  571. __IO uint32_t tm2alf : 1; /* [18] */
  572. __IO uint32_t tm2tef : 1; /* [19] */
  573. __IO uint32_t reserved3 : 3; /* [22:20] */
  574. __IO uint32_t tm2ct : 1; /* [23] */
  575. __IO uint32_t tmnr : 2; /* [25:24] */
  576. __IO uint32_t tm0ef : 1; /* [26] */
  577. __IO uint32_t tm1ef : 1; /* [27] */
  578. __IO uint32_t tm2ef : 1; /* [28] */
  579. __IO uint32_t tm0lpf : 1; /* [29] */
  580. __IO uint32_t tm1lpf : 1; /* [30] */
  581. __IO uint32_t tm2lpf : 1; /* [31] */
  582. } tsts_bit;
  583. };
  584. /**
  585. * @brief can rf0 register, offset:0x0C
  586. */
  587. union
  588. {
  589. __IO uint32_t rf0;
  590. struct
  591. {
  592. __IO uint32_t rf0mn : 2; /* [1:0] */
  593. __IO uint32_t reserved1 : 1; /* [2] */
  594. __IO uint32_t rf0ff : 1; /* [3] */
  595. __IO uint32_t rf0of : 1; /* [4] */
  596. __IO uint32_t rf0r : 1; /* [5] */
  597. __IO uint32_t reserved2 : 26;/* [31:6] */
  598. } rf0_bit;
  599. };
  600. /**
  601. * @brief can rf1 register, offset:0x10
  602. */
  603. union
  604. {
  605. __IO uint32_t rf1;
  606. struct
  607. {
  608. __IO uint32_t rf1mn : 2; /* [1:0] */
  609. __IO uint32_t reserved1 : 1; /* [2] */
  610. __IO uint32_t rf1ff : 1; /* [3] */
  611. __IO uint32_t rf1of : 1; /* [4] */
  612. __IO uint32_t rf1r : 1; /* [5] */
  613. __IO uint32_t reserved2 : 26;/* [31:6] */
  614. } rf1_bit;
  615. };
  616. /**
  617. * @brief can inten register, offset:0x14
  618. */
  619. union
  620. {
  621. __IO uint32_t inten;
  622. struct
  623. {
  624. __IO uint32_t tcien : 1; /* [0] */
  625. __IO uint32_t rf0mien : 1; /* [1] */
  626. __IO uint32_t rf0fien : 1; /* [2] */
  627. __IO uint32_t rf0oien : 1; /* [3] */
  628. __IO uint32_t rf1mien : 1; /* [4] */
  629. __IO uint32_t rf1fien : 1; /* [5] */
  630. __IO uint32_t rf1oien : 1; /* [6] */
  631. __IO uint32_t reserved1 : 1; /* [7] */
  632. __IO uint32_t eaien : 1; /* [8] */
  633. __IO uint32_t epien : 1; /* [9] */
  634. __IO uint32_t boien : 1; /* [10] */
  635. __IO uint32_t etrien : 1; /* [11] */
  636. __IO uint32_t reserved2 : 3; /* [14:12] */
  637. __IO uint32_t eoien : 1; /* [15] */
  638. __IO uint32_t qdzien : 1; /* [16] */
  639. __IO uint32_t edzien : 1; /* [17] */
  640. __IO uint32_t reserved3 : 14;/* [31:18] */
  641. } inten_bit;
  642. };
  643. /**
  644. * @brief can ests register, offset:0x18
  645. */
  646. union
  647. {
  648. __IO uint32_t ests;
  649. struct
  650. {
  651. __IO uint32_t eaf : 1; /* [0] */
  652. __IO uint32_t epf : 1; /* [1] */
  653. __IO uint32_t bof : 1; /* [2] */
  654. __IO uint32_t reserved1 : 1; /* [3] */
  655. __IO uint32_t etr : 3; /* [6:4] */
  656. __IO uint32_t reserved2 : 9; /* [15:7] */
  657. __IO uint32_t tec : 8; /* [23:16] */
  658. __IO uint32_t rec : 8; /* [31:24] */
  659. } ests_bit;
  660. };
  661. /**
  662. * @brief can btmg register, offset:0x1C
  663. */
  664. union
  665. {
  666. __IO uint32_t btmg;
  667. struct
  668. {
  669. __IO uint32_t brdiv : 12;/* [11:0] */
  670. __IO uint32_t reserved1 : 4; /* [15:12] */
  671. __IO uint32_t bts1 : 4; /* [19:16] */
  672. __IO uint32_t bts2 : 3; /* [22:20] */
  673. __IO uint32_t reserved2 : 1; /* [23] */
  674. __IO uint32_t rsaw : 2; /* [25:24] */
  675. __IO uint32_t reserved3 : 4; /* [29:26] */
  676. __IO uint32_t lben : 1; /* [30] */
  677. __IO uint32_t loen : 1; /* [31] */
  678. } btmg_bit;
  679. };
  680. /**
  681. * @brief can reserved register, offset:0x20~0x17C
  682. */
  683. __IO uint32_t reserved1[88];
  684. /**
  685. * @brief can controller area network tx mailbox register, offset:0x180~0x1AC
  686. */
  687. can_tx_mailbox_type tx_mailbox[3];
  688. /**
  689. * @brief can controller area network fifo mailbox register, offset:0x1B0~0x1CC
  690. */
  691. can_fifo_mailbox_type fifo_mailbox[2];
  692. /**
  693. * @brief can reserved register, offset:0x1D0~0x1FC
  694. */
  695. __IO uint32_t reserved2[12];
  696. /**
  697. * @brief can fctrl register, offset:0x200
  698. */
  699. union
  700. {
  701. __IO uint32_t fctrl;
  702. struct
  703. {
  704. __IO uint32_t fcs : 1; /* [0] */
  705. __IO uint32_t reserved1 : 31;/* [31:1] */
  706. } fctrl_bit;
  707. };
  708. /**
  709. * @brief can fmcfg register, offset:0x204
  710. */
  711. union
  712. {
  713. __IO uint32_t fmcfg;
  714. struct
  715. {
  716. __IO uint32_t fmsel0 : 1; /* [0] */
  717. __IO uint32_t fmsel1 : 1; /* [1] */
  718. __IO uint32_t fmsel2 : 1; /* [2] */
  719. __IO uint32_t fmsel3 : 1; /* [3] */
  720. __IO uint32_t fmsel4 : 1; /* [4] */
  721. __IO uint32_t fmsel5 : 1; /* [5] */
  722. __IO uint32_t fmsel6 : 1; /* [6] */
  723. __IO uint32_t fmsel7 : 1; /* [7] */
  724. __IO uint32_t fmsel8 : 1; /* [8] */
  725. __IO uint32_t fmsel9 : 1; /* [9] */
  726. __IO uint32_t fmsel10 : 1; /* [10] */
  727. __IO uint32_t fmsel11 : 1; /* [11] */
  728. __IO uint32_t fmsel12 : 1; /* [12] */
  729. __IO uint32_t fmsel13 : 1; /* [13] */
  730. __IO uint32_t reserved1 : 18;/* [31:14] */
  731. } fmcfg_bit;
  732. };
  733. /**
  734. * @brief can reserved register, offset:0x208
  735. */
  736. __IO uint32_t reserved3;
  737. /**
  738. * @brief can fbwcfg register, offset:0x20C
  739. */
  740. union
  741. {
  742. __IO uint32_t fbwcfg;
  743. struct
  744. {
  745. __IO uint32_t fbwsel0 : 1; /* [0] */
  746. __IO uint32_t fbwsel1 : 1; /* [1] */
  747. __IO uint32_t fbwsel2 : 1; /* [2] */
  748. __IO uint32_t fbwsel3 : 1; /* [3] */
  749. __IO uint32_t fbwsel4 : 1; /* [4] */
  750. __IO uint32_t fbwsel5 : 1; /* [5] */
  751. __IO uint32_t fbwsel6 : 1; /* [6] */
  752. __IO uint32_t fbwsel7 : 1; /* [7] */
  753. __IO uint32_t fbwsel8 : 1; /* [8] */
  754. __IO uint32_t fbwsel9 : 1; /* [9] */
  755. __IO uint32_t fbwsel10 : 1; /* [10] */
  756. __IO uint32_t fbwsel11 : 1; /* [11] */
  757. __IO uint32_t fbwsel12 : 1; /* [12] */
  758. __IO uint32_t fbwsel13 : 1; /* [13] */
  759. __IO uint32_t reserved1 : 18;/* [31:14] */
  760. } fbwcfg_bit;
  761. };
  762. /**
  763. * @brief can reserved register, offset:0x210
  764. */
  765. __IO uint32_t reserved4;
  766. /**
  767. * @brief can frf register, offset:0x214
  768. */
  769. union
  770. {
  771. __IO uint32_t frf;
  772. struct
  773. {
  774. __IO uint32_t frfsel0 : 1; /* [0] */
  775. __IO uint32_t frfsel1 : 1; /* [1] */
  776. __IO uint32_t frfsel2 : 1; /* [2] */
  777. __IO uint32_t frfsel3 : 1; /* [3] */
  778. __IO uint32_t frfsel4 : 1; /* [4] */
  779. __IO uint32_t frfsel5 : 1; /* [5] */
  780. __IO uint32_t frfsel6 : 1; /* [6] */
  781. __IO uint32_t frfsel7 : 1; /* [7] */
  782. __IO uint32_t frfsel8 : 1; /* [8] */
  783. __IO uint32_t frfsel9 : 1; /* [9] */
  784. __IO uint32_t frfsel10 : 1; /* [10] */
  785. __IO uint32_t frfsel11 : 1; /* [11] */
  786. __IO uint32_t frfsel12 : 1; /* [12] */
  787. __IO uint32_t frfsel13 : 1; /* [13] */
  788. __IO uint32_t reserved1 : 18;/* [31:14] */
  789. } frf_bit;
  790. };
  791. /**
  792. * @brief can reserved register, offset:0x218
  793. */
  794. __IO uint32_t reserved5;
  795. /**
  796. * @brief can facfg register, offset:0x21C
  797. */
  798. union
  799. {
  800. __IO uint32_t facfg;
  801. struct
  802. {
  803. __IO uint32_t faen0 : 1; /* [0] */
  804. __IO uint32_t faen1 : 1; /* [1] */
  805. __IO uint32_t faen2 : 1; /* [2] */
  806. __IO uint32_t faen3 : 1; /* [3] */
  807. __IO uint32_t faen4 : 1; /* [4] */
  808. __IO uint32_t faen5 : 1; /* [5] */
  809. __IO uint32_t faen6 : 1; /* [6] */
  810. __IO uint32_t faen7 : 1; /* [7] */
  811. __IO uint32_t faen8 : 1; /* [8] */
  812. __IO uint32_t faen9 : 1; /* [9] */
  813. __IO uint32_t faen10 : 1; /* [10] */
  814. __IO uint32_t faen11 : 1; /* [11] */
  815. __IO uint32_t faen12 : 1; /* [12] */
  816. __IO uint32_t faen13 : 1; /* [13] */
  817. __IO uint32_t reserved1 : 18;/* [31:14] */
  818. } facfg_bit;
  819. };
  820. /**
  821. * @brief can reserved register, offset:0x220~0x23C
  822. */
  823. __IO uint32_t reserved6[8];
  824. /**
  825. * @brief can ffb register, offset:0x240~0x2AC
  826. */
  827. can_filter_register_type ffb[14];
  828. } can_type;
  829. /**
  830. * @}
  831. */
  832. #define CAN1 ((can_type *) CAN1_BASE)
  833. #define CAN2 ((can_type *) CAN2_BASE)
  834. /** @defgroup CAN_exported_functions
  835. * @{
  836. */
  837. void can_reset(can_type* can_x);
  838. void can_baudrate_default_para_init(can_baudrate_type* can_baudrate_struct);
  839. error_status can_baudrate_set(can_type* can_x, can_baudrate_type* can_baudrate_struct);
  840. void can_default_para_init(can_base_type* can_base_struct);
  841. error_status can_base_init(can_type* can_x, can_base_type* can_base_struct);
  842. void can_filter_default_para_init(can_filter_init_type* can_filter_init_struct);
  843. void can_filter_init(can_type* can_x, can_filter_init_type* can_filter_init_struct);
  844. void can_debug_transmission_prohibit(can_type* can_x, confirm_state new_state);
  845. void can_ttc_mode_enable(can_type* can_x, confirm_state new_state);
  846. uint8_t can_message_transmit(can_type* can_x, can_tx_message_type* tx_message_struct);
  847. can_transmit_status_type can_transmit_status_get(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox);
  848. void can_transmit_cancel(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox);
  849. void can_message_receive(can_type* can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type* rx_message_struct);
  850. void can_receive_fifo_release(can_type* can_x, can_rx_fifo_num_type fifo_number);
  851. uint8_t can_receive_message_pending_get(can_type* can_x, can_rx_fifo_num_type fifo_number);
  852. error_status can_operating_mode_set(can_type* can_x, can_operating_mode_type can_operating_mode);
  853. can_enter_doze_status_type can_doze_mode_enter(can_type* can_x);
  854. can_quit_doze_status_type can_doze_mode_exit(can_type* can_x);
  855. can_error_record_type can_error_type_record_get(can_type* can_x);
  856. uint8_t can_receive_error_counter_get(can_type* can_x);
  857. uint8_t can_transmit_error_counter_get(can_type* can_x);
  858. void can_interrupt_enable(can_type* can_x, uint32_t can_int, confirm_state new_state);
  859. flag_status can_flag_get(can_type* can_x, uint32_t can_flag);
  860. void can_flag_clear(can_type* can_x, uint32_t can_flag);
  861. /**
  862. * @}
  863. */
  864. /**
  865. * @}
  866. */
  867. /**
  868. * @}
  869. */
  870. #ifdef __cplusplus
  871. }
  872. #endif
  873. #endif