Contiki 2.6

usb-api.h

00001 #ifndef __USB_API_H__SYN81IFYBN__
00002 #define __USB_API_H__SYN81IFYBN__
00003 
00004 #include <sys/process.h>
00005 
00006 typedef struct _USBBuffer USBBuffer;
00007 
00008 struct _USBBuffer
00009 {
00010   USBBuffer *next;      /* Pointer to next buffer in chain */
00011   uint8_t *data;        /* Where to read/write data next */
00012   uint16_t left;        /* Remaining length of buffer. */
00013   uint16_t flags;
00014   uint32_t id;  /* User data */
00015 };
00016 
00017 /* Buffer owned by the USB code, cleared when done */
00018 #define USB_BUFFER_SUBMITTED 0x01
00019 
00020 /* Write a short packet at end of buffer or release buffer when a
00021    short packet is received. */
00022 #define USB_BUFFER_SHORT_END 0x02
00023 
00024 /* Release buffer as soon as any received data has been written in it. */
00025 #define USB_BUFFER_PACKET_END 0x04
00026 
00027 /* Notify the user when the buffer is released */
00028 #define USB_BUFFER_NOTIFY 0x08
00029 
00030 /* Packet should be sent to host. */
00031 #define USB_BUFFER_IN 0x40
00032 
00033 /* Used for receiving SETUP packets. If a SETUP packet is received and
00034    the next buffers doesn't have this flag set, they will be skipped
00035    until one is found. The associated buffer must be at least 8 bytes */
00036 #define USB_BUFFER_SETUP 0x20
00037 
00038 /* HALT the endpoint at this point. Only valid for bulk and interrupt
00039    endpoints */
00040 #define USB_BUFFER_HALT 0x100
00041 
00042 /* Flags set by system */
00043 
00044 /* The last packet written to this buffer was short. */
00045 #define USB_BUFFER_SHORT_PACKET 0x10
00046 
00047 /* The operation associated with this buffer failed. I.e. it was discarded since it didn't match the received SETUP packet. */
00048 #define USB_BUFFER_FAILED 0x80
00049 
00050 /* Architecture specific flags */
00051 #define USB_BUFFER_ARCH_FLAG_1 0x1000
00052 #define USB_BUFFER_ARCH_FLAG_2 0x2000
00053 #define USB_BUFFER_ARCH_FLAG_3 0x4000
00054 #define USB_BUFFER_ARCH_FLAG_4 0x8000
00055 
00056 void
00057 usb_setup(void);
00058 
00059 
00060 /* Read only */
00061 struct USBRequestHandler
00062 {
00063   uint8_t request_type;
00064   uint8_t request_type_mask;
00065   uint8_t request;
00066   uint8_t request_mask;
00067   /* Returns true if it handled the request, if false let another handler try*/
00068   unsigned int (*handler_func)();
00069 };
00070   
00071 /* Must be writeable */
00072 struct USBRequestHandlerHook
00073 {
00074   struct USBRequestHandlerHook *next;
00075   const struct USBRequestHandler * const handler;
00076 };
00077 
00078 void
00079 usb_register_request_handler(struct USBRequestHandlerHook *hook);
00080 
00081 void
00082 usb_prepend_request_handler(struct USBRequestHandlerHook *hook);
00083 
00084 void
00085 usb_setup_bulk_endpoint(uint8_t addr);
00086 void
00087 usb_setup_interrupt_endpoint(uint8_t addr);
00088 
00089 /* Submit a chain of buffers to be filled with received data. Last
00090    buffer must have next set to NULL. */
00091 void
00092 usb_submit_recv_buffer(uint8_t ep_addr, USBBuffer *buffer);
00093 
00094 /* Submit a chain of buffers to be sent. Last buffer must have next
00095    set to NULL. When submitting packets to receive or send data in on
00096    a control enpoint, all packets in the data stage must be submitted
00097    at the same time. */
00098 void
00099 usb_submit_xmit_buffer(uint8_t ep_addr, USBBuffer *buffer);
00100 
00101 /* Return true if not all data has been sent to the host */
00102 int 
00103 usb_send_pending(uint8_t ep_addr);
00104 
00105 /* Release all buffers submitted to the endpoint and discard any
00106    buffered data. */
00107 void
00108 usb_discard_all_buffers(uint8_t ep_addr);
00109 
00110 void
00111 usb_disable_endpoint(uint8_t addr);
00112 
00113 /* Set or remove a HALT condition on an endpoint */
00114 void
00115 usb_halt_endpoint(uint8_t addr, int halt);
00116 
00117 /* Select what process should be polled when buffers with the
00118    USB_BUFFER_NOTIFY flag set is released from the endpoint */
00119 void
00120 usb_set_ep_event_process(uint8_t addr, struct process *p);
00121 
00122 /* Select what process should be polled when a global event occurs */
00123 void
00124 usb_set_global_event_process(struct process *p);
00125 
00126 /* Global events */
00127 #define USB_EVENT_CONFIG 0x01 
00128 #define USB_EVENT_SUSPEND 0x02 
00129 #define USB_EVENT_RESUME 0x04
00130 #define USB_EVENT_RESET 0x08
00131 
00132 /* Returns global events that has occured since last time this
00133    function was called */
00134 unsigned int
00135 usb_get_global_events(void);
00136 
00137 
00138 #define USB_EP_EVENT_NOTIFICATION 0x01
00139 unsigned int
00140 usb_get_ep_events(uint8_t addr);
00141 
00142 unsigned int
00143 usb_get_current_configuration(void);
00144 
00145 #endif /* __USB_API_H__SYN81IFYBN__ */