root / lab4 / .minix-src / include / minix / usb.h @ 14
History | View | Annotate | Download (3.79 KB)
1 |
#ifndef _MINIX_USB_H
|
---|---|
2 |
#define _MINIX_USB_H
|
3 |
|
4 |
#include <sys/types.h> |
5 |
#include <minix/com.h> |
6 |
#include <minix/ipc.h> |
7 |
#include <stdio.h> |
8 |
|
9 |
#define USB_URBSIZE(data_size, iso_count) \
|
10 |
(data_size + sizeof(struct usb_urb) + iso_count * \ |
11 |
sizeof(struct usb_iso_packet_desc)) |
12 |
|
13 |
#define USB_PREPARE_URB(urb, data_size, iso_count) \
|
14 |
do { \
|
15 |
if(iso_count)\
|
16 |
urb->iso_data.iso_desc = data_size;\ |
17 |
urb->urb_size = data_size+sizeof(struct usb_urb)+iso_count * \ |
18 |
sizeof(struct usb_iso_packet_desc); \ |
19 |
} while (0) |
20 |
|
21 |
|
22 |
struct usb_urb;
|
23 |
|
24 |
struct usb_driver {
|
25 |
void (*urb_completion)(struct usb_urb *urb); |
26 |
void (*connect_device)(unsigned dev_id, unsigned int interfaces); |
27 |
void (*disconnect_device)(unsigned dev_id); |
28 |
}; |
29 |
|
30 |
struct usb_device_id {
|
31 |
u16_t idVendor; |
32 |
u16_t idProduct; |
33 |
u32_t bcdDevice; |
34 |
|
35 |
u8_t bDeviceClass; |
36 |
u8_t bDeviceSubClass; |
37 |
u8_t bDeviceProtocol; |
38 |
|
39 |
u8_t bInterfaceClass; |
40 |
u8_t bInterfaceSubClass; |
41 |
u8_t bInterfaceProtocol; |
42 |
}; |
43 |
|
44 |
struct usb_iso_packet_desc {
|
45 |
unsigned int offset; |
46 |
unsigned int length; /* expected length */ |
47 |
unsigned int actual_length; |
48 |
unsigned int status; |
49 |
}; |
50 |
|
51 |
/** isochronous transfer */
|
52 |
#define USB_TRANSFER_ISO 0 |
53 |
/** interrupt transfer */
|
54 |
#define USB_TRANSFER_INT 1 |
55 |
/** control transfer */
|
56 |
#define USB_TRANSFER_CTL 2 |
57 |
/** bulk transfer */
|
58 |
#define USB_TRANSFER_BLK 3 |
59 |
|
60 |
#define USB_IN 0 |
61 |
#define USB_OUT 1 |
62 |
|
63 |
#define USB_INVALID_URB_ID 0 |
64 |
|
65 |
struct usb_urb {
|
66 |
/* private */
|
67 |
struct usb_urb *next;
|
68 |
|
69 |
/** ID identifying the device on HCD side */
|
70 |
int dev_id;
|
71 |
int type;
|
72 |
int endpoint;
|
73 |
int direction;
|
74 |
int status;
|
75 |
int error_count;
|
76 |
size_t size; |
77 |
size_t actual_length; |
78 |
void *priv;
|
79 |
int interval;
|
80 |
|
81 |
unsigned long transfer_flags; |
82 |
|
83 |
|
84 |
/* housekeeping information needed by usb library */
|
85 |
unsigned urb_id;
|
86 |
size_t urb_size; |
87 |
cp_grant_id_t gid; |
88 |
|
89 |
size_t iso_desc_offset; |
90 |
int number_of_packets;
|
91 |
int start_frame;
|
92 |
char setup_packet[8]; |
93 |
|
94 |
/* data allways starts here */
|
95 |
char buffer[1]; |
96 |
}; |
97 |
|
98 |
struct usb_ctrlrequest {
|
99 |
u8_t bRequestType; |
100 |
u8_t bRequest; |
101 |
u16_t wValue; |
102 |
u16_t wIndex; |
103 |
u16_t wLength; |
104 |
} __attribute__ ((packed)); |
105 |
|
106 |
#ifdef DEBUG
|
107 |
static void dump_urb(struct usb_urb *urb) { |
108 |
printf("================\n");
|
109 |
printf("DUMP: urb (0x%p)\n", urb);
|
110 |
printf("================\n");
|
111 |
printf("= dev_id: %d\n", urb->dev_id);
|
112 |
printf("= type: %d\n", urb->type);
|
113 |
printf("= endpoint: %d\n", urb->endpoint);
|
114 |
printf("= direction: %d\n", urb->direction);
|
115 |
printf("= status: %d\n", urb->status);
|
116 |
printf("= error_count: %d\n", urb->error_count);
|
117 |
printf("= size: %d\n", urb->size);
|
118 |
printf("= actual_length: %d\n", urb->actual_length);
|
119 |
printf("= interval %d\n", urb->interval);
|
120 |
printf("= transfer_flags %x\n", urb->transfer_flags);
|
121 |
printf("= urb_id = %d\n", urb->urb_id);
|
122 |
printf("= urb_size = 0x%x\n", urb->urb_size);
|
123 |
printf("= setup_packet: \n");
|
124 |
printf("= bRequestType: 0x%x \n",
|
125 |
((struct usb_ctrlrequest *)urb->setup_packet)->bRequestType);
|
126 |
printf("= bRequest 0x%x \n",
|
127 |
((struct usb_ctrlrequest *)urb->setup_packet)->bRequest);
|
128 |
printf("= wValue: 0x%x \n",
|
129 |
((struct usb_ctrlrequest *)urb->setup_packet)->wValue);
|
130 |
printf("= wIndex: 0x%x \n",
|
131 |
((struct usb_ctrlrequest *)urb->setup_packet)->wIndex);
|
132 |
printf("= wLength: 0x%x \n",
|
133 |
((struct usb_ctrlrequest *)urb->setup_packet)->wLength);
|
134 |
printf("===============\n");
|
135 |
} |
136 |
#else
|
137 |
#define dumb_urb(x)
|
138 |
#endif
|
139 |
|
140 |
/** Submit a URB */
|
141 |
int usb_send_urb(struct usb_urb* urb); |
142 |
|
143 |
/** Cancels an URB */
|
144 |
int usb_cancle_urb(struct usb_urb* urb); |
145 |
|
146 |
/** Gets the USB device ID of an USB device **/
|
147 |
int usb_get_device_id(int dev_id, struct usb_device_id *usb_device_id); |
148 |
|
149 |
/* this initializes a session with the HCD */
|
150 |
int usb_init(char *name); |
151 |
|
152 |
/** This functions handles a message from the HCD */
|
153 |
int usb_handle_msg(struct usb_driver *ubd, message *msg); |
154 |
|
155 |
/** Lets device driver send HCD various information */
|
156 |
int usb_send_info(long, long); |
157 |
|
158 |
#endif /* _MINIX_USB_H */ |