host_mass_storage_task.c File Reference


Detailed Description

Management of the USB host mass-storage task.

This file manages the USB host mass-storage task.

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

Definition in file host_mass_storage_task.c.

#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "usb_host_enum.h"
#include "usb_host_task.h"
#include "host_mem.h"
#include "ctrl_access.h"
#include "navigation.h"
#include "host_mass_storage_task.h"

Go to the source code of this file.

Functions

void host_mass_storage_task (void *pvParameters)
 This function manages the host mass-storage task.
void host_mass_storage_task_init (void)
 This function initializes the host mass-storage task.
void host_sof_action (void)
 host_sof_action

Variables

static const char log_ms_dev_connected [] = "Mass-storage device connected\n"
volatile Bool ms_connected
volatile Bool ms_new_device_connected
static U16 sof_cnt


Function Documentation

void host_mass_storage_task ( void *  pvParameters  ) 

This function manages the host mass-storage task.

Definition at line 110 of file host_mass_storage_task.c.

References configTSK_USB_HMS_PERIOD, g_pipe_ms_in, g_pipe_ms_out, host_get_lun(), host_ms_inquiry(), host_ms_request_sense(), host_read_capacity(), host_selected_lun, host_test_unit_ready(), log_ms_dev_connected, LOG_STR, ms_connected, ms_new_device_connected, and sof_cnt.

Referenced by host_mass_storage_task_init(), and main().

00114 {
00115   U8 i;
00116   U8 max_lun;
00117   U32 capacity;
00118 
00119 #ifdef FREERTOS_USED
00120   portTickType xLastWakeTime;
00121 
00122   xLastWakeTime = xTaskGetTickCount();
00123   while (TRUE)
00124   {
00125     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD);
00126 
00127 #endif  // FREERTOS_USED
00128     // First, check the host controller is in full operating mode with the
00129     // B-device attached and enumerated
00130     if (Is_host_ready())
00131     {
00132 #if BOARD == EVK1100
00133       // Display Start-of-Frame counter on LEDs
00134       LED_Display_Field(LED_MONO0_GREEN |
00135                         LED_MONO1_GREEN |
00136                         LED_MONO2_GREEN |
00137                         LED_MONO3_GREEN,
00138                         sof_cnt >> 5);
00139 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105 || BOARD == UC3C_EK
00140       // Display Start-of-Frame counter on LEDs
00141       LED_Display_Field(LED0 |
00142                         LED1,
00143                         sof_cnt >> 5);
00144 #else
00145   #error The display of the SOFs must be defined here.
00146 #endif
00147 
00148       // New device connection (executed only once after device connection)
00149       if (ms_new_device_connected)
00150       {
00151         ms_new_device_connected = FALSE;
00152 
00153         // For all supported interfaces
00154         for (i = 0; i < Get_nb_supported_interface(); i++)
00155         {
00156           // If mass-storage class
00157           if (Get_class(i) == MS_CLASS)
00158           {
00159             ms_connected = TRUE;
00160             LOG_STR(log_ms_dev_connected);
00161 
00162             // Get correct physical pipes associated with IN/OUT endpoints
00163             if (Is_ep_in(i, 0))
00164             { // Yes, associate it with the IN pipe
00165               g_pipe_ms_in = Get_ep_pipe(i, 0);
00166               g_pipe_ms_out = Get_ep_pipe(i, 1);
00167             }
00168             else
00169             { // No, invert...
00170               g_pipe_ms_in = Get_ep_pipe(i, 1);
00171               g_pipe_ms_out = Get_ep_pipe(i, 0);
00172             }
00173 
00174             // Get the number of LUNs in the connected mass-storage device
00175             max_lun = host_get_lun();
00176 
00177             // Initialize all USB drives
00178             for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++)
00179             {
00180               host_ms_inquiry();
00181               host_read_capacity(host_selected_lun, &capacity);
00182               host_ms_request_sense();
00183               for (i = 0; i < 3; i++)
00184               {
00185                 if (host_test_unit_ready(host_selected_lun) == CTRL_GOOD)
00186                 {
00187                   host_read_capacity(host_selected_lun, &capacity);
00188                   break;
00189                 }
00190               }
00191             }
00192             break;
00193           }
00194         }
00195       }
00196     }
00197 #ifdef FREERTOS_USED
00198   }
00199 #endif
00200 }

void host_mass_storage_task_init ( void   ) 

This function initializes the host mass-storage task.

Definition at line 89 of file host_mass_storage_task.c.

References configTSK_USB_HMS_NAME, configTSK_USB_HMS_PRIORITY, configTSK_USB_HMS_STACK_SIZE, host_mass_storage_task(), ms_connected, ms_new_device_connected, and sof_cnt.

Referenced by main().

00090 {
00091   sof_cnt = 0;
00092   ms_new_device_connected = FALSE;
00093   ms_connected = FALSE;
00094 
00095 #ifdef FREERTOS_USED
00096   xTaskCreate(host_mass_storage_task,
00097               configTSK_USB_HMS_NAME,
00098               configTSK_USB_HMS_STACK_SIZE,
00099               NULL,
00100               configTSK_USB_HMS_PRIORITY,
00101               NULL);
00102 #endif  // FREERTOS_USED
00103 }


Variable Documentation

const char log_ms_dev_connected[] = "Mass-storage device connected\n" [static]

Definition at line 78 of file host_mass_storage_task.c.

Referenced by host_mass_storage_task().

U16 sof_cnt [static]

Definition at line 80 of file host_mass_storage_task.c.


Generated on Fri Feb 19 02:33:37 2010 for AVR32 - USB Mass-Storage on FreeRTOS Example by  doxygen 1.5.5