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