Contiki-NG
usb-api.h
1#ifndef USB_API_H_SYN81IFYBN__
2#define USB_API_H_SYN81IFYBN__
3
4#include <sys/process.h>
5
6typedef struct _USBBuffer USBBuffer;
7
8struct _USBBuffer
9{
10 USBBuffer *next; /* Pointer to next buffer in chain */
11 uint8_t *data; /* Where to read/write data next */
12 uint16_t left; /* Remaining length of buffer. */
13 uint16_t flags;
14 uint32_t id; /* User data */
15};
16
17/* Buffer owned by the USB code, cleared when done */
18#define USB_BUFFER_SUBMITTED 0x01
19
20/* Write a short packet at end of buffer or release buffer when a
21 short packet is received. */
22#define USB_BUFFER_SHORT_END 0x02
23
24/* Release buffer as soon as any received data has been written in it. */
25#define USB_BUFFER_PACKET_END 0x04
26
27/* Notify the user when the buffer is released */
28#define USB_BUFFER_NOTIFY 0x08
29
30/* Packet should be sent to host. */
31#define USB_BUFFER_IN 0x40
32
33/* Used for receiving SETUP packets. If a SETUP packet is received and
34 the next buffers doesn't have this flag set, they will be skipped
35 until one is found. The associated buffer must be at least 8 bytes */
36#define USB_BUFFER_SETUP 0x20
37
38/* HALT the endpoint at this point. Only valid for bulk and interrupt
39 endpoints */
40#define USB_BUFFER_HALT 0x100
41
42/* Flags set by system */
43
44/* The last packet written to this buffer was short. */
45#define USB_BUFFER_SHORT_PACKET 0x10
46
47/* The operation associated with this buffer failed. I.e. it was discarded since it didn't match the received SETUP packet. */
48#define USB_BUFFER_FAILED 0x80
49
50/* Architecture specific flags */
51#define USB_BUFFER_ARCH_FLAG_1 0x1000
52#define USB_BUFFER_ARCH_FLAG_2 0x2000
53#define USB_BUFFER_ARCH_FLAG_3 0x4000
54#define USB_BUFFER_ARCH_FLAG_4 0x8000
55
56void
57usb_setup(void);
58
59
60/* Read only */
61struct USBRequestHandler
62{
63 uint8_t request_type;
64 uint8_t request_type_mask;
65 uint8_t request;
66 uint8_t request_mask;
67 /* Returns true if it handled the request, if false let another handler try*/
68 unsigned int (*handler_func)();
69};
70
71/* Must be writeable */
72struct USBRequestHandlerHook
73{
74 struct USBRequestHandlerHook *next;
75 const struct USBRequestHandler * const handler;
76};
77
78void
79usb_register_request_handler(struct USBRequestHandlerHook *hook);
80
81void
82usb_prepend_request_handler(struct USBRequestHandlerHook *hook);
83
84void
85usb_setup_bulk_endpoint(uint8_t addr);
86void
87usb_setup_interrupt_endpoint(uint8_t addr);
88
89/* Submit a chain of buffers to be filled with received data. Last
90 buffer must have next set to NULL. */
91void
92usb_submit_recv_buffer(uint8_t ep_addr, USBBuffer *buffer);
93
94/* Submit a chain of buffers to be sent. Last buffer must have next
95 set to NULL. When submitting packets to receive or send data in on
96 a control enpoint, all packets in the data stage must be submitted
97 at the same time. */
98void
99usb_submit_xmit_buffer(uint8_t ep_addr, USBBuffer *buffer);
100
101/* Return true if not all data has been sent to the host */
102int
103usb_send_pending(uint8_t ep_addr);
104
105/* Release all buffers submitted to the endpoint and discard any
106 buffered data. */
107void
108usb_discard_all_buffers(uint8_t ep_addr);
109
110void
111usb_disable_endpoint(uint8_t addr);
112
113/* Set or remove a HALT condition on an endpoint */
114void
115usb_halt_endpoint(uint8_t addr, int halt);
116
117/* Select what process should be polled when buffers with the
118 USB_BUFFER_NOTIFY flag set is released from the endpoint */
119void
120usb_set_ep_event_process(uint8_t addr, struct process *p);
121
122/* Select what process should be polled when a global event occurs */
123void
124usb_set_global_event_process(struct process *p);
125
126/* Global events */
127#define USB_EVENT_CONFIG 0x01
128#define USB_EVENT_SUSPEND 0x02
129#define USB_EVENT_RESUME 0x04
130#define USB_EVENT_RESET 0x08
131
132/* Returns global events that has occured since last time this
133 function was called */
134unsigned int
135usb_get_global_events(void);
136
137
138#define USB_EP_EVENT_NOTIFICATION 0x01
139unsigned int
140usb_get_ep_events(uint8_t addr);
141
142unsigned int
143usb_get_current_configuration(void);
144
145#endif /* USB_API_H_SYN81IFYBN__ */
Header file for the Contiki process interface.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107