usb-msc-bulk.h
00001 #ifndef __USB_MSC_BULK_H__SHSP6ONHDJ__
00002 #define __USB_MSC_BULK_H__SHSP6ONHDJ__
00003
00004 #include <usb.h>
00005 #include <stdint.h>
00006 #include <msc/msc-defs.h>
00007
00008 #define USB_MSC_BUFFERS 16
00009
00010
00011 struct usb_msc_bulk_cbw
00012 {
00013 uint32_t dCBWSignature;
00014 uint32_t dCBWTag;
00015 uint32_t dCBWDataTransferLength;
00016 uint8_t bmCBWFlags;
00017 uint8_t bCBWLUN;
00018 uint8_t bCBWCBLength;
00019 uint8_t CBWCB[16];
00020 } BYTE_ALIGNED;
00021
00022 struct usb_msc_bulk_csw
00023 {
00024 uint32_t dCSWSignature;
00025 uint32_t dCSWTag;
00026 uint32_t dCSWDataResidue;
00027 uint8_t bCSWStatus;
00028 } BYTE_ALIGNED;
00029
00030 struct usb_msc_command_state
00031 {
00032 const uint8_t *command;
00033 unsigned int command_length;
00034 unsigned int status;
00035
00036 unsigned int cmd_data_transfered;
00037
00038 unsigned int cmd_data_submitted;
00039
00040 void (*data_cb)(struct usb_msc_command_state *state);
00041 };
00042
00043 void
00044 usb_msc_bulk_setup();
00045
00046 typedef enum {
00047 USB_MSC_HANDLER_OK = 0,
00048 USB_MSC_HANDLER_DELAYED,
00049 USB_MSC_HANDLER_FAILED
00050 } usb_msc_handler_status;
00051
00052 usb_msc_handler_status
00053 usb_msc_handle_command(struct usb_msc_command_state *state);
00054
00055 void
00056 usb_msc_command_handler_init();
00057
00058
00059 #define USB_MSC_DATA_DO_CALLBACK 0x20
00060
00061
00062 #define USB_MSC_DATA_SEND 0x40
00063
00064
00065 #define USB_MSC_DATA_RECEIVE 0x40
00066
00067
00068 #define USB_MSC_DATA_LAST 0x80
00069
00070
00071
00072
00073 void
00074 usb_msc_send_data(const uint8_t *data, unsigned int len, unsigned int flags);
00075
00076
00077
00078 void
00079 usb_msc_send_data_buf_flags(const uint8_t *data, unsigned int len,
00080 unsigned int flags, uint16_t buf_flags);
00081
00082 #define USB_MSC_SEND_ABORT() \
00083 usb_msc_send_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
00084
00085
00086
00087 void
00088 usb_msc_receive_data(uint8_t *data, unsigned int len, unsigned int flags);
00089
00090
00091
00092 void
00093 usb_msc_receive_data_buf_flags(uint8_t *data, unsigned int len,
00094 unsigned int flags, uint16_t buf_flags);
00095 #define USB_MSC_RECEIVE_ABORT() \
00096 usb_msc_receive_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
00097
00098 #define USB_MSC_DONE() \
00099 usb_msc_send_data_buf_flags(NULL, 0, USB_MSC_DATA_LAST, 0)
00100
00101
00102
00103 #endif