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 232 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().

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

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 217 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().

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


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 106 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 161 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 138 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 Fri Feb 19 02:27:53 2010 for AVR32 - USB Enumeration Example by  doxygen 1.5.5