USB task entry point module

Collaboration diagram for USB task entry point module:


Modules

 USB software Events Management
 Standard requests defines

Defines

#define USB_MODE_UNDEFINED   0x00
#define USB_MODE_HOST   0x01
#define USB_MODE_DEVICE   0x02

Functions

void usb_task_init (void)
 This function initializes the USB proces.
void usb_task (void)
 Entry point of the USB mamnagement.

Variables

volatile U16 g_usb_event
U8 g_usb_mode
volatile U8 private_sof_counter

Define Documentation

#define USB_MODE_UNDEFINED   0x00

Definition at line 106 of file usb_task.h.

Referenced by usb_task(), and usb_task_init().

#define USB_MODE_HOST   0x01

Definition at line 107 of file usb_task.h.

Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().

#define USB_MODE_DEVICE   0x02

Definition at line 108 of file usb_task.h.

Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().


Function Documentation

void usb_task_init ( void   ) 

This function initializes the USB proces.

Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the coresponding usb mode initialization function

Parameters:
none 
Returns:
none

Definition at line 140 of file usb_task.c.

References g_old_usb_mode, g_usb_mode, Is_usb_id_device, Usb_ack_id_transition, usb_device_task_init(), Usb_enable_id_interrupt, Usb_enable_regulator, Usb_enable_uid_pin, Usb_force_device_mode, Usb_force_host_mode, USB_MODE_DEVICE, USB_MODE_HOST, and USB_MODE_UNDEFINED.

00141 {
00142    #if (USB_HOST_FEATURE == ENABLED && USB_DEVICE_FEATURE == ENABLED)
00143    U8 delay;
00144    #endif
00145 
00146    #if (USE_USB_PADS_REGULATOR==ENABLE)  // Otherwise assume USB PADs regulator is not used
00147    Usb_enable_regulator();
00148    #endif
00149 
00150 // ---- DUAL ROLE DEVICE USB MODE ---------------------------------------------
00151 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED))
00152    Usb_enable_uid_pin();
00153    delay=PORTA;
00154    g_usb_mode=USB_MODE_UNDEFINED;
00155    if(Is_usb_id_device())
00156    {
00157      g_usb_mode=USB_MODE_DEVICE;
00158      usb_device_task_init();
00159    }
00160    else
00161    {
00162      g_usb_mode=USB_MODE_HOST;
00163      Usb_ack_id_transition(); // REQUIRED !!! Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode)
00164      Usb_enable_id_interrupt();
00165      Enable_interrupt();
00166      usb_host_task_init();
00167    }
00168    g_old_usb_mode=g_usb_mode;   // Store current usb mode, for mode change detection
00169 // -----------------------------------------------------------------------------
00170 
00171 // ---- DEVICE ONLY USB MODE ---------------------------------------------------
00172 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE))
00173    Usb_force_device_mode();
00174    usb_device_task_init();
00175 // -----------------------------------------------------------------------------
00176 
00177 // ---- REDUCED HOST ONLY USB MODE ---------------------------------------------
00178 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED))
00179    Usb_force_host_mode();
00180    usb_host_task_init();
00181 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE))
00182    #error  at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled
00183 #endif
00184 // -----------------------------------------------------------------------------
00185 
00186 
00187 }

Here is the call graph for this function:

void usb_task ( void   ) 

Entry point of the USB mamnagement.

Depending on the USB mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the coresponding usb management function.

Parameters:
none 
Returns:
none

Definition at line 199 of file usb_task.c.

References g_old_usb_mode, g_usb_mode, Is_usb_id_device, LOG_STR_CODE, usb_device_task(), USB_MODE_DEVICE, USB_MODE_HOST, USB_MODE_UNDEFINED, Wdt_change_16ms, and Wdt_change_enable.

00200 {
00201 // ---- DUAL ROLE DEVICE USB MODE ---------------------------------------------
00202 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED))
00203    if(Is_usb_id_device())
00204    { g_usb_mode=USB_MODE_DEVICE;}
00205    else
00206    { g_usb_mode=USB_MODE_HOST;}
00207   // TODO !!! ID pin hot state change
00208   // Preliminary management: HARDWARE RESET !!!
00209    #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE)
00210      // Hot ID transition generates wdt reset
00211       if((g_old_usb_mode!=g_usb_mode))
00212       #ifndef  AVRGCC
00213          {Wdt_change_16ms(); while(1);   LOG_STR_CODE(log_id_change);}
00214       #else
00215          {Wdt_change_enable(); while(1); LOG_STR_CODE(log_id_change);}
00216       #endif
00217 
00218    #endif
00219   g_old_usb_mode=g_usb_mode;   // Store current usb mode, for mode change detection
00220   // Depending on current usb mode, launch the correct usb task (device or host)
00221    switch(g_usb_mode)
00222    {
00223       case USB_MODE_DEVICE:
00224          usb_device_task();
00225          break;
00226       case USB_MODE_HOST:
00227          usb_host_task();
00228          break;
00229       case USB_MODE_UNDEFINED:  // No break !
00230       default:
00231          break;
00232   }
00233 // -----------------------------------------------------------------------------
00234 
00235 // ---- DEVICE ONLY USB MODE ---------------------------------------------------
00236 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE))
00237    usb_device_task();
00238 // -----------------------------------------------------------------------------
00239 
00240 // ---- REDUCED HOST ONLY USB MODE ---------------------------------------------
00241 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED))
00242    usb_host_task();
00243 // -----------------------------------------------------------------------------
00244 
00246 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE))
00247    #error  at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled
00248    #error  otherwise the usb task has nothing to do ...
00249 #endif
00250 // -----------------------------------------------------------------------------
00251 
00252 }

Here is the call graph for this function:


Variable Documentation

volatile U16 g_usb_event

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)

Definition at line 81 of file usb_task.c.

U8 g_usb_mode

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 124 of file usb_task.c.

Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().

volatile U8 private_sof_counter

Private : (U8) private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect timeout in host requests. It must not be modified by the user application tasks. /

Definition at line 110 of file usb_task.c.

Referenced by usb_general_interrupt().


Generated on Fri Jan 26 17:33:10 2007 for Atmel by  doxygen 1.5.1-p1