USB task entry point module


Modules

 USB software Events Management
 Macros to manage USB events detected under interrupt.
 Standard requests defines

Defines

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

Functions

void usb_task (void *pvParameters)
 Entry point of the USB mamnagement.
void usb_task_init (void)
 This function initializes the USB process.

Variables

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) Is_usb_event(x) Usb_clear_all_event().
volatile 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.
volatile U32 private_sof_counter
 Private: U8 private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect time-out in host requests.


Define Documentation

#define USB_HIGH_SPEED_SUPPORT   DISABLED

Definition at line 212 of file usb_task.h.

#define USB_MODE_DEVICE   0x01

Definition at line 189 of file usb_task.h.

Referenced by usb_general_interrupt_non_naked(), and usb_task().

#define USB_MODE_HOST   0x02

Definition at line 190 of file usb_task.h.

Referenced by usb_general_interrupt_non_naked(), and usb_task().

#define USB_MODE_UNDEFINED   0x00

Definition at line 188 of file usb_task.h.


Function Documentation

void usb_task ( void *  pvParameters  ) 

Entry point of the USB mamnagement.

Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the corespong USB management function

Definition at line 233 of file usb_task.c.

References g_old_usb_mode, g_usb_mode, Is_usb_id_device, private_sof_counter, usb_device_task_init(), usb_device_tsk, Usb_enable_id_interrupt, Usb_enable_id_pin, Usb_force_device_mode, Usb_force_host_mode, usb_general_interrupt(), usb_host_task_init(), usb_host_tsk, Usb_input_id_pin, USB_INT_LEVEL, USB_MODE_DEVICE, USB_MODE_HOST, Usb_raise_id_transition, and usb_tsk_semphr.

Referenced by main(), and usb_task_init().

00234 {
00235 #endif  // FREERTOS_USED
00236   // Register the USB interrupt handler to the interrupt controller and enable
00237   // the USB interrupt.
00238   Disable_global_interrupt();
00239   INTC_register_interrupt((__int_handler)&usb_general_interrupt, AVR32_USBB_IRQ, USB_INT_LEVEL);
00240   Enable_global_interrupt();
00241 
00242 #ifdef FREERTOS_USED
00243   while (TRUE)
00244   {
00245     // Wait for the semaphore
00246     while (!xSemaphoreTake(usb_tsk_semphr, portMAX_DELAY));
00247 
00248 #endif  // FREERTOS_USED
00249 // ---- DUAL-ROLE DEVICE/HOST USB MODE -----------------------------------------
00250 #if USB_DEVICE_FEATURE == ENABLED && USB_HOST_FEATURE == ENABLED
00251   #ifdef FREERTOS_USED
00252     if (usb_device_tsk) vTaskDelete(usb_device_tsk), usb_device_tsk = NULL;
00253     if (usb_host_tsk) vTaskDelete(usb_host_tsk), usb_host_tsk = NULL;
00254   #endif
00255     Usb_input_id_pin();
00256     Usb_enable_id_pin();
00257     if (Is_usb_id_device())
00258     {
00259       g_usb_mode = USB_MODE_DEVICE;
00260       usb_device_task_init();
00261     }
00262     else
00263     {
00264       private_sof_counter = 0;
00265       g_usb_mode = USB_MODE_HOST;
00266       usb_host_task_init();
00267     }
00268     g_old_usb_mode = g_usb_mode;  // Store current USB mode, for mode change detection
00269     Usb_raise_id_transition();  // Check no ID transition has been missed during initialization
00270     Usb_enable_id_interrupt();
00271     Enable_global_interrupt();
00272 // -----------------------------------------------------------------------------
00273 
00274 // ---- DEVICE-ONLY USB MODE ---------------------------------------------------
00275 #elif USB_DEVICE_FEATURE == ENABLED
00276   #ifdef FREERTOS_USED
00277     if (usb_device_tsk) vTaskDelete(usb_device_tsk), usb_device_tsk = NULL;
00278   #endif
00279     Usb_force_device_mode();
00280     usb_device_task_init();
00281 // -----------------------------------------------------------------------------
00282 
00283 // ---- REDUCED-HOST-ONLY USB MODE ---------------------------------------------
00284 #elif USB_HOST_FEATURE == ENABLED
00285   #ifdef FREERTOS_USED
00286     if (usb_host_tsk) vTaskDelete(usb_host_tsk), usb_host_tsk = NULL;
00287   #endif
00288     private_sof_counter = 0;
00289     Usb_force_host_mode();
00290     usb_host_task_init();
00291 // -----------------------------------------------------------------------------
00292 
00293 // ---- ERROR, NO MODE ENABLED -------------------------------------------------
00294 #else
00295   #error At least one of USB_DEVICE_FEATURE and USB_HOST_FEATURE must be enabled
00296 #endif
00297 // -----------------------------------------------------------------------------
00298 #ifdef FREERTOS_USED
00299   }
00300 #endif
00301 }

void usb_task_init ( void   ) 

This function initializes the USB process.

This function enables the USB controller and init 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. Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the corespong USB mode initialization function

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

Definition at line 218 of file usb_task.c.

References configTSK_USB_NAME, configTSK_USB_PRIORITY, configTSK_USB_STACK_SIZE, usb_task(), and usb_tsk_semphr.

Referenced by main().

00219 {
00220 #ifdef FREERTOS_USED
00221   // Create the semaphore
00222   vSemaphoreCreateBinary(usb_tsk_semphr);
00223 
00224   xTaskCreate(usb_task,
00225               configTSK_USB_NAME,
00226               configTSK_USB_STACK_SIZE,
00227               NULL,
00228               configTSK_USB_PRIORITY,
00229               NULL);
00230 }


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) Is_usb_event(x) Usb_clear_all_event().

Definition at line 107 of file usb_task.c.

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

Referenced by usb_general_interrupt_non_naked(), and usb_task().

volatile U32 private_sof_counter

Private: U8 private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect time-out in host requests.

It must not be modified by the user applicative tasks.

Definition at line 139 of file usb_task.c.

Referenced by host_get_data(), host_get_data_interrupt(), host_get_timeout(), host_send_data(), host_send_data_interrupt(), host_transfer_control(), usb_general_interrupt_non_naked(), usb_pipe_interrupt(), and usb_task().


Generated on Thu Dec 17 20:00:27 2009 for AVR32 - USB Enumeration Example by  doxygen 1.5.5