usb_device_task.c File Reference


Detailed Description

Management of the USB device controller.

The USB task checks the income of new requests from the USB host. When a setup request occurs, this task launches the processing of this setup contained in the usb_standard_request.c file. Other class-specific requests are also processed in this file.

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

Definition in file usb_device_task.c.

#include "conf_usb.h"
#include "compiler.h"
#include "usb_drv.h"
#include "usb_task.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "usb_device_task.h"

Go to the source code of this file.

Functions

void usb_device_task (void)
 Entry point of the USB device mamagement.
void usb_device_task_init (void)
 This function initializes the USB device controller.
void usb_start_device (void)
 This function starts the USB device controller.

Variables

volatile Bool usb_connected
 Public : (Bool) usb_connected usb_connected is set to TRUE when VBus has been detected usb_connected is set to FALSE otherwise.


Function Documentation

void usb_device_task ( void   ) 

Entry point of the USB device mamagement.

This function is the entry point of the USB management. Each USB event is checked here in order to launch the appropriate action. If a Setup request occurs on the Default Control Endpoint, the usb_process_request() function is call in the usb_standard_request.c file

Definition at line 172 of file usb_device_task.c.

References usb_connected, usb_start_device(), and Usb_vbus_on_action.

Referenced by usb_device_task_init().

00174 {
00175 #ifdef FREERTOS_USED
00176   portTickType xLastWakeTime;
00177 
00178   xLastWakeTime = xTaskGetTickCount();
00179   while (TRUE)
00180   {
00181     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DEV_PERIOD);
00182 
00183 #endif  // FREERTOS_USED
00184     if (!usb_connected && Is_usb_vbus_high())
00185     {
00186       usb_start_device();
00187       Usb_send_event(EVT_USB_POWERED);
00188       Usb_vbus_on_action();
00189     }
00190 
00191     if (Is_usb_event(EVT_USB_RESET))
00192     {
00193       Usb_ack_event(EVT_USB_RESET);
00194       Usb_reset_endpoint(EP_CONTROL);
00195       usb_configuration_nb = 0;
00196     }
00197 
00198     // Connection to the device enumeration process
00199     if (Is_usb_setup_received())
00200     {
00201       usb_process_request();
00202     }
00203 #ifdef FREERTOS_USED
00204   }
00205 #endif
00206 }

void usb_device_task_init ( void   ) 

This function initializes the USB device controller.

This function enables the USB controller and inits the USB interrupts. The aim is to allow the USB connection detection in order to send the appropriate USB event to the operating mode manager.

Todo:
Implement this on the silicon version

Definition at line 97 of file usb_device_task.c.

References usb_connected, and usb_device_task().

00098 {
00099   usb_connected = FALSE;
00100   usb_configuration_nb = 0;
00102   //Pll_start_auto();
00103   //Wait_pll_ready();
00104   Disable_global_interrupt();
00105   Usb_disable();
00106   (void)Is_usb_enabled();
00107   Enable_global_interrupt();
00108   Usb_disable_otg_pad();
00109   Usb_enable_otg_pad();
00110   Usb_enable();
00111 #if __AVR32_UC3A3256__  || __AVR32_UC3A3128__  || __AVR32_UC3A364__  || \
00112     __AVR32_UC3A3256S__ || __AVR32_UC3A3128S__ || __AVR32_UC3A364S__ || \
00113     __AT32UC3A3256__  || __AT32UC3A3128__  || __AT32UC3A364__ ||        \
00114     __AT32UC3A3256S__ || __AT32UC3A3128S__ || __AT32UC3A364S__
00115   Set_bits(AVR32_USBB_udcon, (3<<10)); // Force Full Speed
00116 # warning Force UC3A3 USB macro to work in Full-Speed.
00117 #endif
00118   Usb_unfreeze_clock();
00119   (void)Is_usb_clock_frozen();
00120   Usb_ack_suspend();  // A suspend condition may be detected right after enabling the USB macro
00121   Usb_enable_vbus_interrupt();
00122   Enable_global_interrupt();
00123 
00124 #ifdef FREERTOS_USED
00125   xTaskCreate(usb_device_task,
00126               configTSK_USB_DEV_NAME,
00127               configTSK_USB_DEV_STACK_SIZE,
00128               NULL,
00129               configTSK_USB_DEV_PRIORITY,
00130               &usb_device_tsk);
00131 #endif  // FREERTOS_USED
00132 }

void usb_start_device ( void   ) 

This function starts the USB device controller.

This function enables the USB controller and inits the USB interrupts. The aim is to allow the USB connection detection in order to send the appropriate USB event to the operating mode manager. Start device function is executed once VBus connection has been detected either by the VBus change interrupt or by the VBus high level.

Definition at line 144 of file usb_device_task.c.

References usb_connected.

Referenced by usb_device_task().

00145 {
00146   Usb_enable_suspend_interrupt();
00147   Usb_enable_reset_interrupt();
00148 
00149 #if (USB_HIGH_SPEED_SUPPORT==DISABLED)
00150   Usb_force_full_speed_mode();
00151 #else
00152   Usb_use_dual_speed_mode();
00153 #endif
00154   
00155   usb_init_device();  // Configure the USB controller EP0
00156   Usb_attach();
00157   usb_connected = TRUE;
00158 }


Variable Documentation

volatile Bool usb_connected

Public : (Bool) usb_connected usb_connected is set to TRUE when VBus has been detected usb_connected is set to FALSE otherwise.

Definition at line 80 of file usb_device_task.c.

Referenced by usb_device_task(), usb_device_task_init(), and usb_start_device().


Generated on Thu Dec 17 20:03:08 2009 for AVR32 - USB AUDIO Example by  doxygen 1.5.5