8fb152dd57ed006938c1f09c4c95a3e863c742c1
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / USBInterrupt.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef __USBINTERRUPT_H__
32 #define __USBINTERRUPT_H__
33
34 /* Includes: */
35 #if defined(__AVR32__)
36 #include <avr32/io.h>
37 #include <stdbool.h>
38 #include <stdint.h>
39 #elif defined(__AVR__)
40 #include <avr/io.h>
41 #include <stdbool.h>
42 #endif
43
44 #include "../../../Common/Common.h"
45 #include "../LowLevel/LowLevel.h"
46 #include "USBMode.h"
47 #include "Events.h"
48
49 /* Enable C linkage for C++ Compilers: */
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53
54 /* Preprocessor Checks: */
55 #if !defined(__INCLUDE_FROM_USB_DRIVER)
56 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
57 #endif
58
59 /* Private Interface - For use in library only: */
60 #if !defined(__DOXYGEN__)
61 /* Macros: */
62 #if defined(__AVR32__)
63 #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
64 #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
65 #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) ## CLR |= USB_INT_GET_INT_MASK(int) ## C; }MACROE
66 #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
67 #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
68
69 #define USB_INT_GET_EN_REG(a, b, c, d) *((volatile uint32_t*)AVR32_USBB_ ## a)
70 #define USB_INT_GET_EN_MASK(a, b, c, d) AVR32_USBB_ ## b
71 #define USB_INT_GET_INT_REG(a, b, c, d) *((volatile uint32_t*)AVR32_USBB_ ## c)
72 #define USB_INT_GET_INT_MASK(a, b, c, d) AVR32_USBB_ ## d
73
74 #define USB_INT_VBUS USBCON, USBCON_VBUSTE_MASK, USBSTA, USBSTA_VBUSTI_MASK
75 #define USB_INT_IDTI USBCON, USBCON_IDTE_MASK , USBINT, USBCON_IDTI_MASK
76 #define USB_INT_WAKEUP UDIEN , UDIEN_WAKEUPE_MASK, UDINT , UDIEN_WAKEUPI_MASK
77 #define USB_INT_SUSPEND UDIEN , UDIEN_SUSPE_MASK , UDINT , UDIEN_SUSPI_MASK
78 #define USB_INT_EORSTI UDIEN , UDIEN_EORSTE_MASK , UDINT , UDIEN_EORSTI_MASK
79 #define USB_INT_SOFI UDIEN, UDIEN_SOFE_MASK , UDINT , UDIEN_SOFI_MASK
80 #define USB_INT_DCONNI UHIEN , UDIEN_DCONNE_MASK , UHINT , UHIEN_DCONNI_MASK
81 #define USB_INT_DDISCI UHIEN , UDIEN_DDISCE_MASK , UHINT , UHIEN_DDISCI_MASK
82 #define USB_INT_HSOFI UHIEN, UHIEN_HSOFE_MASK , UHINT , UHIEN_HSOFI_MASK
83 #define USB_INT_RSTI UHIEN , UHIEN_RSTE_MASK , UHINT , UHIEN_RSTI_MASK
84 #define USB_INT_RXSTPI UEIENX, UEIENX_RXSTPE_MASK, UEINTX, UEIENX_RXSTPI_MASK
85 #define USB_INT_BCERRI OTGIEN, OTGIEN_BCERRE_MASK, OTGINT, OTGIEN_BCERRI_MASK
86 #define USB_INT_VBERRI OTGIEN, OTGIEN_VBERRE_MASK, OTGINT, OTGIEN_VBERRI_MASK
87 #define USB_INT_SRPI OTGIEN, OTGIEN_SRPE_MASK , OTGINT, OTGIEN_SRPI_MASK
88 #elif defined(__AVR__)
89 #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
90 #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
91 #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
92 #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
93 #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
94
95 #define USB_INT_GET_EN_REG(a, b, c, d) a
96 #define USB_INT_GET_EN_MASK(a, b, c, d) b
97 #define USB_INT_GET_INT_REG(a, b, c, d) c
98 #define USB_INT_GET_INT_MASK(a, b, c, d) d
99
100 #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
101 #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
102 #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
103 #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
104 #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
105 #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
106 #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
107 #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
108 #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
109 #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
110 #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
111 #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
112 #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
113 #define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
114 #endif
115
116 /* Function Prototypes: */
117 void USB_INT_ClearAllInterrupts(void);
118 void USB_INT_DisableAllInterrupts(void);
119 #endif
120
121 /* Disable C linkage for C++ Compilers: */
122 #if defined(__cplusplus)
123 }
124 #endif
125
126 #endif