host_mass_storage_task.h 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.h.

#include "conf_usb.h"
#include "usb_host_task.h"
#include "fs_com.h"

Go to the source code of this file.

Defines

#define DEVICE_TO_HOST   0x01
#define DIR_LOCAL_IN_NAME   "IN"
#define DIR_LOCAL_OUT_NAME   "OUT"
#define DIR_USB_IN_NAME   "IN"
#define DIR_USB_OUT_NAME   "OUT"
#define FULL_SYNC   (DEVICE_TO_HOST | HOST_TO_DEVICE)
#define HOST_TO_DEVICE   0x02
#define Is_host_ms_configured()   (ms_connected && !Is_host_suspended())

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.
Bool host_mass_storage_task_sync_dir (Fs_index *dst_fs_idx, const char *dst_dir, Fs_index *src_fs_idx, const char *src_dir, Bool bDeleteSrc)
Bool host_mass_storage_task_sync_drives (signed short FsNavId, U8 sync_direction, const char *pcdir_name, Bool bDeleteSrc)
 Synchronize the contents of two drives (limited to files).
void host_sof_action (void)
 host_sof_action

Variables

volatile Bool ms_connected


Define Documentation

#define DEVICE_TO_HOST   0x01

#define DIR_LOCAL_IN_NAME   "IN"

Definition at line 77 of file host_mass_storage_task.h.

#define DIR_LOCAL_OUT_NAME   "OUT"

Definition at line 76 of file host_mass_storage_task.h.

#define DIR_USB_IN_NAME   "IN"

Definition at line 80 of file host_mass_storage_task.h.

#define DIR_USB_OUT_NAME   "OUT"

Definition at line 79 of file host_mass_storage_task.h.

#define FULL_SYNC   (DEVICE_TO_HOST | HOST_TO_DEVICE)

Definition at line 74 of file host_mass_storage_task.h.

#define HOST_TO_DEVICE   0x02

 
#define Is_host_ms_configured (  )     (ms_connected && !Is_host_suspended())

Definition at line 67 of file host_mass_storage_task.h.


Function Documentation

void host_mass_storage_task ( void *  pvParameters  ) 

This function manages the host mass-storage task.

Parameters:
pvParameters Input. Unused.

Definition at line 111 of file host_mass_storage_task.c.

References configTSK_USB_HMS_PERIOD, LOG_STR, ms_connected, and ms_new_device_connected.

Referenced by host_mass_storage_task_init().

00112 {
00113   U8 i;
00114   U8 max_lun;
00115   U32 capacity;
00116 
00117   portTickType xLastWakeTime;
00118 
00119   xLastWakeTime = xTaskGetTickCount();
00120   while (TRUE)
00121   {
00122     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD);
00123 
00124     // First, check the host controller is in full operating mode with the
00125     // B-device attached and enumerated
00126     if (Is_host_ready())
00127     {
00128       // Display Start-of-Frame counter on LEDs
00129       // LED_Display_Field(0x7E, sof_cnt >> 5);
00130 
00131       // New device connection (executed only once after device connection)
00132       if (ms_new_device_connected)
00133       {
00134         ms_new_device_connected = FALSE;
00135 
00136         // For all supported interfaces
00137         for (i = 0; i < Get_nb_supported_interface(); i++)
00138         {
00139           // If mass-storage class
00140           if (Get_class(i) == MS_CLASS)
00141           {
00142             ms_connected = TRUE;
00143             LOG_STR(log_ms_dev_connected);
00144 
00145             // Get correct physical pipes associated with IN/OUT endpoints
00146             if (Is_ep_in(i, 0))
00147             { // Yes, associate it with the IN pipe
00148               g_pipe_ms_in = Get_ep_pipe(i, 0);
00149               g_pipe_ms_out = Get_ep_pipe(i, 1);
00150             }
00151             else
00152             { // No, invert...
00153               g_pipe_ms_in = Get_ep_pipe(i, 1);
00154               g_pipe_ms_out = Get_ep_pipe(i, 0);
00155             }
00156 
00157             // Get the number of LUNs in the connected mass-storage device
00158             max_lun = host_get_lun();
00159 
00160             // Initialize all USB drives
00161             for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++)
00162             {
00163               host_ms_inquiry();
00164               host_read_capacity(host_selected_lun, &capacity);
00165               host_ms_request_sense();
00166               // while (host_test_unit_ready(host_selected_lun) != CTRL_GOOD);
00167               for( i=0; i<3; i++)
00168               {
00169                  if( host_test_unit_ready(host_selected_lun) == CTRL_GOOD )
00170                  {
00171                     host_read_capacity(host_selected_lun, &capacity);
00172                     break;
00173                  }
00174               }
00175             }
00176             break;
00177           }
00178         }
00179       }
00180     }
00181   }
00182 }

void host_mass_storage_task_init ( void   ) 

This function initializes the host mass-storage task.

Definition at line 91 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 b_usbsys_start().

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

Bool host_mass_storage_task_sync_dir ( Fs_index *  dst_fs_idx,
const char *  dst_dir,
Fs_index *  src_fs_idx,
const char *  src_dir,
Bool  bDeleteSrc 
)

Bool host_mass_storage_task_sync_drives ( signed short  FsNavId,
U8  sync_direction,
const char *  pcdir_name,
Bool  bDeleteSrc 
)

Synchronize the contents of two drives (limited to files).

Parameters:
FsNavId signed short: the file system navigator id to use.
sync_direction U8: DEVICE_TO_HOST, HOST_TO_DEVICE or FULL_SYNC
pcdir_name const char *: directory name to consider.
bDeleteSrc Bool: if TRUE delete the src directory content.
Returns:
Bool: TRUE on success
Todo:
Do recursive directory copy...

Definition at line 370 of file host_mass_storage_task.c.

References DEVICE_TO_HOST, host_mass_storage_task_copy_tree(), and HOST_TO_DEVICE.

Referenced by prv_e_usbsys_sync_cp_ukey().

00372 {
00373   // First, check the host controller is in full operating mode with the
00374   // B-device attached and enumerated
00375   if (!Is_host_ready()) return FALSE;
00376 
00377   fsaccess_take_mutex();   // Take the fs resource.
00378 
00379   // First synchronization: USB/OUT -> Local/IN
00380   if (sync_direction & DEVICE_TO_HOST)
00381   {
00382      if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, DEVICE_TO_HOST, bDeleteSrc ) )
00383      {
00384 
00385         fsaccess_give_mutex();   // Release the fs resource.
00386         return FALSE;
00387      }
00388   }
00389 
00390   // Second synchronization: Local/pcdir_name -> USB/pcdir_name
00391   if (sync_direction & HOST_TO_DEVICE)
00392   {
00393      if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, HOST_TO_DEVICE, bDeleteSrc ) )
00394      {
00395         fsaccess_give_mutex();   // Release the fs resource.
00396         return FALSE;
00397      }
00398   }
00399 
00400   fsaccess_give_mutex();   // Release the fs resource.
00401   return TRUE;
00402 }


Generated on Fri Feb 19 02:22:46 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5