Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

USBInterrupt_UC3.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
  28. *
  29. * This file contains definitions required for the correct handling of low level USB service routine interrupts
  30. * from the USB controller.
  31. *
  32. * \note This file should not be included directly. It is automatically included as needed by the USB driver
  33. * dispatch header located in LUFA/Drivers/USB/USB.h.
  34. */
  35. #ifndef __USBINTERRUPT_UC3_H__
  36. #define __USBINTERRUPT_UC3_H__
  37. /* Includes: */
  38. #include "../../../../Common/Common.h"
  39. /* Enable C linkage for C++ Compilers: */
  40. #if defined(__cplusplus)
  41. extern "C" {
  42. #endif
  43. /* Preprocessor Checks: */
  44. #if !defined(__INCLUDE_FROM_USB_DRIVER)
  45. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
  46. #endif
  47. /* Private Interface - For use in library only: */
  48. #if !defined(__DOXYGEN__)
  49. /* External Variables: */
  50. extern volatile uint32_t USB_Endpoint_SelectedEndpoint;
  51. /* Enums: */
  52. enum USB_Interrupts_t
  53. {
  54. USB_INT_VBUSTI = 0,
  55. #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
  56. USB_INT_IDTI = 1,
  57. #endif
  58. #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
  59. USB_INT_WAKEUPI = 2,
  60. USB_INT_SUSPI = 3,
  61. USB_INT_EORSTI = 4,
  62. USB_INT_SOFI = 5,
  63. USB_INT_RXSTPI = 6,
  64. #endif
  65. #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
  66. USB_INT_HSOFI = 7,
  67. USB_INT_DCONNI = 8,
  68. USB_INT_DDISCI = 9,
  69. USB_INT_RSTI = 10,
  70. USB_INT_BCERRI = 11,
  71. USB_INT_VBERRI = 12,
  72. #endif
  73. };
  74. /* Inline Functions: */
  75. static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
  76. static inline void USB_INT_Enable(const uint8_t Interrupt)
  77. {
  78. switch (Interrupt)
  79. {
  80. case USB_INT_VBUSTI:
  81. AVR32_USBB.USBCON.vbuste = true;
  82. break;
  83. #if defined(USB_CAN_BE_BOTH)
  84. case USB_INT_IDTI:
  85. AVR32_USBB.USBCON.idte = true;
  86. break;
  87. #endif
  88. #if defined(USB_CAN_BE_DEVICE)
  89. case USB_INT_WAKEUPI:
  90. AVR32_USBB.UDINTESET.wakeupes = true;
  91. break;
  92. case USB_INT_SUSPI:
  93. AVR32_USBB.UDINTESET.suspes = true;
  94. break;
  95. case USB_INT_EORSTI:
  96. AVR32_USBB.UDINTESET.eorstes = true;
  97. break;
  98. case USB_INT_SOFI:
  99. AVR32_USBB.UDINTESET.sofes = true;
  100. break;
  101. case USB_INT_RXSTPI:
  102. (&AVR32_USBB.UECON0SET)[USB_Endpoint_SelectedEndpoint].rxstpes = true;
  103. break;
  104. #endif
  105. #if defined(USB_CAN_BE_HOST)
  106. case USB_INT_HSOFI:
  107. AVR32_USBB.UHINTESET.hsofies = true;
  108. break;
  109. case USB_INT_DCONNI:
  110. AVR32_USBB.UHINTESET.dconnies = true;
  111. break;
  112. case USB_INT_DDISCI:
  113. AVR32_USBB.UHINTESET.ddiscies = true;
  114. break;
  115. case USB_INT_RSTI:
  116. AVR32_USBB.UHINTESET.rsties = true;
  117. break;
  118. case USB_INT_BCERRI:
  119. AVR32_USBB.USBCON.bcerre = true;
  120. break;
  121. case USB_INT_VBERRI:
  122. AVR32_USBB.USBCON.vberre = true;
  123. break;
  124. #endif
  125. default:
  126. break;
  127. }
  128. }
  129. static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
  130. static inline void USB_INT_Disable(const uint8_t Interrupt)
  131. {
  132. switch (Interrupt)
  133. {
  134. case USB_INT_VBUSTI:
  135. AVR32_USBB.USBCON.vbuste = false;
  136. break;
  137. #if defined(USB_CAN_BE_BOTH)
  138. case USB_INT_IDTI:
  139. AVR32_USBB.USBCON.idte = false;
  140. break;
  141. #endif
  142. #if defined(USB_CAN_BE_DEVICE)
  143. case USB_INT_WAKEUPI:
  144. AVR32_USBB.UDINTECLR.wakeupec = true;
  145. break;
  146. case USB_INT_SUSPI:
  147. AVR32_USBB.UDINTECLR.suspec = true;
  148. break;
  149. case USB_INT_EORSTI:
  150. AVR32_USBB.UDINTECLR.eorstec = true;
  151. break;
  152. case USB_INT_SOFI:
  153. AVR32_USBB.UDINTECLR.sofec = true;
  154. break;
  155. case USB_INT_RXSTPI:
  156. (&AVR32_USBB.UECON0CLR)[USB_Endpoint_SelectedEndpoint].rxstpec = true;
  157. break;
  158. #endif
  159. #if defined(USB_CAN_BE_HOST)
  160. case USB_INT_HSOFI:
  161. AVR32_USBB.UHINTECLR.hsofiec = true;
  162. break;
  163. case USB_INT_DCONNI:
  164. AVR32_USBB.UHINTECLR.dconniec = true;
  165. break;
  166. case USB_INT_DDISCI:
  167. AVR32_USBB.UHINTECLR.ddisciec = true;
  168. break;
  169. case USB_INT_RSTI:
  170. AVR32_USBB.UHINTECLR.rstiec = true;
  171. break;
  172. case USB_INT_BCERRI:
  173. AVR32_USBB.USBCON.bcerre = false;
  174. break;
  175. case USB_INT_VBERRI:
  176. AVR32_USBB.USBCON.vberre = false;
  177. break;
  178. #endif
  179. default:
  180. break;
  181. }
  182. }
  183. static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
  184. static inline void USB_INT_Clear(const uint8_t Interrupt)
  185. {
  186. switch (Interrupt)
  187. {
  188. case USB_INT_VBUSTI:
  189. AVR32_USBB.USBSTACLR.vbustic = true;
  190. (void)AVR32_USBB.USBSTACLR;
  191. break;
  192. #if defined(USB_CAN_BE_BOTH)
  193. case USB_INT_IDTI:
  194. AVR32_USBB.USBSTACLR.idtic = true;
  195. (void)AVR32_USBB.USBSTACLR;
  196. break;
  197. #endif
  198. #if defined(USB_CAN_BE_DEVICE)
  199. case USB_INT_WAKEUPI:
  200. AVR32_USBB.UDINTCLR.wakeupc = true;
  201. (void)AVR32_USBB.UDINTCLR;
  202. break;
  203. case USB_INT_SUSPI:
  204. AVR32_USBB.UDINTCLR.suspc = true;
  205. (void)AVR32_USBB.UDINTCLR;
  206. break;
  207. case USB_INT_EORSTI:
  208. AVR32_USBB.UDINTCLR.eorstc = true;
  209. (void)AVR32_USBB.UDINTCLR;
  210. break;
  211. case USB_INT_SOFI:
  212. AVR32_USBB.UDINTCLR.sofc = true;
  213. (void)AVR32_USBB.UDINTCLR;
  214. break;
  215. case USB_INT_RXSTPI:
  216. (&AVR32_USBB.UESTA0CLR)[USB_Endpoint_SelectedEndpoint].rxstpic = true;
  217. break;
  218. #endif
  219. #if defined(USB_CAN_BE_HOST)
  220. case USB_INT_HSOFI:
  221. AVR32_USBB.UHINTCLR.hsofic = true;
  222. (void)AVR32_USBB.UHINTCLR;
  223. break;
  224. case USB_INT_DCONNI:
  225. AVR32_USBB.UHINTCLR.dconnic = true;
  226. (void)AVR32_USBB.UHINTCLR;
  227. break;
  228. case USB_INT_DDISCI:
  229. AVR32_USBB.UHINTCLR.ddiscic = true;
  230. (void)AVR32_USBB.UHINTCLR;
  231. break;
  232. case USB_INT_RSTI:
  233. AVR32_USBB.UHINTCLR.rstic = true;
  234. (void)AVR32_USBB.UHINTCLR;
  235. break;
  236. case USB_INT_BCERRI:
  237. AVR32_USBB.USBSTACLR.bcerric = true;
  238. (void)AVR32_USBB.USBSTACLR;
  239. break;
  240. case USB_INT_VBERRI:
  241. AVR32_USBB.USBSTACLR.vberric = true;
  242. (void)AVR32_USBB.USBSTACLR;
  243. break;
  244. #endif
  245. default:
  246. break;
  247. }
  248. }
  249. static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
  250. static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
  251. {
  252. switch (Interrupt)
  253. {
  254. case USB_INT_VBUSTI:
  255. return AVR32_USBB.USBCON.vbuste;
  256. #if defined(USB_CAN_BE_BOTH)
  257. case USB_INT_IDTI:
  258. return AVR32_USBB.USBCON.idte;
  259. #endif
  260. #if defined(USB_CAN_BE_DEVICE)
  261. case USB_INT_WAKEUPI:
  262. return AVR32_USBB.UDINTE.wakeupe;
  263. case USB_INT_SUSPI:
  264. return AVR32_USBB.UDINTE.suspe;
  265. case USB_INT_EORSTI:
  266. return AVR32_USBB.UDINTE.eorste;
  267. case USB_INT_SOFI:
  268. return AVR32_USBB.UDINTE.sofe;
  269. case USB_INT_RXSTPI:
  270. return (&AVR32_USBB.UECON0)[USB_Endpoint_SelectedEndpoint].rxstpe;
  271. #endif
  272. #if defined(USB_CAN_BE_HOST)
  273. case USB_INT_HSOFI:
  274. return AVR32_USBB.UHINTE.hsofie;
  275. case USB_INT_DCONNI:
  276. return AVR32_USBB.UHINTE.dconnie;
  277. case USB_INT_DDISCI:
  278. return AVR32_USBB.UHINTE.ddiscie;
  279. case USB_INT_RSTI:
  280. return AVR32_USBB.UHINTE.rstie;
  281. case USB_INT_BCERRI:
  282. return AVR32_USBB.USBCON.bcerre;
  283. case USB_INT_VBERRI:
  284. return AVR32_USBB.USBCON.vberre;
  285. #endif
  286. default:
  287. return false;
  288. }
  289. }
  290. static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
  291. static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
  292. {
  293. switch (Interrupt)
  294. {
  295. case USB_INT_VBUSTI:
  296. return AVR32_USBB.USBSTA.vbusti;
  297. #if defined(USB_CAN_BE_BOTH)
  298. case USB_INT_IDTI:
  299. return AVR32_USBB.USBSTA.idti;
  300. #endif
  301. #if defined(USB_CAN_BE_DEVICE)
  302. case USB_INT_WAKEUPI:
  303. return AVR32_USBB.UDINT.wakeup;
  304. case USB_INT_SUSPI:
  305. return AVR32_USBB.UDINT.susp;
  306. case USB_INT_EORSTI:
  307. return AVR32_USBB.UDINT.eorst;
  308. case USB_INT_SOFI:
  309. return AVR32_USBB.UDINT.sof;
  310. case USB_INT_RXSTPI:
  311. return (&AVR32_USBB.UESTA0)[USB_Endpoint_SelectedEndpoint].rxstpi;
  312. #endif
  313. #if defined(USB_CAN_BE_HOST)
  314. case USB_INT_HSOFI:
  315. return AVR32_USBB.UHINT.hsofi;
  316. case USB_INT_DCONNI:
  317. return AVR32_USBB.UHINT.dconni;
  318. case USB_INT_DDISCI:
  319. return AVR32_USBB.UHINT.ddisci;
  320. case USB_INT_RSTI:
  321. return AVR32_USBB.UHINT.rsti;
  322. case USB_INT_BCERRI:
  323. return AVR32_USBB.USBSTA.bcerri;
  324. case USB_INT_VBERRI:
  325. return AVR32_USBB.USBSTA.vberri;
  326. #endif
  327. default:
  328. return false;
  329. }
  330. }
  331. /* Includes: */
  332. #include "../USBMode.h"
  333. #include "../Events.h"
  334. #include "../USBController.h"
  335. /* Function Prototypes: */
  336. void USB_INT_ClearAllInterrupts(void);
  337. void USB_INT_DisableAllInterrupts(void);
  338. #endif
  339. /* Public Interface - May be used in end-application: */
  340. /* Function Prototypes: */
  341. #if defined(__DOXYGEN__)
  342. /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
  343. * linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
  344. * using the user application's preferred USB controller driver.
  345. */
  346. void USB_GEN_vect(void);
  347. #else
  348. ISR(USB_GEN_vect);
  349. #endif
  350. /* Disable C linkage for C++ Compilers: */
  351. #if defined(__cplusplus)
  352. }
  353. #endif
  354. #endif