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_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


Detailed Description

This file manages the USB task device.

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:

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

Definition in file usb_task.c.


Function Documentation

void usb_delay_ms ( U8  ms  ) 

Definition at line 259 of file usb_task.c.

References delay_usb, and FOSC.

Referenced by usb_general_interrupt().

00260 {
00261    for(;ms;ms--)
00262    {
00263       for(delay_usb=0;delay_usb<FOSC/16;delay_usb++);
00264    }
00265 }

Here is the caller graph for this function:

__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 172 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.

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

Here is the call graph for this function:


Variable Documentation

volatile U16 delay_usb

Definition at line 111 of file usb_task.c.

Referenced by usb_delay_ms().


Generated on Mon Nov 3 13:13:45 2008 for ATMEL by  doxygen 1.5.3