usb_task.c File Reference

#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"

Include dependency graph for usb_task.c:

Go to the source code of this file.

Functions

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) /.


Detailed Description

This file manages the USB task device.

This module also contains the general USB interrupt subroutine. This subroutine is used to detect asynchronous USB events. Note:

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file usb_task.c.


Function Documentation

__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

Parameters:
none 
Returns:
none

Definition at line 170 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_disable_resume_interrupt, Usb_disable_wake_up_interrupt, 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.

00172 {
00173   // - Device start of frame received
00174    if (Is_usb_sof() && Is_sof_interrupt_enabled())
00175    {
00176       Usb_ack_sof();
00177       Usb_sof_action();
00178    }
00179   // - Device Suspend event (no more USB activity detected)
00180    if (Is_usb_suspend() && Is_suspend_interrupt_enabled())
00181    {
00182       usb_suspended=TRUE;
00183       Usb_ack_wake_up();                 // clear wake up to detect next event
00184       Usb_send_event(EVT_USB_SUSPEND);
00185       Usb_ack_suspend();
00186       Usb_enable_wake_up_interrupt();
00187       Usb_disable_resume_interrupt();
00188       Usb_freeze_clock();
00189       Stop_pll();
00190       Usb_suspend_action();
00191    }
00192   // - Wake up event (USB activity detected): Used to resume
00193    if (Is_usb_wake_up() && Is_wake_up_interrupt_enabled())
00194    {
00195       if(Is_pll_ready()==FALSE)
00196       {
00197          #ifdef USE_USB_AUTOBAUD
00198             usb_autobaud();
00199          #else
00200             Pll_start_auto();
00201          #endif
00202          Wait_pll_ready();
00203       }
00204       Usb_unfreeze_clock();
00205       Usb_ack_wake_up();
00206       if(usb_suspended)
00207       {
00208 #ifdef WA_USB_SUSPEND_PERTUBATION
00209          Usb_enable_resume_interrupt();
00210          Usb_enable_reset_interrupt();
00211          while(Is_usb_wake_up())
00212          {
00213             Usb_ack_wake_up();
00214          }
00215          usb_delay_ms(2);
00216          if(Is_usb_sof() || Is_usb_resume() || Is_usb_reset() )
00217          {
00218             Usb_disable_wake_up_interrupt();
00219             Usb_wake_up_action();
00220             Usb_send_event(EVT_USB_WAKE_UP);
00221             Usb_enable_suspend_interrupt();
00222             Usb_enable_resume_interrupt();
00223             Usb_enable_reset_interrupt();
00224             
00225          }
00226          else // Workarround to make the USB enter power down mode again (spurious transcient detected on the USB lines)
00227          {
00228             Usb_ack_wake_up();                 // clear wake up to detect next event
00229             Usb_send_event(EVT_USB_SUSPEND);
00230             Usb_ack_suspend();
00231             Usb_enable_wake_up_interrupt();
00232             Usb_disable_resume_interrupt();
00233             Usb_freeze_clock();
00234             Stop_pll();
00235             Usb_suspend_action();
00236          }
00237 #else
00238          Usb_enable_resume_interrupt();
00239          Usb_enable_reset_interrupt();
00240          Usb_ack_wake_up();
00241          Usb_disable_wake_up_interrupt();
00242          Usb_wake_up_action();
00243          Usb_send_event(EVT_USB_WAKE_UP);
00244          Usb_enable_suspend_interrupt();
00245          Usb_enable_resume_interrupt();
00246          Usb_enable_reset_interrupt();
00247 #endif
00248       }
00249    }
00250   // - Resume state bus detection
00251    if (Is_usb_resume() && Is_resume_interrupt_enabled())
00252    {
00253       usb_suspended = FALSE;
00254       Usb_disable_wake_up_interrupt();
00255       Usb_ack_resume();
00256       Usb_disable_resume_interrupt();
00257       Usb_resume_action();
00258       Usb_send_event(EVT_USB_RESUME);
00259    }
00260   // - USB bus reset detection
00261    if (Is_usb_reset()&& Is_reset_interrupt_enabled())
00262    {
00263       Usb_ack_reset();
00264       usb_init_device();
00265       Usb_reset_action();
00266       Usb_send_event(EVT_USB_RESET);
00267    }
00268 
00269 }

Here is the call graph for this function:


Generated on Fri Sep 11 15:02:36 2009 for ATMEL by  doxygen 1.5.3