#include "config.h"
#include "conf_usb.h"
#include "usb_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "lib_mcu/power/power_drv.h"
#include "lib_mcu/wdt/wdt_drv.h"
#include "lib_mcu/pll/pll_drv.h"
#include "modules/usb/device_chap9/usb_device_task.h"
Go to the source code of this file.
Functions | |
void | usb_delay_ms (U8 ms) |
void | usb_task_init (void) |
void | usb_task (void) |
__interrupt void | usb_general_interrupt () |
Variables | |
volatile U16 | g_usb_event = 0 |
Public : U16 g_usb_event usb_connected is used to store USB events detected upon USB general interrupt subroutine Its value is managed by the following macros (See usb_task.h file) Usb_send_event(x) Usb_ack_event(x) Usb_clear_all_event() Is_usb_event(x) Is_not_usb_event(x). | |
bit | usb_connected |
Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected is set to FALSE otherwise Used with USB_DEVICE_FEATURE == ENABLED only /. | |
U8 | usb_configuration_nb |
Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device when its value is different from zero, it means the device mode is enumerated Used with USB_DEVICE_FEATURE == ENABLED only /. | |
U8 | remote_wakeup_feature |
Public : (U8) remote_wakeup_feature Store a host request for remote wake up (set feature received) /. | |
volatile U16 | delay_usb |
The USB task selects the correct USB task (usb_device task or usb_host task to be executed depending on the current mode available. According to USB_DEVICE_FEATURE and USB_HOST_FEATURE value (located in conf_usb.h file) The usb_task can be configured to support USB DEVICE mode or USB Host mode or both for a dual role device application. This module also contains the general USB interrupt subroutine. This subroutine is used to detect asynchronous USB events. Note:
Definition in file usb_task.c.
void usb_delay_ms | ( | U8 | ms | ) |
Definition at line 262 of file usb_task.c.
References delay_usb, and FOSC.
Referenced by usb_general_interrupt().
00263 { 00264 for(;ms;ms--) 00265 { 00266 for(delay_usb=0;delay_usb<FOSC/16;delay_usb++); 00267 } 00268 }
__interrupt void usb_general_interrupt | ( | ) |
USB interrupt subroutine This function is called each time a USB interrupt occurs. The following USB DEVICE events are taken in charge:
For each event, the user can launch an action by completing the associate define (See conf_usb.h file to add action upon events)
Note: Only interrupts events that are enabled are processed
none |
Definition at line 175 of file usb_task.c.
References EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_WAKE_UP, FALSE, Is_pll_ready, Is_reset_interrupt_enabled, Is_resume_interrupt_enabled, Is_sof_interrupt_enabled, Is_suspend_interrupt_enabled, Is_usb_reset, Is_usb_resume, Is_usb_sof, Is_usb_suspend, Is_usb_wake_up, Is_wake_up_interrupt_enabled, Stop_pll, TRUE, Usb_ack_reset, Usb_ack_resume, Usb_ack_sof, Usb_ack_suspend, Usb_ack_wake_up, usb_delay_ms(), Usb_direct_drive_disable, Usb_direct_drive_usb_enable, Usb_disable_resume_interrupt, Usb_disable_wake_up_interrupt, Usb_drive_dp_low, Usb_enable_reset_interrupt, Usb_enable_resume_interrupt, Usb_enable_suspend_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, usb_init_device(), Usb_reset_action, Usb_resume_action, Usb_send_event, Usb_sof_action, Usb_suspend_action, usb_suspended, Usb_unfreeze_clock, Usb_wake_up_action, and Wait_pll_ready.
00177 { 00178 // - Device start of frame received 00179 if (Is_usb_sof() && Is_sof_interrupt_enabled()) 00180 { 00181 Usb_ack_sof(); 00182 Usb_sof_action(); 00183 } 00184 // - Device Suspend event (no more USB activity detected) 00185 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()) 00186 { 00187 usb_suspended=TRUE; 00188 Usb_ack_wake_up(); // clear wake up to detect next event 00189 Usb_send_event(EVT_USB_SUSPEND); 00190 Usb_ack_suspend(); 00191 Usb_enable_wake_up_interrupt(); 00192 Usb_disable_resume_interrupt(); 00193 Usb_freeze_clock(); 00194 Stop_pll(); 00195 Usb_suspend_action(); 00196 } 00197 // - Wake up event (USB activity detected): Used to resume 00198 if (Is_usb_wake_up() && Is_wake_up_interrupt_enabled()) 00199 { 00200 if(Is_pll_ready()==FALSE) 00201 { 00202 #ifdef USE_USB_AUTOBAUD 00203 usb_autobaud(); 00204 #else 00205 Pll_start_auto(); 00206 #endif 00207 Wait_pll_ready(); 00208 } 00209 Usb_unfreeze_clock(); 00210 Usb_ack_wake_up(); 00211 if(usb_suspended) 00212 { 00213 Usb_enable_resume_interrupt(); 00214 Usb_enable_reset_interrupt(); 00215 while(Is_usb_wake_up()) 00216 { 00217 Usb_ack_wake_up(); 00218 } 00219 usb_delay_ms(2); 00220 if(Is_usb_sof() || Is_usb_resume() || Is_usb_reset() ) 00221 { 00222 Usb_disable_wake_up_interrupt(); 00223 Usb_wake_up_action(); 00224 Usb_send_event(EVT_USB_WAKE_UP); 00225 Usb_enable_suspend_interrupt(); 00226 Usb_enable_resume_interrupt(); 00227 Usb_enable_reset_interrupt(); 00228 00229 } 00230 else // Workarround to make the USB enter power down mode again (spurious transcient detected on the USB lines) 00231 { 00232 if(Is_usb_wake_up()) return; 00233 Usb_drive_dp_low(); 00234 Usb_direct_drive_usb_enable(); 00235 Usb_direct_drive_disable(); 00236 Usb_disable_wake_up_interrupt(); 00237 } 00238 } 00239 } 00240 // - Resume state bus detection 00241 if (Is_usb_resume() && Is_resume_interrupt_enabled()) 00242 { 00243 usb_suspended = FALSE; 00244 Usb_disable_wake_up_interrupt(); 00245 Usb_ack_resume(); 00246 Usb_disable_resume_interrupt(); 00247 Usb_resume_action(); 00248 Usb_send_event(EVT_USB_RESUME); 00249 } 00250 // - USB bus reset detection 00251 if (Is_usb_reset()&& Is_reset_interrupt_enabled()) 00252 { 00253 Usb_ack_reset(); 00254 usb_init_device(); 00255 Usb_reset_action(); 00256 Usb_send_event(EVT_USB_RESET); 00257 } 00258 00259 }