00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 //_____ I N C L U D E S ___________________________________________________ 00033 00034 #include "config.h" 00035 #include "conf_usb.h" 00036 #include "usb_task.h" 00037 #include "lib_mcu/usb/usb_drv.h" 00038 #if ((USB_DEVICE_FEATURE == ENABLED)) 00039 #include "usb_descriptors.h" 00040 #endif 00041 #include "lib_mcu/power/power_drv.h" 00042 #include "lib_mcu/wdt/wdt_drv.h" 00043 #include "lib_mcu/pll/pll_drv.h" 00044 #include "modules/usb/device_chap9/usb_device_task.h" 00045 00046 #ifndef USE_USB_PADS_REGULATOR 00047 #error "USE_USB_PADS_REGULATOR" should be defined as ENABLE or DISABLE in conf_usb.h file 00048 #endif 00049 00050 //_____ M A C R O S ________________________________________________________ 00051 00052 #ifndef LOG_STR_CODE 00053 #define LOG_STR_CODE(str) 00054 #else 00055 U8 code log_device_disconnect[]="Device Disconnected"; 00056 U8 code log_id_change[]="Pin Id Change"; 00057 #endif 00058 00059 //_____ D E F I N I T I O N S ______________________________________________ 00060 00071 volatile U16 g_usb_event=0; 00072 00073 00074 #if (USB_DEVICE_FEATURE == ENABLED) 00081 extern bit usb_connected; 00082 00089 extern U8 usb_configuration_nb; 00090 #endif 00091 00092 00093 #if (USB_HOST_FEATURE == ENABLED) 00100 volatile U8 private_sof_counter=0; 00101 00102 #if (USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE) 00103 extern volatile S_pipe_int it_pipe_str[MAX_EP_NB]; 00104 #endif 00105 00106 #endif 00107 00108 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) 00114 U8 g_usb_mode=USB_MODE_UNDEFINED; 00115 U8 g_old_usb_mode; 00116 #endif 00117 00118 //_____ D E C L A R A T I O N S ____________________________________________ 00119 00129 void usb_task_init(void) 00130 { 00131 #if (USE_USB_PADS_REGULATOR==ENABLE) // Otherwise assume USB PADs regulator is not used 00132 Usb_enable_regulator(); 00133 #endif 00134 usb_device_task_init(); 00135 #if (USB_REMOTE_WAKEUP == ENABLED) 00136 usb_remote_wup_feature = DISABLED; 00137 #endif 00138 } 00139 00149 void usb_task(void) 00150 { 00151 usb_device_task(); 00152 } 00153 00172 #ifdef AVRGCC 00173 ISR(USB_GEN_vect) 00174 #else 00175 #pragma vector = USB_GENERAL_vect 00176 __interrupt void usb_general_interrupt() 00177 #endif 00178 { 00179 // - Device start of frame received 00180 if (Is_usb_sof() && Is_sof_interrupt_enabled()) 00181 { 00182 Usb_ack_sof(); 00183 Usb_sof_action(); 00184 } 00185 // - Device Suspend event (no more USB activity detected) 00186 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()) 00187 { 00188 Usb_enable_wake_up_interrupt(); 00189 Usb_ack_wake_up(); // clear wake up to detect next event 00190 Usb_freeze_clock(); 00191 Usb_send_event(EVT_USB_SUSPEND); 00192 Usb_suspend_action(); 00193 Usb_ack_suspend(); // must be executed last (after Usb_suspend_action()) to allow upstream resume 00194 } 00195 // - Wake up event (USB activity detected): Used to resume 00196 if (Is_usb_wake_up() && Is_swake_up_interrupt_enabled()) 00197 { 00198 Usb_unfreeze_clock(); 00199 Usb_ack_wake_up(); 00200 Usb_disable_wake_up_interrupt(); 00201 Usb_wake_up_action(); 00202 Usb_send_event(EVT_USB_WAKE_UP); 00203 } 00204 // - Resume state bus detection 00205 if (Is_usb_resume() && Is_resume_interrupt_enabled()) 00206 { 00207 Usb_disable_wake_up_interrupt(); 00208 Usb_ack_resume(); 00209 Usb_disable_resume_interrupt(); 00210 Usb_resume_action(); 00211 Usb_send_event(EVT_USB_RESUME); 00212 } 00213 // - USB bus reset detection 00214 if (Is_usb_reset()&& Is_reset_interrupt_enabled()) 00215 { 00216 #if (USB_REMOTE_WAKEUP == ENABLED) 00217 usb_remote_wup_feature = DISABLED; 00218 #endif 00219 Usb_ack_reset(); 00220 usb_init_device(); 00221 Usb_reset_action(); 00222 Usb_send_event(EVT_USB_RESET); 00223 } 00224 00225 } 00226 00227