00001
00042 #ifndef AT90USB_INTERNAL_H_INCLUDED
00043 #define AT90USB_INTERNAL_H_INCLUDED
00044
00045 #include <slist.h>
00046 #include <bitops.h>
00047 #include <stdint.h>
00048 #include <workqueue.h>
00049
00050 #include <usb/udc.h>
00051 #include <usb/request.h>
00052
00053 #include <chip/regs.h>
00054
00055 #include "at90usb_regs.h"
00056
00057
00058
00062 enum ep0_state {
00063 EP0_STATE_SETUP = 0,
00064 EP0_STATE_DATA_IN,
00065 EP0_STATE_DATA_ZLP,
00066 EP0_STATE_DATA_OUT,
00067 EP0_STATE_STATUS_IN,
00068 EP0_STATE_STATUS_OUT,
00069 };
00070
00074 enum at90usb_ep_flag {
00075 AT90USB_EP_ALLOCATED,
00076 AT90USB_EP_ACTIVE_XFER,
00077 AT90USB_EP_ENABLED,
00078 AT90USB_EP_IS_IN,
00079 AT90USB_EP_WEDGE,
00080 };
00081
00085 struct at90usb_udc_ep {
00087 uint8_t ueienx;
00089 usb_ep_id_t id;
00091 struct at90usb_udc *udc90;
00093 unsigned int buf_offset;
00095 struct workqueue_task task;
00097 struct slist req_queue;
00099 struct slist buf_queue;
00101 bit_word_t flags;
00103 uint16_t maxpacket;
00105 uint16_t bytes_written;
00106 };
00107
00111 struct at90usb_udc {
00113 struct udc udc;
00115 enum ep0_state ctrl_state;
00117 struct usb_setup_req setup_req;
00119 struct at90usb_controller *at90usb;
00121 struct workqueue_task task;
00123 struct at90usb_udc_ep ep[APP_UDC_NR_ENDPOINTS];
00124 };
00125
00126
00135 static inline bool at90usb_udc_is_enabled(struct at90usb_udc *udc90)
00136 {
00137 #if defined(CONFIG_AT90USB_OTG)
00138 return test_bit(UDC_IS_ENABLED, &udc90->udc.flags);
00139 #elif defined(CONFIG_UDC)
00140 return true;
00141 #else
00142 return false;
00143 #endif
00144 }
00145
00152 static inline void at90usb_udc_enable(struct at90usb_udc *udc90)
00153 {
00154
00155
00156
00157
00158
00159
00160 udc90->udc.flags &= (1 << UDC_IS_ENABLED) | (1 << UDC_AUTOATTACH);
00161 udc90->udc.flags |= (1 << UDC_IS_ENABLED);
00162 }
00163
00170 static inline void at90usb_udc_disable(struct at90usb_udc *udc90)
00171 {
00172
00173
00174
00175
00176 udc90->udc.flags &= (1 << UDC_AUTOATTACH);
00177 }
00178
00179 extern void at90usb_udc_vbus_off(struct at90usb_udc *udc90);
00180 extern void at90usb_udc_vbus_on(struct at90usb_udc *udc90);
00181 extern struct at90usb_udc *at90usb_udc_init(void);
00182 extern void at90usb_udc_shutdown(struct at90usb_udc *udc90);
00183
00184
00185
00189 struct at90usb_host {
00190
00191 uint8_t placeholder;
00192 };
00193
00202 static inline bool at90usb_host_is_enabled(struct at90usb_host *host90)
00203 {
00204 #if defined(CONFIG_AT90USB_OTG)
00205 return test_bit(USB_HOST_IS_ENABLED, &host90->hcd.flags);
00206 #else
00207 return false;
00208 #endif
00209 }
00210
00211 static inline void at90usb_host_enable(struct at90usb_host *host90)
00212 {
00213
00214 }
00215
00216 static inline void at90usb_host_disable(struct at90usb_host *host90)
00217 {
00218
00219 }
00220 extern struct at90usb_host *at90usb_host_init(void);
00221 extern void at90usb_host_shutdown(struct at90usb_host *host90);
00222
00223
00224
00228 struct at90usb_controller {
00229 #ifdef CONFIG_UDC
00230 struct at90usb_udc *udc;
00231 #endif
00232 };
00233
00234 #endif