#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\host_chap9\usb_host_task.h"
#include "modules\usb\device_chap9\usb_device_task.h"
Include dependency graph for usb_task.c:
Go to the source code of this file.
Functions | |
void | usb_task_init (void) |
This function initializes the USB proces. | |
void | usb_task (void) |
Entry point of the USB mamnagement. | |
__interrupt void | usb_general_interrupt () |
USB interrupt subroutine. | |
void | suspend_action (void) |
void | host_suspend_action (void) |
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 /. | |
volatile U8 | private_sof_counter = 0 |
Private : (U8) private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect timeout in host requests. | |
U8 | g_usb_mode = 0x00 |
Public : (U8) g_usb_mode Used in dual role application (both device/host) to store the current mode the usb controller is operating /. | |
U8 | g_old_usb_mode |
Copyright (c) 2006 Atmel.
Please read file license.txt for copyright notice.
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.
|
USB interrupt subroutine. This function is called each time a USB interrupt occurs. The following USB DEVICE events are taken in charge:
The following USB HOST 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
Definition at line 269 of file usb_task.c. References EVT_HOST_DISCONNECTION, EVT_HOST_HWUP, EVT_HOST_SOF, EVT_USB_DEVICE_FUNCTION, EVT_USB_HOST_FUNCTION, EVT_USB_POWERED, EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_UNPOWERED, EVT_USB_WAKE_UP, FALSE, Host_ack_device_connection, Host_ack_device_disconnection, Host_ack_hwup, Host_ack_sof, Host_device_connection_action, Host_device_disconnection_action, host_disable_all_pipe(), Host_disable_hwup_interrupt, Host_hwup_action, Host_sof_action, Is_device_connection, Is_device_disconnection, Is_host_device_connection_interrupt_enabled, Is_host_device_disconnection_interrupt_enabled, Is_host_hwup, Is_host_hwup_interrupt_enabled, Is_host_sof, Is_host_sof_interrupt_enabled, Is_reset_interrupt_enabled, Is_resume_interrupt_enabled, Is_sof_interrupt_enabled, Is_suspend_interrupt_enabled, Is_swake_up_interrupt_enabled, Is_usb_id_device, Is_usb_id_interrupt_enabled, Is_usb_id_transition, Is_usb_reset, Is_usb_resume, Is_usb_sof, Is_usb_suspend, Is_usb_vbus_high, Is_usb_vbus_interrupt_enabled, Is_usb_vbus_transition, Is_usb_wake_up, private_sof_counter, TRUE, Usb_ack_id_transition, Usb_ack_reset, Usb_ack_resume, Usb_ack_sof, Usb_ack_suspend, Usb_ack_vbus_transition, Usb_ack_wake_up, Usb_attach, usb_connected, Usb_disable_resume_interrupt, Usb_disable_wake_up_interrupt, Usb_enable_reset_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, Usb_id_transition_action, usb_init_device(), Usb_reset_action, Usb_resume_action, Usb_send_event, Usb_sof_action, usb_start_device(), Usb_suspend_action, Usb_unfreeze_clock, Usb_vbus_off_action, Usb_vbus_on_action, Usb_wake_up_action, Wait_pll_ready, and Wdt_change_16ms. 00271 { 00272 // ---------- DEVICE events management ----------------------------------- 00273 #if (USB_DEVICE_FEATURE == ENABLED) 00274 //- VBUS state detection 00275 if (Is_usb_vbus_transition() && Is_usb_vbus_interrupt_enabled()) 00276 { 00277 Usb_ack_vbus_transition(); 00278 if (Is_usb_vbus_high()) 00279 { 00280 usb_connected = TRUE; 00281 Usb_vbus_on_action(); 00282 Usb_send_event(EVT_USB_POWERED); 00283 Usb_enable_reset_interrupt(); 00284 usb_start_device(); 00285 Usb_attach(); 00286 } 00287 else 00288 { 00289 Usb_vbus_off_action(); 00290 usb_connected = FALSE; 00291 Usb_send_event(EVT_USB_UNPOWERED); 00292 } 00293 } 00294 // - Device start of frame received 00295 if (Is_usb_sof() && Is_sof_interrupt_enabled()) 00296 { 00297 Usb_ack_sof(); 00298 Usb_sof_action(); 00299 } 00300 // - Device Suspend event (no more USB activity detected) 00301 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()) 00302 { 00303 Usb_ack_suspend(); 00304 Usb_enable_wake_up_interrupt(); 00305 Usb_ack_wake_up(); // clear wake up to detect next event 00306 Usb_freeze_clock(); 00307 Usb_send_event(EVT_USB_SUSPEND); 00308 Usb_suspend_action(); 00309 } 00310 // - Wake up event (USB activity detected): Used to resume 00311 if (Is_usb_wake_up() && Is_swake_up_interrupt_enabled()) 00312 { 00313 Usb_unfreeze_clock(); 00314 Usb_ack_wake_up(); 00315 Usb_disable_wake_up_interrupt(); 00316 Usb_wake_up_action(); 00317 Usb_send_event(EVT_USB_WAKE_UP); 00318 } 00319 // - Resume state bus detection 00320 if (Is_usb_resume() && Is_resume_interrupt_enabled()) 00321 { 00322 Usb_disable_wake_up_interrupt(); 00323 Usb_ack_resume(); 00324 Usb_disable_resume_interrupt(); 00325 Usb_resume_action(); 00326 Usb_send_event(EVT_USB_RESUME); 00327 } 00328 // - USB bus reset detection 00329 if (Is_usb_reset()&& Is_reset_interrupt_enabled()) 00330 { 00331 Usb_ack_reset(); 00332 usb_init_device(); 00333 Usb_reset_action(); 00334 Usb_send_event(EVT_USB_RESET); 00335 } 00336 #endif// End DEVICE FEATURE MODE 00337 00338 // ---------- HOST events management ----------------------------------- 00339 #if (USB_HOST_FEATURE == ENABLED) 00340 // - ID pin change detection 00341 if(Is_usb_id_transition()&&Is_usb_id_interrupt_enabled()) 00342 { 00343 Usb_ack_id_transition(); 00344 if(Is_usb_id_device()) // Going to device mode 00345 { 00346 Usb_send_event(EVT_USB_DEVICE_FUNCTION); 00347 } 00348 else // Going to host mode 00349 { 00350 Usb_send_event(EVT_USB_HOST_FUNCTION); 00351 } 00352 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00353 // Hot ID transition generates wdt reset 00354 Wdt_change_16ms(); while(1); 00355 #endif 00356 Usb_id_transition_action(); 00357 } 00358 // - The device has been disconnected 00359 if(Is_device_disconnection() && Is_host_device_disconnection_interrupt_enabled()) 00360 { 00361 Host_ack_device_disconnection(); 00362 device_state=DEVICE_UNATTACHED; 00363 Usb_send_event(EVT_HOST_DISCONNECTION); 00364 Host_device_disconnection_action(); 00365 } 00366 // - Device connection 00367 if(Is_device_connection() && Is_host_device_connection_interrupt_enabled()) 00368 { 00369 Host_ack_device_connection(); 00370 host_disable_all_pipe(); 00371 Host_device_connection_action(); 00372 } 00373 // - Host Start of frame has been sent 00374 if (Is_host_sof() && Is_host_sof_interrupt_enabled()) 00375 { 00376 Host_ack_sof(); 00377 Usb_send_event(EVT_HOST_SOF); 00378 private_sof_counter++; 00379 Host_sof_action(); 00380 } 00381 // - Host Wake-up has been received 00382 if (Is_host_hwup() && Is_host_hwup_interrupt_enabled()) 00383 { 00384 Host_disable_hwup_interrupt(); // Wake up interrupt should be disable host is now wake up ! 00385 // CAUTION HWUP can be cleared only when USB clock is active! 00386 Pll_start_auto(); // First Restart the PLL for USB operation 00387 Wait_pll_ready(); // Get sure pll is lock 00388 Usb_unfreeze_clock(); // Enable clock on USB interface 00389 Host_ack_hwup(); // Clear HWUP interrupt flag 00390 Usb_send_event(EVT_HOST_HWUP); // Send software event 00391 Host_hwup_action(); // Map custom action 00392 } 00393 #endif // End HOST FEATURE MODE 00394 }
Here is the call graph for this function: ![]() |
|
Definition at line 397 of file usb_task.c. References Enter_power_down_mode. 00398 { 00399 Enable_interrupt(); 00400 Enter_power_down_mode(); 00401 }
|
|
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 /.
Definition at line 46 of file usb_device_task.c. |
|
Public : (U8) g_usb_mode Used in dual role application (both device/host) to store the current mode the usb controller is operating /.
Definition at line 108 of file usb_task.c. Referenced by usb_task(), and usb_task_init(). |
|
Definition at line 109 of file usb_task.c. Referenced by usb_task(), and usb_task_init(). |