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 169 of file usb_device_task.c.

References usb_connected, usb_start_device(), and Usb_vbus_on_action.

Referenced by usb_device_task_init().

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

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 UC3A3
00112   Set_bits(AVR32_USBB_udcon, (3<<10)); // Force Full Speed
00113 # warning Force UC3A3 USB macro to work in Full-Speed.
00114 #endif
00115   Usb_unfreeze_clock();
00116   (void)Is_usb_clock_frozen();
00117   Usb_ack_suspend();  // A suspend condition may be detected right after enabling the USB macro
00118   Usb_enable_vbus_interrupt();
00119   Enable_global_interrupt();
00120 
00121 #ifdef FREERTOS_USED
00122   xTaskCreate(usb_device_task,
00123               configTSK_USB_DEV_NAME,
00124               configTSK_USB_DEV_STACK_SIZE,
00125               NULL,
00126               configTSK_USB_DEV_PRIORITY,
00127               &usb_device_tsk);
00128 #endif  // FREERTOS_USED
00129 }

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 141 of file usb_device_task.c.

References usb_connected.

Referenced by usb_device_task().

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


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 Fri Feb 19 02:32:16 2010 for AVR32 - USB AUDIO Example by  doxygen 1.5.5