Makefiles: Tweaked to build using clang/llvm
[simavr] / simavr / sim / avr_usb.h
1 /* vim: set sts=4:sw=4:ts=4:noexpandtab
2         avr_usb.h
3
4         Copyright 2012 Torbjorn Tyridal <ttyridal@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef AVR_USB_H_
23 #define AVR_USB_H_
24
25 #include "sim_avr.h"
26
27 enum {
28         USB_IRQ_ATTACH = 0,
29         USB_IRQ_COUNT
30 };
31
32 // add port number to get the real IRQ
33 #define AVR_IOCTL_USB_WRITE AVR_IOCTL_DEF('u','s','b','w')
34 #define AVR_IOCTL_USB_READ AVR_IOCTL_DEF('u','s','b','r')
35 #define AVR_IOCTL_USB_SETUP AVR_IOCTL_DEF('u','s','b','s')
36 #define AVR_IOCTL_USB_RESET AVR_IOCTL_DEF('u','s','b','R')
37 #define AVR_IOCTL_USB_VBUS AVR_IOCTL_DEF('u','s','b','V')
38 #define AVR_IOCTL_USB_GETIRQ() AVR_IOCTL_DEF('u','s','b',' ')
39
40 struct avr_io_usb {
41         uint8_t pipe;   //[in]
42         size_t  sz;             //[in/out]
43         uint8_t * buf;  //[in/out]
44 };
45 #define AVR_IOCTL_USB_NAK -2
46 #define AVR_IOCTL_USB_STALL -3
47 #define AVR_IOCTL_USB_OK 0
48
49 typedef struct avr_usb_t {
50         avr_io_t        io;
51         char name;
52         avr_regbit_t    disabled;       // bit in the PRR
53         avr_regbit_t    usbrf;          // bit in the MCUSR
54         avr_io_addr_t   r_usbcon;       // every usb reg is an offset of this.
55         avr_io_addr_t   r_pllcsr;
56
57
58         uint8_t usb_com_vect;
59         uint8_t usb_gen_vect;
60
61         struct usb_internal_state * state;
62 } avr_usb_t;
63
64 void avr_usb_init(avr_t * avr, avr_usb_t * port);
65
66 #endif /* AVR_USB_H_ */