at32f413_can.h 36 KB

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