More AVR32 achitecture ports.
[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_INTC_REG(int) |= USB_INT_GET_INTC_MASK(int); }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 #define USB_INT_GET_INTC_REG(a, b, c, d) *( (volatile uint32_t*)AVR32_USBB_ ## c ## CLR )
74 #define USB_INT_GET_INTC_MASK(a, b, c, d) AVR32_USBB_ ## d ## C
75
76 #define USB_INT_VBUS USBCON, USBCON_VBUSTE_MASK, USBSTA, USBSTA_VBUSTI_MASK
77 #define USB_INT_IDTI USBCON, USBCON_IDTE_MASK , USBSTA, USBCON_IDTI_MASK
78 #define USB_INT_WAKEUP UDIEN , UDIEN_WAKEUPE_MASK, UDINT , UDIEN_WAKEUPI_MASK
79 #define USB_INT_SUSPEND UDIEN , UDIEN_SUSPE_MASK , UDINT , UDIEN_SUSPI_MASK
80 #define USB_INT_EORSTI UDIEN , UDIEN_EORSTE_MASK , UDINT , UDIEN_EORSTI_MASK
81 #define USB_INT_SOFI UDIEN, UDIEN_SOFE_MASK , UDINT , UDIEN_SOFI_MASK
82 #define USB_INT_DCONNI UHIEN , UDIEN_DCONNE_MASK , UHINT , UHIEN_DCONNI_MASK
83 #define USB_INT_DDISCI UHIEN , UDIEN_DDISCE_MASK , UHINT , UHIEN_DDISCI_MASK
84 #define USB_INT_HSOFI UHIEN, UHIEN_HSOFE_MASK , UHINT , UHIEN_HSOFI_MASK
85 #define USB_INT_RSTI UHIEN , UHIEN_RSTE_MASK , UHINT , UHIEN_RSTI_MASK
86 #define USB_INT_RXSTPI UECONX, UECONX_RXSTPE_MASK, UESTAX, UESTAX_RXSTPI_MASK
87 #define USB_INT_BCERRI USBCON, USBCON_BCERRE_MASK, USBSTA, USBSTA_BCERRI_MASK
88 #define USB_INT_VBERRI USBCON, USBCON_VBERRE_MASK, USBSTA, USBSTA_VBERRI_MASK
89 #define USB_INT_SRPI USBCON, USBCON_SRPE_MASK , USBSTA, USBSTA_SRPI_MASK
90 #elif defined(__AVR__)
91 #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
92 #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
93 #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
94 #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
95 #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
96
97 #define USB_INT_GET_EN_REG(a, b, c, d) a
98 #define USB_INT_GET_EN_MASK(a, b, c, d) b
99 #define USB_INT_GET_INT_REG(a, b, c, d) c
100 #define USB_INT_GET_INT_MASK(a, b, c, d) d
101
102 #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
103 #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
104 #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
105 #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
106 #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
107 #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
108 #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
109 #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
110 #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
111 #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
112 #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
113 #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
114 #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
115 #define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
116 #endif
117
118 /* Function Prototypes: */
119 void USB_INT_ClearAllInterrupts(void);
120 void USB_INT_DisableAllInterrupts(void);
121 #endif
122
123 /* Disable C linkage for C++ Compilers: */
124 #if defined(__cplusplus)
125 }
126 #endif
127
128 #endif