can.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Control Area Network (CAN) Low Level Driver
  5. *
  6. * Copyright (C) 2015-2016 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef CAN_H_INCLUDED
  47. #define CAN_H_INCLUDED
  48. #include <compiler.h>
  49. #include <system.h>
  50. #include <conf_can.h>
  51. /**
  52. * \name Message RAM
  53. * @{
  54. */
  55. /* -------- CAN_RX_ELEMENT_R0 : (CAN RX element: 0x00) (R/W 32) Rx Element R0 Configuration -------- */
  56. typedef union {
  57. struct {
  58. uint32_t ID:29; /*!< bit: 0..28 Identifier */
  59. uint32_t RTR:1; /*!< bit: 29 Remote Transmission Request */
  60. uint32_t XTD:1; /*!< bit: 30 Extended Identifier */
  61. uint32_t ESI:1; /*!< bit: 31 Error State Indicator */
  62. } bit; /*!< Structure used for bit access */
  63. uint32_t reg; /*!< Type used for register access */
  64. } CAN_RX_ELEMENT_R0_Type;
  65. #define CAN_RX_ELEMENT_R0_ID_Pos 0
  66. #define CAN_RX_ELEMENT_R0_ID_Msk (0x1FFFFFFFul << CAN_RX_ELEMENT_R0_ID_Pos)
  67. #define CAN_RX_ELEMENT_R0_ID(value) ((CAN_RX_ELEMENT_R0_ID_Msk & ((value) << CAN_RX_ELEMENT_R0_ID_Pos)))
  68. #define CAN_RX_ELEMENT_R0_RTR_Pos 29
  69. #define CAN_RX_ELEMENT_R0_RTR (0x1ul << CAN_RX_ELEMENT_R0_RTR_Pos)
  70. #define CAN_RX_ELEMENT_R0_XTD_Pos 30
  71. #define CAN_RX_ELEMENT_R0_XTD (0x1ul << CAN_RX_ELEMENT_R0_XTD_Pos)
  72. #define CAN_RX_ELEMENT_R0_ESI_Pos 31
  73. #define CAN_RX_ELEMENT_R0_ESI (0x1ul << CAN_RX_ELEMENT_R0_ESI_Pos)
  74. /* -------- CAN_RX_ELEMENT_R1 : (CAN RX element: 0x01) (R/W 32) Rx Element R1 Configuration -------- */
  75. typedef union {
  76. struct {
  77. uint32_t RXTS:16; /*!< bit: 0..15 Rx Timestamp */
  78. uint32_t DLC:4; /*!< bit: 16..19 Data Length Code */
  79. uint32_t BRS:1; /*!< bit: 20 Bit Rate Switch */
  80. uint32_t FDF:1; /*!< bit: 21 FD Format */
  81. uint32_t :2; /*!< bit: 22..23 Reserved */
  82. uint32_t FIDX:7; /*!< bit: 24..30 Filter Index */
  83. uint32_t ANMF:1; /*!< bit: 31 Accepted Non-matching Frame */
  84. } bit; /*!< Structure used for bit access */
  85. uint32_t reg; /*!< Type used for register access */
  86. } CAN_RX_ELEMENT_R1_Type;
  87. #define CAN_RX_ELEMENT_R1_RXTS_Pos 0
  88. #define CAN_RX_ELEMENT_R1_RXTS_Msk (0xFFFFul << CAN_RX_ELEMENT_R1_RXTS_Pos)
  89. #define CAN_RX_ELEMENT_R1_RXTS(value) ((CAN_RX_ELEMENT_R1_RXTS_Msk & ((value) << CAN_RX_ELEMENT_R1_RXTS_Pos)))
  90. #define CAN_RX_ELEMENT_R1_DLC_Pos 16
  91. #define CAN_RX_ELEMENT_R1_DLC_Msk (0xFul << CAN_RX_ELEMENT_R1_DLC_Pos)
  92. #define CAN_RX_ELEMENT_R1_DLC(value) ((CAN_RX_ELEMENT_R1_DLC_Msk & ((value) << CAN_RX_ELEMENT_R1_DLC_Pos)))
  93. #define CAN_RX_ELEMENT_R1_BRS_Pos 20
  94. #define CAN_RX_ELEMENT_R1_BRS (0x1ul << CAN_RX_ELEMENT_R1_BRS_Pos)
  95. #define CAN_RX_ELEMENT_R1_FDF_Pos 21
  96. #define CAN_RX_ELEMENT_R1_FDF (0x1ul << CAN_RX_ELEMENT_R1_FDF_Pos)
  97. #define CAN_RX_ELEMENT_R1_FIDX_Pos 24
  98. #define CAN_RX_ELEMENT_R1_FIDX_Msk (0x7Ful << CAN_RX_ELEMENT_R1_FIDX_Pos)
  99. #define CAN_RX_ELEMENT_R1_FIDX(value) ((CAN_RX_ELEMENT_R1_FIDX_Msk & ((value) << CAN_RX_ELEMENT_R1_FIDX_Pos)))
  100. #define CAN_RX_ELEMENT_R1_ANMF_Pos 31
  101. #define CAN_RX_ELEMENT_R1_ANMF (0x1ul << CAN_RX_ELEMENT_R1_ANMF_Pos)
  102. /**
  103. * \brief CAN receive element structure for buffer.
  104. */
  105. struct can_rx_element_buffer {
  106. __IO CAN_RX_ELEMENT_R0_Type R0;
  107. __IO CAN_RX_ELEMENT_R1_Type R1;
  108. uint8_t data[CONF_CAN_ELEMENT_DATA_SIZE];
  109. };
  110. /**
  111. * \brief CAN receive element structure for FIFO 0.
  112. */
  113. struct can_rx_element_fifo_0 {
  114. __IO CAN_RX_ELEMENT_R0_Type R0;
  115. __IO CAN_RX_ELEMENT_R1_Type R1;
  116. uint8_t data[CONF_CAN_ELEMENT_DATA_SIZE];
  117. };
  118. /**
  119. * \brief CAN receive element structure for FIFO 1.
  120. */
  121. struct can_rx_element_fifo_1 {
  122. __IO CAN_RX_ELEMENT_R0_Type R0;
  123. __IO CAN_RX_ELEMENT_R1_Type R1;
  124. uint8_t data[CONF_CAN_ELEMENT_DATA_SIZE];
  125. };
  126. /* -------- CAN_TX_ELEMENT_T0 : (CAN TX element: 0x00) (R/W 32) Tx Element T0 Configuration -------- */
  127. typedef union {
  128. struct {
  129. uint32_t ID:29; /*!< bit: 0..28 Identifier */
  130. uint32_t RTR:1; /*!< bit: 29 Remote Transmission Request */
  131. uint32_t XTD:1; /*!< bit: 30 Extended Identifier */
  132. uint32_t ESI:1; /*!< bit: 31 Error State Indicator */
  133. } bit; /*!< Structure used for bit access */
  134. uint32_t reg; /*!< Type used for register access */
  135. } CAN_TX_ELEMENT_T0_Type;
  136. #define CAN_TX_ELEMENT_T0_EXTENDED_ID_Pos 0
  137. #define CAN_TX_ELEMENT_T0_EXTENDED_ID_Msk (0x1FFFFFFFul << CAN_TX_ELEMENT_T0_EXTENDED_ID_Pos)
  138. #define CAN_TX_ELEMENT_T0_EXTENDED_ID(value) ((CAN_TX_ELEMENT_T0_EXTENDED_ID_Msk & ((value) << CAN_TX_ELEMENT_T0_EXTENDED_ID_Pos)))
  139. #define CAN_TX_ELEMENT_T0_STANDARD_ID_Pos 18
  140. #define CAN_TX_ELEMENT_T0_STANDARD_ID_Msk (0x7FFul << CAN_TX_ELEMENT_T0_STANDARD_ID_Pos)
  141. #define CAN_TX_ELEMENT_T0_STANDARD_ID(value) ((CAN_TX_ELEMENT_T0_STANDARD_ID_Msk & ((value) << CAN_TX_ELEMENT_T0_STANDARD_ID_Pos)))
  142. #define CAN_TX_ELEMENT_T0_RTR_Pos 29
  143. #define CAN_TX_ELEMENT_T0_RTR (0x1ul << CAN_TX_ELEMENT_T0_RTR_Pos)
  144. #define CAN_TX_ELEMENT_T0_XTD_Pos 30
  145. #define CAN_TX_ELEMENT_T0_XTD (0x1ul << CAN_TX_ELEMENT_T0_XTD_Pos)
  146. #define CAN_TX_ELEMENT_T0_ESI_Pos 31
  147. #define CAN_TX_ELEMENT_T0_ESI (0x1ul << CAN_TX_ELEMENT_T0_ESI_Pos)
  148. /* -------- CAN_TX_ELEMENT_T1 : (CAN TX element: 0x01) (R/W 32) Tx Element T1 Configuration -------- */
  149. typedef union {
  150. struct {
  151. uint32_t :16; /*!< bit: 0..15 Reserved */
  152. uint32_t DLC:4; /*!< bit: 16..19 Data Length Code */
  153. uint32_t BRS:1; /*!< bit: 20 Bit Rate Switch */
  154. uint32_t FDF:1; /*!< bit: 21 FD Format */
  155. uint32_t :1; /*!< bit: 22 Reserved */
  156. uint32_t EFC:1; /*!< bit: 23 Event FIFO Control */
  157. uint32_t MM:8; /*!< bit: 24..31 Message Marker */
  158. } bit; /*!< Structure used for bit access */
  159. uint32_t reg; /*!< Type used for register access */
  160. } CAN_TX_ELEMENT_T1_Type;
  161. #define CAN_TX_ELEMENT_T1_DLC_Pos 16
  162. #define CAN_TX_ELEMENT_T1_DLC_Msk (0xFul << CAN_TX_ELEMENT_T1_DLC_Pos)
  163. #define CAN_TX_ELEMENT_T1_DLC(value) ((CAN_TX_ELEMENT_T1_DLC_Msk & ((value) << CAN_TX_ELEMENT_T1_DLC_Pos)))
  164. #define CAN_TX_ELEMENT_T1_DLC_DATA8_Val 0x8ul /**< \brief (CAN_RXESC) 8 byte data field */
  165. #define CAN_TX_ELEMENT_T1_DLC_DATA12_Val 0x9ul /**< \brief (CAN_RXESC) 12 byte data field */
  166. #define CAN_TX_ELEMENT_T1_DLC_DATA16_Val 0xAul /**< \brief (CAN_RXESC) 16 byte data field */
  167. #define CAN_TX_ELEMENT_T1_DLC_DATA20_Val 0xBul /**< \brief (CAN_RXESC) 20 byte data field */
  168. #define CAN_TX_ELEMENT_T1_DLC_DATA24_Val 0xCul /**< \brief (CAN_RXESC) 24 byte data field */
  169. #define CAN_TX_ELEMENT_T1_DLC_DATA32_Val 0xDul /**< \brief (CAN_RXESC) 32 byte data field */
  170. #define CAN_TX_ELEMENT_T1_DLC_DATA48_Val 0xEul /**< \brief (CAN_RXESC) 48 byte data field */
  171. #define CAN_TX_ELEMENT_T1_DLC_DATA64_Val 0xFul /**< \brief (CAN_RXESC) 64 byte data field */
  172. #define CAN_TX_ELEMENT_T1_BRS_Pos 20
  173. #define CAN_TX_ELEMENT_T1_BRS (0x1ul << CAN_TX_ELEMENT_T1_BRS_Pos)
  174. #define CAN_TX_ELEMENT_T1_FDF_Pos 21
  175. #define CAN_TX_ELEMENT_T1_FDF (0x1ul << CAN_TX_ELEMENT_T1_FDF_Pos)
  176. #define CAN_TX_ELEMENT_T1_EFC_Pos 23
  177. #define CAN_TX_ELEMENT_T1_EFC (0x1ul << CAN_TX_ELEMENT_T1_EFC_Pos)
  178. #define CAN_TX_ELEMENT_T1_MM_Pos 24
  179. #define CAN_TX_ELEMENT_T1_MM_Msk (0xFFul << CAN_TX_ELEMENT_T1_MM_Pos)
  180. #define CAN_TX_ELEMENT_T1_MM(value) ((CAN_TX_ELEMENT_T1_MM_Msk & ((value) << CAN_TX_ELEMENT_T1_MM_Pos)))
  181. /**
  182. * \brief CAN transfer element structure.
  183. *
  184. * Common element structure for transfer buffer and FIFO/QUEUE.
  185. */
  186. struct can_tx_element {
  187. __IO CAN_TX_ELEMENT_T0_Type T0;
  188. __IO CAN_TX_ELEMENT_T1_Type T1;
  189. uint8_t data[CONF_CAN_ELEMENT_DATA_SIZE];
  190. };
  191. /* -------- CAN_TX_EVENT_ELEMENT_E0 : (CAN TX event element: 0x00) (R/W 32) Tx Event Element E0 Configuration -------- */
  192. typedef union {
  193. struct {
  194. uint32_t ID:29; /*!< bit: 0..28 Identifier */
  195. uint32_t RTR:1; /*!< bit: 29 Remote Transmission Request */
  196. uint32_t XTD:1; /*!< bit: 30 Extended Identifier */
  197. uint32_t ESI:1; /*!< bit: 31 Error State Indicator */
  198. } bit; /*!< Structure used for bit access */
  199. uint32_t reg; /*!< Type used for register access */
  200. } CAN_TX_EVENT_ELEMENT_E0_Type;
  201. #define CAN_TX_EVENT_ELEMENT_E0_ID_Pos 0
  202. #define CAN_TX_EVENT_ELEMENT_E0_ID_Msk (0x1FFFFFFFul << CAN_TX_EVENT_ELEMENT_E0_ID_Pos)
  203. #define CAN_TX_EVENT_ELEMENT_E0_ID(value) ((CAN_TX_EVENT_ELEMENT_E0_ID_Msk & ((value) << CAN_TX_EVENT_ELEMENT_E0_ID_Pos)))
  204. #define CAN_TX_EVENT_ELEMENT_E0_RTR_Pos 29
  205. #define CAN_TX_EVENT_ELEMENT_E0_RTR (0x1ul << CAN_TX_EVENT_ELEMENT_E0_RTR_Pos)
  206. #define CAN_TX_EVENT_ELEMENT_E0_XTD_Pos 30
  207. #define CAN_TX_EVENT_ELEMENT_E0_XTD (0x1ul << CAN_TX_EVENT_ELEMENT_E0_XTD_Pos)
  208. #define CAN_TX_EVENT_ELEMENT_E0_ESI_Pos 31
  209. #define CAN_TX_EVENT_ELEMENT_E0_ESI (0x1ul << CAN_TX_EVENT_ELEMENT_E0_ESI_Pos)
  210. /* -------- CAN_TX_EVENT_ELEMENT_E1 : (CAN TX event element: 0x01) (R/W 32) Tx Event Element E1 Configuration -------- */
  211. typedef union {
  212. struct {
  213. uint32_t TXTS:16; /*!< bit: 0..15 Tx Timestamp */
  214. uint32_t DLC:4; /*!< bit: 16..19 Data Length Code */
  215. uint32_t BRS:1; /*!< bit: 20 Bit Rate Switch */
  216. uint32_t FDF:1; /*!< bit: 21 FD Format */
  217. uint32_t ET:2; /*!< bit: 22..23 Event Type */
  218. uint32_t MM:8; /*!< bit: 24..31 Message Marker */
  219. } bit; /*!< Structure used for bit access */
  220. uint32_t reg; /*!< Type used for register access */
  221. } CAN_TX_EVENT_ELEMENT_E1_Type;
  222. #define CAN_TX_EVENT_ELEMENT_E1_TXTS_Pos 0
  223. #define CAN_TX_EVENT_ELEMENT_E1_TXTS_Msk (0xFFFFul << CAN_TX_EVENT_ELEMENT_E1_TXTS_Pos)
  224. #define CAN_TX_EVENT_ELEMENT_E1_TXTS(value) ((CAN_TX_EVENT_ELEMENT_E1_TXTS_Msk & ((value) << CAN_TX_EVENT_ELEMENT_E1_TXTS_Pos)))
  225. #define CAN_TX_EVENT_ELEMENT_E1_DLC_Pos 16
  226. #define CAN_TX_EVENT_ELEMENT_E1_DLC_Msk (0xFul << CAN_TX_EVENT_ELEMENT_E1_DLC_Pos)
  227. #define CAN_TX_EVENT_ELEMENT_E1_DLC(value) ((CAN_TX_EVENT_ELEMENT_E1_DLC_Msk & ((value) << CAN_TX_EVENT_ELEMENT_E1_DLC_Pos)))
  228. #define CAN_TX_EVENT_ELEMENT_E1_BRS_Pos 20
  229. #define CAN_TX_EVENT_ELEMENT_E1_BRS (0x1ul << CAN_TX_EVENT_ELEMENT_E1_BRS_Pos)
  230. #define CAN_TX_EVENT_ELEMENT_E1_FDF_Pos 21
  231. #define CAN_TX_EVENT_ELEMENT_E1_FDF (0x1ul << CAN_TX_EVENT_ELEMENT_E1_FDF_Pos)
  232. #define CAN_TX_EVENT_ELEMENT_E1_ET_Pos 22
  233. #define CAN_TX_EVENT_ELEMENT_E1_ET_Msk (0x3ul << CAN_TX_EVENT_ELEMENT_E1_ET_Pos)
  234. #define CAN_TX_EVENT_ELEMENT_E1_ET(value) ((CAN_TX_EVENT_ELEMENT_E1_ET_Msk & ((value) << CAN_TX_EVENT_ELEMENT_E1_ET_Pos)))
  235. #define CAN_TX_EVENT_ELEMENT_E1_MM_Pos 24
  236. #define CAN_TX_EVENT_ELEMENT_E1_MM_Msk (0xFFul << CAN_TX_EVENT_ELEMENT_E1_MM_Pos)
  237. #define CAN_TX_EVENT_ELEMENT_E1_MM(value) ((CAN_TX_EVENT_ELEMENT_E1_MM_Msk & ((value) << CAN_TX_EVENT_ELEMENT_E1_MM_Pos)))
  238. /**
  239. * \brief CAN transfer event FIFO element structure.
  240. *
  241. * Common element structure for transfer event FIFO.
  242. */
  243. struct can_tx_event_element {
  244. __IO CAN_TX_EVENT_ELEMENT_E0_Type E0;
  245. __IO CAN_TX_EVENT_ELEMENT_E1_Type E1;
  246. };
  247. /* -------- CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0 : (CAN standard message ID filter element: 0x00) (R/W 32) Standard Message ID Filter Element S0 Configuration -------- */
  248. typedef union {
  249. struct {
  250. uint32_t SFID2:11; /*!< bit: 0..10 Standard Filter ID 2 */
  251. uint32_t :5; /*!< bit: 11..15 Reserved */
  252. uint32_t SFID1:11; /*!< bit: 16..26 Standard Filter ID 1 */
  253. uint32_t SFEC:3; /*!< bit: 27..29 Standard Filter Element Configuration */
  254. uint32_t SFT:2; /*!< bit: 30..31 Standard Filter Type */
  255. } bit; /*!< Structure used for bit access */
  256. uint32_t reg; /*!< Type used for register access */
  257. } CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_Type;
  258. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Pos 0
  259. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Msk (0x7FFul << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Pos)
  260. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2(value) ((CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Msk & ((value) << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Pos)))
  261. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1_Pos 16
  262. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1_Msk (0x7FFul << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1_Pos)
  263. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1(value) ((CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1_Msk & ((value) << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1_Pos)))
  264. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_Pos 27
  265. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_Msk (0x7ul << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_Pos)
  266. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC(value) ((CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_Msk & ((value) << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_Pos)))
  267. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_DISABLE_Val 0
  268. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_STF0M_Val 1
  269. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_STF1M_Val 2
  270. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_REJECT_Val 3
  271. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_PRIORITY_Val 4
  272. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_PRIF0M_Val 5
  273. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_PRIF1M_Val 6
  274. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_STRXBUF_Val 7
  275. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_Pos 30
  276. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_Msk (0x3ul << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_Pos)
  277. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT(value) ((CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_Msk & ((value) << CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_Pos)))
  278. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_RANGE CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT(0)
  279. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_DUAL CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT(1)
  280. #define CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_CLASSIC CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT(2)
  281. /**
  282. * \brief CAN standard message ID filter element structure.
  283. *
  284. * Common element structure for standard message ID filter element.
  285. */
  286. struct can_standard_message_filter_element {
  287. __IO CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_Type S0;
  288. };
  289. /* -------- CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0 : (CAN extended message ID filter element: 0x00) (R/W 32) Extended Message ID Filter Element F0 Configuration -------- */
  290. typedef union {
  291. struct {
  292. uint32_t EFID1:29; /*!< bit: 0..28 Extended Filter ID 1 */
  293. uint32_t EFEC:3; /*!< bit: 29..31 Extended Filter Element Configuration */
  294. } bit; /*!< Structure used for bit access */
  295. uint32_t reg; /*!< Type used for register access */
  296. } CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_Type;
  297. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1_Pos 0
  298. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1_Msk (0x1FFFFFFFul << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1_Pos)
  299. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1(value) ((CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1_Msk & ((value) << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1_Pos)))
  300. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_Pos 29
  301. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_Msk (0x7ul << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_Pos)
  302. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC(value) ((CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_Msk & ((value) << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_Pos)))
  303. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_DISABLE_Val 0
  304. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_STF0M_Val 1
  305. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_STF1M_Val 2
  306. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_REJECT_Val 3
  307. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_PRIORITY_Val 4
  308. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_PRIF0M_Val 5
  309. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_PRIF1M_Val 6
  310. # define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_STRXBUF_Val 7
  311. /* -------- CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1 : (CAN extended message ID filter element: 0x01) (R/W 32) Extended Message ID Filter Element F1 Configuration -------- */
  312. typedef union {
  313. struct {
  314. uint32_t EFID2:29; /*!< bit: 0..28 Extended Filter ID 2 */
  315. uint32_t :1; /*!< bit: 29 Reserved */
  316. uint32_t EFT:2; /*!< bit: 30..31 Extended Filter Type */
  317. } bit; /*!< Structure used for bit access */
  318. uint32_t reg; /*!< Type used for register access */
  319. } CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_Type;
  320. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Pos 0
  321. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Msk (0x1FFFFFFFul << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Pos)
  322. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2(value) ((CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Msk & ((value) << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Pos)))
  323. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_Pos 30
  324. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_Msk (0x3ul << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_Pos)
  325. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT(value) ((CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_Msk & ((value) << CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_Pos)))
  326. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_RANGEM CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT(0)
  327. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_DUAL CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT(1)
  328. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_CLASSIC CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT(2)
  329. #define CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_RANGE CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT(3)
  330. /**
  331. * \brief CAN extended message ID filter element structure.
  332. *
  333. * Common element structure for extended message ID filter element.
  334. */
  335. struct can_extended_message_filter_element {
  336. __IO CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_Type F0;
  337. __IO CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_Type F1;
  338. };
  339. /** @} */
  340. /**
  341. * \defgroup asfdoc_sam0_can_group SAM Control Area Network (CAN) Low Level Driver
  342. *
  343. * This driver for Atmel® | SMART SAM devices provides an low level
  344. * interface for the configuration and management of the device's
  345. * Control Area Network functionality.
  346. *
  347. * \note Since "The Control Area Network (CAN) performs communication according
  348. * to ISO 11898-1 (Bosch CAN specification 2.0 part A,B) and to Bosch CAN FD
  349. * specification V1.0", the driver is focus on the MAC layer and try to offer
  350. * the APIs which can be used by upper application layer.
  351. *
  352. * For storage of Rx/Tx messages and for storage of the filter configuration,
  353. * a message RAM is needed to the CAN module. In this driver, the message RAM
  354. * is static allocated, the related setting is defined and can be changed in
  355. * the module configuration file "conf_can.h".
  356. *
  357. * The following peripherals are used by this module:
  358. * - CAN (Control Area Network)
  359. *
  360. * The following devices can use this module:
  361. * - SAM C21
  362. *
  363. * The outline of this documentation is as follows:
  364. * - \ref asfdoc_sam0_can_prerequisites
  365. * - \ref asfdoc_sam0_can_module_overview
  366. * - \ref asfdoc_sam0_can_special_considerations
  367. * - \ref asfdoc_sam0_can_extra_info
  368. * - \ref asfdoc_sam0_can_examples
  369. * - \ref asfdoc_sam0_can_api_overview
  370. *
  371. *
  372. * \section asfdoc_sam0_can_prerequisites Prerequisites
  373. *
  374. * There are no prerequisites for this module.
  375. *
  376. *
  377. * \section asfdoc_sam0_can_module_overview Module Overview
  378. *
  379. * This driver provides an interface for the Control Area Network Controller
  380. * functions on the device.
  381. *
  382. *
  383. * \section asfdoc_sam0_can_special_considerations Special Considerations
  384. *
  385. * There are no special considerations for this module.
  386. *
  387. *
  388. * \section asfdoc_sam0_can_extra_info Extra Information
  389. *
  390. * For extra information see \ref asfdoc_sam0_can_extra. This includes:
  391. * - \ref asfdoc_sam0_can_extra_acronyms
  392. * - \ref asfdoc_sam0_can_extra_dependencies
  393. * - \ref asfdoc_sam0_can_extra_errata
  394. * - \ref asfdoc_sam0_can_extra_history
  395. *
  396. *
  397. * \section asfdoc_sam0_can_examples Examples
  398. *
  399. * For a list of examples related to this driver, see
  400. * \ref asfdoc_sam0_can_exqsg.
  401. *
  402. *
  403. * \section asfdoc_sam0_can_api_overview API Overview
  404. * @{
  405. */
  406. #ifdef __cplusplus
  407. extern "C" {
  408. #endif
  409. /**
  410. * \name Module Setting
  411. * @{
  412. */
  413. /**
  414. * \brief Can time out modes.
  415. */
  416. enum can_timeout_mode {
  417. /** Continuous operation. */
  418. CAN_TIMEOUT_CONTINUES = CAN_TOCC_TOS_CONT,
  419. /** Timeout controlled by TX Event FIFO. */
  420. CAN_TIMEOUT_TX_EVEN_FIFO = CAN_TOCC_TOS_TXEF,
  421. /** Timeout controlled by Rx FIFO 0. */
  422. CAN_TIMEOUT_RX_FIFO_0 = CAN_TOCC_TOS_RXF0,
  423. /** Timeout controlled by Rx FIFO 1. */
  424. CAN_TIMEOUT_RX_FIFO_1 = CAN_TOCC_TOS_RXF1,
  425. };
  426. /**
  427. * \brief Can nonmatching frames action.
  428. */
  429. enum can_nonmatching_frames_action {
  430. /** Accept in Rx FIFO 0. */
  431. CAN_NONMATCHING_FRAMES_FIFO_0,
  432. /** Accept in Rx FIFO 1. */
  433. CAN_NONMATCHING_FRAMES_FIFO_1,
  434. /** Reject. */
  435. CAN_NONMATCHING_FRAMES_REJECT,
  436. };
  437. /**
  438. * \brief CAN software device instance structure.
  439. *
  440. * CAN software instance structure, used to retain software state information
  441. * of an associated hardware module instance.
  442. *
  443. * \note The fields of this structure should not be altered by the user
  444. * application; they are reserved for module-internal use only.
  445. */
  446. struct can_module {
  447. #if !defined(__DOXYGEN__)
  448. /** Pointer to CAN hardware module. */
  449. Can *hw;
  450. #endif
  451. };
  452. /**
  453. * \brief CAN configuration structure.
  454. *
  455. * Configuration structure for an CAN instance. This structure should be
  456. * initialized by the \ref can_get_config_defaults()
  457. * function before being modified by the user application.
  458. */
  459. struct can_config {
  460. /** GCLK generator used to clock the peripheral. */
  461. enum gclk_generator clock_source;
  462. /** CAN run in standby control. */
  463. bool run_in_standby;
  464. /** Start value of the Message RAM Watchdog Counter */
  465. uint8_t watchdog_configuration;
  466. /** Transmit Pause. */
  467. bool transmit_pause;
  468. /** Edge Filtering during Bus Integration. */
  469. bool edge_filtering;
  470. /** Protocol Exception Handling. */
  471. bool protocol_exception_handling;
  472. /** Automatic Retransmission. */
  473. bool automatic_retransmission;
  474. /** Clock Stop Request. */
  475. bool clock_stop_request;
  476. /** Clock Stop Acknowledge. */
  477. bool clock_stop_acknowledge;
  478. /** Timestamp Counter Prescaler: 0x0-0xF */
  479. uint8_t timestamp_prescaler;
  480. /** Timeout Period. */
  481. uint16_t timeout_period;
  482. /** Timeout Mode. */
  483. enum can_timeout_mode timeout_mode;
  484. /** Timeout enable. */
  485. bool timeout_enable;
  486. /** Transceiver Delay Compensation enable. */
  487. bool tdc_enable;
  488. /** Transmitter Delay Compensation Offset : 0x0-0x7F */
  489. uint8_t delay_compensation_offset;
  490. /** Transmitter Delay Compensation Filter Window Length : 0x0-0x7F */
  491. uint8_t delay_compensation_filter_window_length;
  492. /** Nonmatching frames action for standard frames. */
  493. enum can_nonmatching_frames_action nonmatching_frames_action_standard;
  494. /** Nonmatching frames action for extended frames. */
  495. enum can_nonmatching_frames_action nonmatching_frames_action_extended;
  496. /** Reject Remote Standard Frames. */
  497. bool remote_frames_standard_reject;
  498. /** Reject Remote Extended Frames. */
  499. bool remote_frames_extended_reject;
  500. /** Extended ID Mask: 0x0-0x1FFFFFFF. */
  501. uint32_t extended_id_mask;
  502. /** Rx FIFO 0 Operation Mode. */
  503. bool rx_fifo_0_overwrite;
  504. /** Rx FIFO 0 Watermark: 1-64, other value disable it. */
  505. uint8_t rx_fifo_0_watermark;
  506. /** Rx FIFO 1 Operation Mode. */
  507. bool rx_fifo_1_overwrite;
  508. /** Rx FIFO 1 Watermark: 1-64, other value disable it. */
  509. uint8_t rx_fifo_1_watermark;
  510. /** Tx FIFO/Queue Mode, 0 for FIFO and 1 for Queue. */
  511. bool tx_queue_mode;
  512. /** Tx Event FIFO Watermark: 1-32, other value disable it. */
  513. uint8_t tx_event_fifo_watermark;
  514. };
  515. /**
  516. * \brief Initializes an CAN configuration structure to defaults
  517. *
  518. * Initializes a given CAN configuration struct to a set of known default
  519. * values. This function should be called on any new instance of the
  520. * configuration struct before being modified by the user application.
  521. *
  522. * The default configuration is as follows:
  523. * \li GCLK generator 8 (GCLK main) clock source
  524. * \li Not run in standby mode
  525. * \li Disable Watchdog
  526. * \li Transmit pause enabled
  527. * \li Edge filtering during bus integration enabled
  528. * \li Protocol exception handling enabled
  529. * \li Automatic retransmission enabled
  530. * \li Clock stop request disabled
  531. * \li Clock stop acknowledge disabled
  532. * \li Timestamp Counter Prescaler 1
  533. * \li Timeout Period with 0xFFFF
  534. * \li Timeout Mode: Continuous operation
  535. * \li Disable Timeout
  536. * \li Transmitter Delay Compensation Offset is 0
  537. * \li Transmitter Delay Compensation Filter Window Length is 0
  538. * \li Reject nonmatching standard frames
  539. * \li Reject nonmatching extended frames
  540. * \li Reject remote standard frames
  541. * \li Reject remote extended frames
  542. * \li Extended ID Mask is 0x1FFFFFFF
  543. * \li Rx FIFO 0 Operation Mode: overwrite
  544. * \li Disable Rx FIFO 0 Watermark
  545. * \li Rx FIFO 1 Operation Mode: overwrite
  546. * \li Disable Rx FIFO 1 Watermark
  547. * \li Tx FIFO/Queue Mode: FIFO
  548. * \li Disable Tx Event FIFO Watermark
  549. *
  550. * \param[out] config Pointer to configuration struct to initialize to
  551. * default values
  552. */
  553. static inline void can_get_config_defaults(
  554. struct can_config *const config)
  555. {
  556. /* Sanity check arguments */
  557. Assert(config);
  558. /* Default configuration values */
  559. config->clock_source = GCLK_GENERATOR_8;
  560. config->run_in_standby = false;
  561. config->watchdog_configuration = 0x00;
  562. config->transmit_pause = true;
  563. config->edge_filtering = true;
  564. config->protocol_exception_handling = true;
  565. config->automatic_retransmission = true;
  566. config->clock_stop_request = false;
  567. config->clock_stop_acknowledge = false;
  568. config->timestamp_prescaler = 0;
  569. config->timeout_period = 0xFFFF;
  570. config->timeout_mode = CAN_TIMEOUT_CONTINUES;
  571. config->timeout_enable = false;
  572. config->tdc_enable = false;
  573. config->delay_compensation_offset = 0;
  574. config->delay_compensation_filter_window_length = 0;
  575. config->nonmatching_frames_action_standard = CAN_NONMATCHING_FRAMES_REJECT;
  576. config->nonmatching_frames_action_extended = CAN_NONMATCHING_FRAMES_REJECT;
  577. config->remote_frames_standard_reject = true;
  578. config->remote_frames_extended_reject = true;
  579. config->extended_id_mask = 0x1FFFFFFF;
  580. config->rx_fifo_0_overwrite = true;
  581. config->rx_fifo_0_watermark = 0;
  582. config->rx_fifo_1_overwrite = true;
  583. config->rx_fifo_1_watermark = 0;
  584. config->tx_queue_mode = false;
  585. config->tx_event_fifo_watermark = 0;
  586. }
  587. /**
  588. * \brief Initializes CAN module.
  589. *
  590. * \param[in] module_inst Pointer to the CAN software instance struct
  591. * \param[in] hw Pointer to the CAN module instance
  592. * \param[in] config Pointer to the configuration struct
  593. */
  594. void can_init(struct can_module *const module_inst, Can *hw,
  595. struct can_config *config);
  596. /**
  597. * \brief Set CAN baudrate.
  598. *
  599. * \param[in] hw Pointer to the CAN module instance
  600. * \param[in] baudrate CAN baudrate
  601. */
  602. void can_set_baudrate(Can *hw, uint32_t baudrate);
  603. /**
  604. * \brief Set CAN_FD baudrate.
  605. *
  606. * \param[in] hw Pointer to the CAN module instance
  607. * \param[in] baudrate CAN_FD baudrate
  608. */
  609. void can_fd_set_baudrate(Can *hw, uint32_t baudrate);
  610. /**
  611. * \brief Start CAN module communication.
  612. *
  613. * \param[in] module_inst Pointer to the CAN software instance struct
  614. */
  615. void can_start(struct can_module *const module_inst);
  616. /**
  617. * \brief Stop CAN module communication.
  618. *
  619. * \param[in] module_inst Pointer to the CAN software instance struct
  620. */
  621. void can_stop(struct can_module *const module_inst);
  622. /**
  623. * \brief Enable CAN FD mode.
  624. *
  625. * \note This function will set the CCCR.INIT bit, can_start() is needed to
  626. * restart the communication.
  627. *
  628. * \param[in] module_inst Pointer to the CAN software instance struct
  629. */
  630. void can_enable_fd_mode(struct can_module *const module_inst);
  631. /**
  632. * \brief Disable CAN FD mode.
  633. *
  634. * \param[in] module_inst Pointer to the CAN software instance struct
  635. */
  636. void can_disable_fd_mode(struct can_module *const module_inst);
  637. /**
  638. * \brief Enable CAN restricted operation mode.
  639. *
  640. * \note This function will set the CCCR.INIT bit, can_start() is needed to
  641. * restart the communication.
  642. *
  643. * \param[in] module_inst Pointer to the CAN software instance struct
  644. */
  645. void can_enable_restricted_operation_mode(
  646. struct can_module *const module_inst);
  647. /**
  648. * \brief Disable CAN restricted operation mode.
  649. *
  650. * \param[in] module_inst Pointer to the CAN software instance struct
  651. */
  652. void can_disable_restricted_operation_mode(
  653. struct can_module *const module_inst);
  654. /**
  655. * \brief Enable CAN bus monitor mode.
  656. *
  657. * \note This function will set the CCCR.INIT bit, can_start() is needed to
  658. * restart the communication.
  659. *
  660. * \param[in] module_inst Pointer to the CAN software instance struct
  661. */
  662. void can_enable_bus_monitor_mode(struct can_module *const module_inst);
  663. /**
  664. * \brief Disable CAN bus monitor mode.
  665. *
  666. * \param[in] module_inst Pointer to the CAN software instance struct
  667. */
  668. void can_disable_bus_monitor_mode(struct can_module *const module_inst);
  669. /**
  670. * \brief Enable CAN sleep mode.
  671. *
  672. * \param[in] module_inst Pointer to the CAN software instance struct
  673. */
  674. void can_enable_sleep_mode(struct can_module *const module_inst);
  675. /**
  676. * \brief Disable CAN sleep mode.
  677. *
  678. * \param[in] module_inst Pointer to the CAN software instance struct
  679. */
  680. void can_disable_sleep_mode(struct can_module *const module_inst);
  681. /**
  682. * \brief Enable CAN test mode.
  683. *
  684. * \note This function will set the CCCR.INIT bit, can_start() is needed to
  685. * restart the communication.
  686. *
  687. * \param[in] module_inst Pointer to the CAN software instance struct
  688. */
  689. void can_enable_test_mode(struct can_module *const module_inst);
  690. /**
  691. * \brief Disable CAN test mode.
  692. *
  693. * \param[in] module_inst Pointer to the CAN software instance struct
  694. */
  695. void can_disable_test_mode(struct can_module *const module_inst);
  696. /**
  697. * \brief Can read timestamp count value.
  698. *
  699. * \param[in] module_inst Pointer to the CAN software instance struct
  700. *
  701. * \return Timestamp count value.
  702. */
  703. static inline uint16_t can_read_timestamp_count_value(
  704. struct can_module *const module_inst)
  705. {
  706. return module_inst->hw->TSCV.bit.TSC;
  707. }
  708. /**
  709. * \brief Can read timeout count value.
  710. *
  711. * \param[in] module_inst Pointer to the CAN software instance struct
  712. *
  713. * \return Timeout count value.
  714. */
  715. static inline uint16_t can_read_timeout_count_value(
  716. struct can_module *const module_inst)
  717. {
  718. return module_inst->hw->TOCV.bit.TOC;
  719. }
  720. /**
  721. * \brief Can read error count.
  722. *
  723. * \param[in] module_inst Pointer to the CAN software instance struct
  724. *
  725. * \return Error count value.
  726. */
  727. static inline uint32_t can_read_error_count(
  728. struct can_module *const module_inst)
  729. {
  730. return module_inst->hw->ECR.reg;
  731. }
  732. /**
  733. * \brief Can read protocol status.
  734. *
  735. * \param[in] module_inst Pointer to the CAN software instance struct
  736. *
  737. * \return protocol status value.
  738. */
  739. static inline uint32_t can_read_protocal_status(
  740. struct can_module *const module_inst)
  741. {
  742. return module_inst->hw->PSR.reg;
  743. }
  744. /** @} */
  745. /**
  746. * \name Rx Handling
  747. * @{
  748. */
  749. /**
  750. * \brief Read high priority message status.
  751. *
  752. * \param[in] module_inst Pointer to the CAN software instance struct
  753. *
  754. * \return High priority message status value.
  755. */
  756. static inline uint32_t can_read_high_priority_message_status(
  757. struct can_module *const module_inst)
  758. {
  759. return module_inst->hw->HPMS.reg;
  760. }
  761. /**
  762. * \brief Get Rx buffer status.
  763. *
  764. * \param[in] module_inst Pointer to the CAN software instance struct
  765. * \param[in] index Index offset in Rx buffer
  766. *
  767. * \return Rx buffer status value.
  768. *
  769. * \retval true Rx Buffer updated from new message.
  770. * \retval false Rx Buffer not updated.
  771. */
  772. static inline bool can_rx_get_buffer_status(
  773. struct can_module *const module_inst, uint32_t index)
  774. {
  775. if (index < 32) {
  776. if (module_inst->hw->NDAT1.reg & (1 << index)) {
  777. return true;
  778. } else {
  779. return false;
  780. }
  781. } else {
  782. index -= 32;
  783. if (module_inst->hw->NDAT2.reg & (1 << index)) {
  784. return true;
  785. } else {
  786. return false;
  787. }
  788. }
  789. }
  790. /**
  791. * \brief Clear Rx buffer status.
  792. *
  793. * \param[in] module_inst Pointer to the CAN software instance struct
  794. * \param[in] index Index offset in Rx buffer
  795. *
  796. */
  797. static inline void can_rx_clear_buffer_status(
  798. struct can_module *const module_inst, uint32_t index)
  799. {
  800. if (index < 32) {
  801. module_inst->hw->NDAT1.reg = (1 << index);
  802. } else {
  803. index -= 32;
  804. module_inst->hw->NDAT2.reg = (1 << index);
  805. }
  806. }
  807. /**
  808. * \brief Get Rx FIFO status.
  809. *
  810. * \param[in] module_inst Pointer to the CAN software instance struct
  811. * \param[in] fifo_number Rx FIFO 0 or 1
  812. *
  813. * \return Rx FIFO status value.
  814. */
  815. static inline uint32_t can_rx_get_fifo_status(
  816. struct can_module *const module_inst, bool fifo_number)
  817. {
  818. if (!fifo_number) {
  819. return module_inst->hw->RXF0S.reg;
  820. } else {
  821. return module_inst->hw->RXF1S.reg;
  822. }
  823. }
  824. /**
  825. * \brief Set Rx acknowledge.
  826. *
  827. * \param[in] module_inst Pointer to the CAN software instance struct
  828. * \param[in] fifo_number Rx FIFO 0 or 1
  829. * \param[in] index Index offset in FIFO
  830. */
  831. static inline void can_rx_fifo_acknowledge(
  832. struct can_module *const module_inst, bool fifo_number, uint32_t index)
  833. {
  834. if (!fifo_number) {
  835. module_inst->hw->RXF0A.reg = CAN_RXF0A_F0AI(index);
  836. } else {
  837. module_inst->hw->RXF1A.reg = CAN_RXF1A_F1AI(index);
  838. }
  839. }
  840. /**
  841. * \brief Get the standard message filter default value.
  842. *
  843. * The default configuration is as follows:
  844. * \li Classic filter: SFID1 = filter, SFID2 = mask
  845. * \li Store in Rx FIFO 0 if filter matches
  846. * \li SFID2 = 0x7FFul
  847. * \li SFID1 = 0x0ul
  848. *
  849. * \param[out] sd_filter Pointer to standard filter element struct to initialize to default values
  850. */
  851. static inline void can_get_standard_message_filter_element_default(
  852. struct can_standard_message_filter_element *sd_filter)
  853. {
  854. sd_filter->S0.reg = CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Msk |
  855. CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1(0) |
  856. CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC(
  857. CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_STF0M_Val) |
  858. CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_CLASSIC;
  859. }
  860. /**
  861. * \brief Set the standard message filter.
  862. *
  863. * \param[in] module_inst Pointer to the CAN software instance struct
  864. * \param[in] sd_filter Pointer to standard filter element struct
  865. * \param[in] index Index offset in standard filter element
  866. *
  867. * \return Status of the result.
  868. *
  869. * \retval STATUS_OK Set the correct standard message filter.
  870. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  871. */
  872. enum status_code can_set_rx_standard_filter(
  873. struct can_module *const module_inst,
  874. struct can_standard_message_filter_element *sd_filter, uint32_t index);
  875. /**
  876. * \brief Get the extended message filter default value.
  877. *
  878. * The default configuration is as follows:
  879. * \li Classic filter: SFID1 = filter, SFID2 = mask
  880. * \li Store in Rx FIFO 1 if filter matches
  881. * \li SFID2 = 0x1FFFFFFFul
  882. * \li SFID1 = 0x0ul
  883. *
  884. * \param[out] et_filter Pointer to extended filter element struct to initialize to default values
  885. */
  886. static inline void can_get_extended_message_filter_element_default(
  887. struct can_extended_message_filter_element *et_filter)
  888. {
  889. et_filter->F0.reg = CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1(0) |
  890. CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC(
  891. CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_STF1M_Val);
  892. et_filter->F1.reg = CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Msk |
  893. CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_CLASSIC;
  894. }
  895. /**
  896. * \brief Set the extended message filter.
  897. *
  898. * \param[in] module_inst Pointer to the CAN software instance struct
  899. * \param[in] et_filter Pointer to extended filter element struct
  900. * \param[in] index Index offset in extended filter element
  901. *
  902. * \return Status of the result.
  903. *
  904. * \retval STATUS_OK Set the correct extended message filter.
  905. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  906. */
  907. enum status_code can_set_rx_extended_filter(
  908. struct can_module *const module_inst,
  909. struct can_extended_message_filter_element *et_filter, uint32_t index);
  910. /**
  911. * \brief Get the pointer to the receive buffer element.
  912. *
  913. * \param[in] module_inst Pointer to the CAN software instance struct
  914. * \param[in] rx_element Pointer to receive buffer element
  915. * \param[in] index Index offset in receive buffer
  916. *
  917. * \return Status of the result.
  918. *
  919. * \retval STATUS_OK Get the correct pointer to the receive buffer element.
  920. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  921. */
  922. enum status_code can_get_rx_buffer_element(
  923. struct can_module *const module_inst,
  924. struct can_rx_element_buffer *rx_element, uint32_t index);
  925. /**
  926. * \brief Get the pointer to the receive FIFO 0 element.
  927. *
  928. * \param[in] module_inst Pointer to the CAN software instance struct
  929. * \param[in] rx_element Pointer to receive FIFO 0
  930. * \param[in] index Index offset in receive FIFO 0
  931. *
  932. * \return Status of the result.
  933. *
  934. * \retval STATUS_OK Get the correct pointer to the receive FIFO 0 element.
  935. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  936. */
  937. enum status_code can_get_rx_fifo_0_element(
  938. struct can_module *const module_inst,
  939. struct can_rx_element_fifo_0 *rx_element, uint32_t index);
  940. /**
  941. * \brief Get the pointer to the receive FIFO 1 element.
  942. *
  943. * \param[in] module_inst Pointer to the CAN software instance struct
  944. * \param[in] rx_element Pointer to receive FIFO 1
  945. * \param[in] index Index offset in receive FIFO 1
  946. *
  947. * \return Status of the result.
  948. *
  949. * \retval STATUS_OK Get the correct pointer to the receive FIFO 1 element.
  950. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  951. */
  952. enum status_code can_get_rx_fifo_1_element(
  953. struct can_module *const module_inst,
  954. struct can_rx_element_fifo_1 *rx_element, uint32_t index);
  955. /** @} */
  956. /**
  957. * \name Tx Handling
  958. * @{
  959. */
  960. /**
  961. * \brief Get Tx FIFO/Queue status.
  962. *
  963. * \param[in] module_inst Pointer to the CAN software instance struct
  964. *
  965. * \return Tx FIFO/Queue status value.
  966. */
  967. static inline uint32_t can_tx_get_fifo_queue_status(
  968. struct can_module *const module_inst)
  969. {
  970. return module_inst->hw->TXFQS.reg;
  971. }
  972. /**
  973. * \brief Get Tx buffer request pending status.
  974. *
  975. * \param[in] module_inst Pointer to the CAN software instance struct
  976. *
  977. * \return Bit mask of Tx buffer request pending status value.
  978. */
  979. static inline uint32_t can_tx_get_pending_status(
  980. struct can_module *const module_inst)
  981. {
  982. return module_inst->hw->TXBRP.reg;
  983. }
  984. /**
  985. * \brief Tx buffer add transfer request.
  986. *
  987. * \param[in] module_inst Pointer to the CAN software instance struct
  988. * \param[in] trig_mask The mask value to trigger transfer buffer
  989. *
  990. * \return Status of the result.
  991. *
  992. * \retval STATUS_OK Set the transfer request.
  993. * \retval STATUS_BUSY The module is in configuration.
  994. */
  995. static inline enum status_code can_tx_transfer_request(
  996. struct can_module *const module_inst, uint32_t trig_mask)
  997. {
  998. if (module_inst->hw->CCCR.reg & CAN_CCCR_CCE) {
  999. return STATUS_BUSY;
  1000. }
  1001. module_inst->hw->TXBAR.reg = trig_mask;
  1002. return STATUS_OK;
  1003. }
  1004. /**
  1005. * \brief Set Tx Queue operation.
  1006. *
  1007. * \param[in] module_inst Pointer to the CAN software instance struct
  1008. * \param[in] trig_mask The mask value to cancel transfer buffer
  1009. *
  1010. * \return Status of the result.
  1011. *
  1012. * \retval STATUS_OK Set the transfer request.
  1013. * \retval STATUS_BUSY The module is in configuration.
  1014. */
  1015. static inline enum status_code can_tx_cancel_request(
  1016. struct can_module *const module_inst, uint32_t trig_mask)
  1017. {
  1018. if (module_inst->hw->CCCR.reg & CAN_CCCR_CCE) {
  1019. return STATUS_BUSY;
  1020. }
  1021. module_inst->hw->TXBCR.reg = trig_mask;
  1022. return STATUS_OK;
  1023. }
  1024. /**
  1025. * \brief Get Tx transmission status.
  1026. *
  1027. * \param[in] module_inst Pointer to the CAN software instance struct
  1028. *
  1029. * \return Bit mask of Tx transmission status value.
  1030. */
  1031. static inline uint32_t can_tx_get_transmission_status(
  1032. struct can_module *const module_inst)
  1033. {
  1034. return module_inst->hw->TXBTO.reg;
  1035. }
  1036. /**
  1037. * \brief Get Tx cancellation status.
  1038. *
  1039. * \param[in] module_inst Pointer to the CAN software instance struct
  1040. *
  1041. * \return Bit mask of Tx cancellation status value.
  1042. */
  1043. static inline uint32_t can_tx_get_cancellation_status(
  1044. struct can_module *const module_inst)
  1045. {
  1046. return module_inst->hw->TXBCF.reg;
  1047. }
  1048. /**
  1049. * \brief Get Tx event FIFO status.
  1050. *
  1051. * \param[in] module_inst Pointer to the CAN software instance struct
  1052. *
  1053. * \return Tx event FIFO status value.
  1054. */
  1055. static inline uint32_t can_tx_get_event_fifo_status(
  1056. struct can_module *const module_inst)
  1057. {
  1058. return module_inst->hw->TXEFS.reg;
  1059. }
  1060. /**
  1061. * \brief Set Tx Queue operation.
  1062. *
  1063. * \param[in] module_inst Pointer to the CAN software instance struct
  1064. * \param[in] index Index for the transfer FIFO
  1065. */
  1066. static inline void can_tx_event_fifo_acknowledge(
  1067. struct can_module *const module_inst, uint32_t index)
  1068. {
  1069. module_inst->hw->TXEFA.reg = CAN_TXEFA_EFAI(index);
  1070. }
  1071. /**
  1072. * \brief Get the default transfer buffer element.
  1073. *
  1074. * The default configuration is as follows:
  1075. * \li 11-bit standard identifier
  1076. * \li Transmit data frame
  1077. * \li ID = 0x0ul
  1078. * \li Store Tx events
  1079. * \li Frame transmitted in Classic CAN format
  1080. * \li Data Length Code is 8
  1081. *
  1082. * \param[out] tx_element Pointer to transfer element struct to initialize to default values
  1083. */
  1084. static inline void can_get_tx_buffer_element_defaults(
  1085. struct can_tx_element *tx_element)
  1086. {
  1087. tx_element->T0.reg = 0;
  1088. tx_element->T1.reg = CAN_TX_ELEMENT_T1_EFC |
  1089. CAN_TX_ELEMENT_T1_DLC(CAN_TX_ELEMENT_T1_DLC_DATA8_Val);
  1090. }
  1091. /**
  1092. * \brief Set the transfer buffer element.
  1093. *
  1094. * \param[in] module_inst Pointer to the CAN software instance struct
  1095. * \param[in] tx_element Pointer to transfer element struct
  1096. * \param[in] index Index for the transfer buffer
  1097. *
  1098. * \return Status of the result.
  1099. *
  1100. * \retval STATUS_OK Set the correct transfer buffer element.
  1101. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  1102. */
  1103. enum status_code can_set_tx_buffer_element(
  1104. struct can_module *const module_inst,
  1105. struct can_tx_element *tx_element, uint32_t index);
  1106. /**
  1107. * \brief Get the pointer to the transfer event FIFO element.
  1108. *
  1109. * \param[in] module_inst Pointer to the CAN software instance struct
  1110. * \param[in] tx_event_element Pointer to transfer event element
  1111. * \param[in] index Index offset in transfer event FIFO
  1112. *
  1113. * \return Status of the result.
  1114. *
  1115. * \retval STATUS_OK Get the correct pointer to the transfer event FIFO element.
  1116. * \retval STATUS_ERR_INVALID_ARG The parameter is not correct.
  1117. */
  1118. enum status_code can_get_tx_event_fifo_element(
  1119. struct can_module *const module_inst,
  1120. struct can_tx_event_element *tx_event_element, uint32_t index);
  1121. /** @} */
  1122. /**
  1123. * \name Interrupt Handling
  1124. * @{
  1125. */
  1126. /**
  1127. * \brief Can module interrupt source.
  1128. *
  1129. * Enum for the interrupt source.
  1130. */
  1131. enum can_interrupt_source {
  1132. /** Rx FIFO 0 New Message Interrupt Enable. */
  1133. CAN_RX_FIFO_0_NEW_MESSAGE = CAN_IE_RF0NE,
  1134. /** Rx FIFO 0 Watermark Reached Interrupt Enable. */
  1135. CAN_RX_FIFO_0_WATERMARK = CAN_IE_RF0WE,
  1136. /** Rx FIFO 0 Full Interrupt Enable. */
  1137. CAN_RX_FIFO_0_FULL = CAN_IE_RF0FE,
  1138. /** Rx FIFO 0 Message Lost Interrupt Enable. */
  1139. CAN_RX_FIFO_0_LOST_MESSAGE = CAN_IE_RF0LE,
  1140. /** Rx FIFO 1 New Message Interrupt Enable. */
  1141. CAN_RX_FIFO_1_NEW_MESSAGE = CAN_IE_RF1NE,
  1142. /** Rx FIFO 1 Watermark Reached Interrupt Enable. */
  1143. CAN_RX_FIFO_1_WATERMARK = CAN_IE_RF1WE,
  1144. /** Rx FIFO 1 Full Interrupt Enable. */
  1145. CAN_RX_FIFO_1_FULL = CAN_IE_RF1FE,
  1146. /** Rx FIFO 1 Message Lost Interrupt Enable. */
  1147. CAN_RX_FIFO_1_MESSAGE_LOST = CAN_IE_RF1LE,
  1148. /** High Priority Message Interrupt Enable. */
  1149. CAN_RX_HIGH_PRIORITY_MESSAGE = CAN_IE_HPME,
  1150. /** Timestamp Completed Interrupt Enable. */
  1151. CAN_TIMESTAMP_COMPLETE = CAN_IE_TCE,
  1152. /** Transmission Cancellation Finished Interrupt Enable. */
  1153. CAN_TX_CANCELLATION_FINISH = CAN_IE_TCFE,
  1154. /** Tx FIFO Empty Interrupt Enable. */
  1155. CAN_TX_FIFO_EMPTY = CAN_IE_TFEE,
  1156. /** Tx Event FIFO New Entry Interrupt Enable. */
  1157. CAN_TX_EVENT_FIFO_NEW_ENTRY = CAN_IE_TEFNE,
  1158. /** Tx Event FIFO Watermark Reached Interrupt Enable. */
  1159. CAN_TX_EVENT_FIFO_WATERMARK = CAN_IE_TEFWE,
  1160. /** Tx Event FIFO Full Interrupt Enable. */
  1161. CAN_TX_EVENT_FIFO_FULL = CAN_IE_TEFFE,
  1162. /** Tx Event FIFO Element Lost Interrupt Enable. */
  1163. CAN_TX_EVENT_FIFO_ELEMENT_LOST = CAN_IE_TEFLE,
  1164. /** Timestamp Wraparound Interrupt Enable. */
  1165. CAN_TIMESTAMP_WRAPAROUND = CAN_IE_TSWE,
  1166. /** Message RAM Access Failure Interrupt Enable. */
  1167. CAN_MESSAGE_RAM_ACCESS_FAILURE = CAN_IE_MRAFE,
  1168. /** Timeout Occurred Interrupt Enable. */
  1169. CAN_TIMEOUT_OCCURRED = CAN_IE_TOOE,
  1170. /** Message stored to Dedicated Rx Buffer Interrupt Enable. */
  1171. CAN_RX_BUFFER_NEW_MESSAGE = CAN_IE_DRXE,
  1172. /** Bit Error Corrected Interrupt Enable. */
  1173. CAN_BIT_ERROR_CORRECTED = CAN_IE_BECE,
  1174. /** Bit Error Uncorrected Interrupt Enable. */
  1175. CAN_BIT_ERROR_UNCORRECTED = CAN_IE_BEUE,
  1176. /** Error Logging Overflow Interrupt Enable. */
  1177. CAN_ERROR_LOGGING_OVERFLOW = CAN_IE_ELOE,
  1178. /** Error Passive Interrupt Enable. */
  1179. CAN_ERROR_PASSIVE = CAN_IE_EPE,
  1180. /** Warning Status Interrupt Enable. */
  1181. CAN_WARNING_STATUS = CAN_IE_EWE,
  1182. /** Bus_Off Status Interrupt Enable. */
  1183. CAN_BUS_OFF = CAN_IE_BOE,
  1184. /** Watchdog Interrupt Interrupt Enable. */
  1185. CAN_WATCHDOG = CAN_IE_WDIE,
  1186. /** Protocol Error in Arbitration Phase Enable. */
  1187. CAN_PROTOCOL_ERROR_ARBITRATION = CAN_IE_PEAE,
  1188. /** Protocol Error in Data Phase Enable. */
  1189. CAN_PROTOCOL_ERROR_DATA = CAN_IE_PEDE,
  1190. /** Access to Reserved Address Enable. */
  1191. CAN_ACCESS_RESERVED_ADDRESS = CAN_IE_ARAE,
  1192. };
  1193. /**
  1194. * \brief Enable CAN interrupt.
  1195. *
  1196. * \param[in] module_inst Pointer to the CAN software instance struct
  1197. * \param[in] source Interrupt source type
  1198. */
  1199. static inline void can_enable_interrupt(struct can_module *const module_inst,
  1200. const enum can_interrupt_source source)
  1201. {
  1202. module_inst->hw->IE.reg |= source;
  1203. }
  1204. /**
  1205. * \brief Disable CAN interrupt.
  1206. *
  1207. * \param[in] module_inst Pointer to the CAN software instance struct
  1208. * \param[in] source Interrupt source type
  1209. */
  1210. static inline void can_disable_interrupt(struct can_module *const module_inst,
  1211. const enum can_interrupt_source source)
  1212. {
  1213. module_inst->hw->IE.reg &= ~source;
  1214. }
  1215. /**
  1216. * \brief Get CAN interrupt status.
  1217. *
  1218. * \param[in] module_inst Pointer to the CAN software instance struct
  1219. */
  1220. static inline uint32_t can_read_interrupt_status(
  1221. struct can_module *const module_inst)
  1222. {
  1223. return module_inst->hw->IR.reg;
  1224. }
  1225. /**
  1226. * \brief Clear CAN interrupt status.
  1227. *
  1228. * \param[in] module_inst Pointer to the CAN software instance struct
  1229. * \param[in] source Interrupt source type
  1230. *
  1231. * \return Bit mask of interrupt status value.
  1232. */
  1233. static inline void can_clear_interrupt_status(
  1234. struct can_module *const module_inst,
  1235. const enum can_interrupt_source source)
  1236. {
  1237. module_inst->hw->IR.reg = source;
  1238. }
  1239. /** @} */
  1240. #ifdef __cplusplus
  1241. }
  1242. #endif
  1243. /** @} */
  1244. /**
  1245. * \page asfdoc_sam0_can_extra Extra Information for CAN Driver
  1246. *
  1247. * \section asfdoc_sam0_can_extra_acronyms Acronyms
  1248. * Below is a table listing the acronyms used in this module, along with their
  1249. * intended meanings.
  1250. *
  1251. * <table>
  1252. * <tr>
  1253. * <th>Acronym</th>
  1254. * <th>Description</th>
  1255. * </tr>
  1256. * <tr>
  1257. * <td>CAN</td>
  1258. * <td>Control Area Network (CAN) Controller</td>
  1259. * </tr>
  1260. * <tr>
  1261. * <td>CAN FD</td>
  1262. * <td>CAN with Flexible Data-Rate</td>
  1263. * </tr>
  1264. * </table>
  1265. *
  1266. *
  1267. * \section asfdoc_sam0_can_extra_dependencies Dependencies
  1268. * This driver has no dependencies.
  1269. *
  1270. *
  1271. * \section asfdoc_sam0_can_extra_errata Errata
  1272. * There are no errata related to this driver.
  1273. *
  1274. *
  1275. * \section asfdoc_sam0_can_extra_history Module History
  1276. * An overview of the module history is presented in the table below, with
  1277. * details on the enhancements and fixes made to the module since its first
  1278. * release. The current version of this corresponds to the newest version in
  1279. * the table.
  1280. *
  1281. * <table>
  1282. * <tr>
  1283. * <th>Changelog</th>
  1284. * </tr>
  1285. * <tr>
  1286. * <td>Initial Release</td>
  1287. * </tr>
  1288. * </table>
  1289. */
  1290. /**
  1291. * \page asfdoc_sam0_can_exqsg Examples for CAN Driver
  1292. *
  1293. * This is a list of the available Quick Start guides (QSGs) and example
  1294. * applications for \ref asfdoc_sam0_can_group. QSGs are simple examples with
  1295. * step-by-step instructions to configure and use this driver in a selection of
  1296. * use cases. Note that QSGs can be compiled as a standalone application or be
  1297. * added to the user application.
  1298. *
  1299. * - \subpage asfdoc_sam0_can_basic_use_case
  1300. *
  1301. * - \subpage asfdoc_sam0_can_fd_use_case
  1302. *
  1303. * \page asfdoc_sam0_can_document_revision_history Document Revision History
  1304. *
  1305. * <table>
  1306. * <tr>
  1307. * <th>Doc. Rev.</td>
  1308. * <th>Date</td>
  1309. * <th>Comments</td>
  1310. * </tr>
  1311. * <tr>
  1312. * <td>A</td>
  1313. * <td>03/2015</td>
  1314. * <td>Initial release</td>
  1315. * </tr>
  1316. * </table>
  1317. */
  1318. #endif /* CAN_H_INCLUDED */