new global_logger, used in AVR_LOG(), default is stdout/stderr
[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 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include "sim_avr.h"
30
31 enum {
32         USB_IRQ_ATTACH = 0,
33         USB_IRQ_COUNT
34 };
35
36 // add port number to get the real IRQ
37 #define AVR_IOCTL_USB_WRITE AVR_IOCTL_DEF('u','s','b','w')
38 #define AVR_IOCTL_USB_READ AVR_IOCTL_DEF('u','s','b','r')
39 #define AVR_IOCTL_USB_SETUP AVR_IOCTL_DEF('u','s','b','s')
40 #define AVR_IOCTL_USB_RESET AVR_IOCTL_DEF('u','s','b','R')
41 #define AVR_IOCTL_USB_VBUS AVR_IOCTL_DEF('u','s','b','V')
42 #define AVR_IOCTL_USB_GETIRQ() AVR_IOCTL_DEF('u','s','b',' ')
43
44 struct avr_io_usb {
45         uint8_t pipe;   //[in]
46         uint32_t  sz;           //[in/out]
47         uint8_t * buf;  //[in/out]
48 };
49 #define AVR_IOCTL_USB_NAK -2
50 #define AVR_IOCTL_USB_STALL -3
51 #define AVR_IOCTL_USB_OK 0
52
53 typedef struct avr_usb_t {
54         avr_io_t        io;
55         char name;
56         avr_regbit_t    disabled;       // bit in the PRR
57         avr_regbit_t    usbrf;          // bit in the MCUSR
58         avr_io_addr_t   r_usbcon;       // every usb reg is an offset of this.
59         avr_io_addr_t   r_pllcsr;
60
61
62         uint8_t usb_com_vect;
63         uint8_t usb_gen_vect;
64
65         struct usb_internal_state * state;
66 } avr_usb_t;
67
68 void avr_usb_init(avr_t * avr, avr_usb_t * port);
69
70 #ifdef __cplusplus
71 };
72 #endif
73
74 #endif /*__AVR_USB_H__*/