Contiki-NG
Loading...
Searching...
No Matches
usb-msc-bulk.h
1#ifndef USB_MSC_BULK_H_SHSP6ONHDJ__
2#define USB_MSC_BULK_H_SHSP6ONHDJ__
3
4#include <usb.h>
5#include <stdint.h>
6#include <msc/msc-defs.h>
7
8#define USB_MSC_BUFFERS 16
9
10
11struct usb_msc_bulk_cbw
12{
13 uint32_t dCBWSignature;
14 uint32_t dCBWTag;
15 uint32_t dCBWDataTransferLength;
16 uint8_t bmCBWFlags;
17 uint8_t bCBWLUN;
18 uint8_t bCBWCBLength;
19 uint8_t CBWCB[16];
20} BYTE_ALIGNED;
21
22struct usb_msc_bulk_csw
23{
24 uint32_t dCSWSignature;
25 uint32_t dCSWTag;
26 uint32_t dCSWDataResidue;
27 uint8_t bCSWStatus;
28} BYTE_ALIGNED;
29
30struct usb_msc_command_state
31{
32 const uint8_t *command;
33 unsigned int command_length;
34 unsigned int status;
35 /* Number of data bytes received or sent */
36 unsigned int cmd_data_transfered;
37 /* Number of data bytes submitted for transmition or reception */
38 unsigned int cmd_data_submitted;
39 /* Set by command handler or callback */
40 void (*data_cb)(struct usb_msc_command_state *state); /* May be NULL */
41};
42
43void
44usb_msc_bulk_setup();
45
46typedef enum {
47 USB_MSC_HANDLER_OK = 0,
48 USB_MSC_HANDLER_DELAYED,
49 USB_MSC_HANDLER_FAILED
50} usb_msc_handler_status;
51
52usb_msc_handler_status
53usb_msc_handle_command(struct usb_msc_command_state *state);
54
55void
56usb_msc_command_handler_init();
57
58/* Call data_cb when this data has been sent or received */
59#define USB_MSC_DATA_DO_CALLBACK 0x20
60
61/* Actually send the data, not just buffer it */
62#define USB_MSC_DATA_SEND 0x40
63
64/* Actually receive the data, not just queue buffers for it */
65#define USB_MSC_DATA_RECEIVE 0x40
66
67/* The command don't want to send or receive anymore data */
68#define USB_MSC_DATA_LAST 0x80
69
70/* Submit a buffer with data to send to the host. Use a callback to be
71 notified when data has been sent. Data is not copied so it must
72 remain constant while sending. */
73void
74usb_msc_send_data(const uint8_t *data, unsigned int len, unsigned int flags);
75
76/* Same as usb_msc_send_data but allows one to set additional flags
77 in USBBuffer */
78void
79usb_msc_send_data_buf_flags(const uint8_t *data, unsigned int len,
80 unsigned int flags, uint16_t buf_flags);
81
82#define USB_MSC_SEND_ABORT() \
83usb_msc_send_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
84
85/* Submit a buffer for receiving data from the host. Use a callback to
86 be notified when data has arrived. */
87void
88usb_msc_receive_data(uint8_t *data, unsigned int len, unsigned int flags);
89
90/* Same as usb_msc_receive_data but allows one to set additional flags
91 in USBBuffer */
92void
93usb_msc_receive_data_buf_flags(uint8_t *data, unsigned int len,
94 unsigned int flags, uint16_t buf_flags);
95#define USB_MSC_RECEIVE_ABORT() \
96 usb_msc_receive_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
97
98#define USB_MSC_DONE() \
99 usb_msc_send_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
100
101
102
103#endif /* USB_MSC_BULK_H_SHSP6ONHDJ__ */