Xmega Application Note


usb_device_task.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00052 #include "config.h"
00053 #include "conf_usb.h"
00054 #include "usb_device_task.h"
00055 #include "usb_task.h"
00056 #include "usb_drv.h"
00057 #include "usb_descriptors.h"
00058 #include "usb_standard_request.h"
00059 
00065 uint8_t usb_connected;
00066 
00067 
00072 extern uint8_t usb_configuration_nb;
00073 
00074 
00081 void usb_device_task_init(void)
00082 {
00083         sei();
00084         Usb_disable();
00085         Usb_enable();
00086         Usb_select_device();
00087         Usb_enable_vbus_interrupt();
00088         sei();
00089         
00090 }
00091 
00100 void usb_start_device (void)
00101 {
00102         Start_PLL();
00103         Wait_pll_ready();
00104         Usb_unfreeze_clock();
00105         Usb_enable_suspend_interrupt();
00106         Usb_enable_reset_interrupt();
00107         usb_init_device();               /* Configure the USB controller EP0 */
00108         Usb_attach();
00109         usb_connected = false;
00110 }
00111 
00112 
00120 void usb_device_task(void)
00121 {
00122         if (Is_usb_vbus_high()&& usb_connected==false)
00123         {
00124                 usb_connected = true;
00125                 Usb_vbus_on_action();
00126                 Usb_send_event(EVT_USB_POWERED);
00127                 Usb_enable_reset_interrupt();
00128                 Usb_attach();
00129         }
00130         
00131         if(Is_usb_event(EVT_USB_RESET))
00132         {
00133                 Usb_ack_event(EVT_USB_RESET);
00134                 Usb_reset_endpoint(0);
00135                 usb_configuration_nb=0;
00136         }
00137         
00138         Usb_select_endpoint(EP_CONTROL);
00139         if (Is_usb_receive_setup())
00140         {
00141                 usb_process_request();
00142         }
00143 }
@DOC_TITLE@
Generated on Mon Jan 18 09:26:08 2010 for AVR1907 Xplain USB Gateway by doxygen 1.5.5