Contiki 2.6
|
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 /* Number of data bytes received or sent */ 00036 unsigned int cmd_data_transfered; 00037 /* Number of data bytes submitted for transmition or reception */ 00038 unsigned int cmd_data_submitted; 00039 /* Set by command handler or callback */ 00040 void (*data_cb)(struct usb_msc_command_state *state); /* May be NULL */ 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 /* Call data_cb when this data has been sent or received */ 00059 #define USB_MSC_DATA_DO_CALLBACK 0x20 00060 00061 /* Actually send the data, not just buffer it */ 00062 #define USB_MSC_DATA_SEND 0x40 00063 00064 /* Actually receive the data, not just queue buffers for it */ 00065 #define USB_MSC_DATA_RECEIVE 0x40 00066 00067 /* The command don't want to send or receive anymore data */ 00068 #define USB_MSC_DATA_LAST 0x80 00069 00070 /* Submit a buffer with data to send to the host. Use a callback to be 00071 notified when data has been sent. Data is not copied so it must 00072 remain constant while sending. */ 00073 void 00074 usb_msc_send_data(const uint8_t *data, unsigned int len, unsigned int flags); 00075 00076 /* Same as usb_msc_send_data but allows one to set additional flags 00077 in USBBuffer */ 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 /* Submit a buffer for receiving data from the host. Use a callback to 00086 be notified when data has arrived. */ 00087 void 00088 usb_msc_receive_data(uint8_t *data, unsigned int len, unsigned int flags); 00089 00090 /* Same as usb_msc_receive_data but allows one to set additional flags 00091 in USBBuffer */ 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 /* __USB_MSC_BULK_H__SHSP6ONHDJ__ */