This file manages the USB host mass-storage task.
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 "fsaccess.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. | |
Bool | host_mass_storage_task_copy_tree (const char *pcdir_name, U8 sync_direction, Bool bDeleteSrc) |
Synchronize the contents of two directories between the USB drive and the AT45DBX dataflash file systems. | |
void | host_mass_storage_task_init (void) |
This function initializes the host mass-storage task. | |
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 | |
static const char | log_ms_dev_connected [] = "Mass-storage device connected\n" |
volatile Bool | ms_connected |
volatile Bool | ms_new_device_connected |
static char | ms_str [MAX_FILE_PATH_LENGTH] |
static U16 | sof_cnt |
void host_mass_storage_task | ( | void * | pvParameters | ) |
This function manages the host mass-storage task.
pvParameters | Input. Unused. |
Definition at line 109 of file host_mass_storage_task.c.
References configTSK_USB_HMS_PERIOD, log_ms_dev_connected, LOG_STR, ms_connected, and ms_new_device_connected.
Referenced by host_mass_storage_task_init().
00110 { 00111 U8 i; 00112 U8 max_lun; 00113 U32 capacity; 00114 00115 portTickType xLastWakeTime; 00116 00117 xLastWakeTime = xTaskGetTickCount(); 00118 while (TRUE) 00119 { 00120 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD); 00121 00122 // First, check the host controller is in full operating mode with the 00123 // B-device attached and enumerated 00124 if (Is_host_ready()) 00125 { 00126 // Display Start-of-Frame counter on LEDs 00127 // LED_Display_Field(0x7E, sof_cnt >> 5); 00128 00129 // New device connection (executed only once after device connection) 00130 if (ms_new_device_connected) 00131 { 00132 ms_new_device_connected = FALSE; 00133 00134 // For all supported interfaces 00135 for (i = 0; i < Get_nb_supported_interface(); i++) 00136 { 00137 // If mass-storage class 00138 if (Get_class(i) == MS_CLASS) 00139 { 00140 ms_connected = TRUE; 00141 LOG_STR(log_ms_dev_connected); 00142 00143 // Get correct physical pipes associated with IN/OUT endpoints 00144 if (Is_ep_in(i, 0)) 00145 { // Yes, associate it with the IN pipe 00146 g_pipe_ms_in = Get_ep_pipe(i, 0); 00147 g_pipe_ms_out = Get_ep_pipe(i, 1); 00148 } 00149 else 00150 { // No, invert... 00151 g_pipe_ms_in = Get_ep_pipe(i, 1); 00152 g_pipe_ms_out = Get_ep_pipe(i, 0); 00153 } 00154 00155 // Get the number of LUNs in the connected mass-storage device 00156 max_lun = host_get_lun(); 00157 00158 // Initialize all USB drives 00159 for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++) 00160 { 00161 host_ms_inquiry(); 00162 host_read_capacity(host_selected_lun, &capacity); 00163 host_ms_request_sense(); 00164 // while (host_test_unit_ready(host_selected_lun) != CTRL_GOOD); 00165 for( i=0; i<3; i++) 00166 { 00167 if( host_test_unit_ready(host_selected_lun) == CTRL_GOOD ) 00168 { 00169 host_read_capacity(host_selected_lun, &capacity); 00170 break; 00171 } 00172 } 00173 } 00174 break; 00175 } 00176 } 00177 } 00178 } 00179 } 00180 }
Bool host_mass_storage_task_copy_tree | ( | const char * | pcdir_name, | |
U8 | sync_direction, | |||
Bool | bDeleteSrc | |||
) |
Synchronize the contents of two directories between the USB drive and the AT45DBX dataflash file systems.
pcdir_name | const char *: directory name null-terminated string | |
sync_direction | U8: DEVICE_TO_HOST, HOST_TO_DEVICE or FULL_SYNC | |
bDeleteSrc | Bool: if TRUE delete the src directory content. |
Definition at line 206 of file host_mass_storage_task.c.
References FS_NAV_ID_COPYFILE_TREE_DEST, FS_NAV_ID_COPYFILE_TREE_SRC, HOST_TO_DEVICE, LUN_ID_AT45DBX_MEM, LUN_ID_MEM_USB, MAX_FILE_PATH_LENGTH, and ms_str.
Referenced by host_mass_storage_task_sync_drives().
00208 { 00209 U8 u8_folder_level = 0; 00210 long nav_src = 0; // A navigator for the source 00211 long nav_dst = 0; // A navigator for the destination 00212 // DEVICE_TO_HOST default sync direction 00213 U8 u8SrcDrv = LUN_ID_MEM_USB; 00214 U8 u8DstDrv = LUN_ID_AT45DBX_MEM; 00215 U8 u8Status; 00216 00217 00218 // Eventually change the sync direction. 00219 if( sync_direction & HOST_TO_DEVICE ) 00220 { 00221 u8SrcDrv = LUN_ID_AT45DBX_MEM; 00222 u8DstDrv = LUN_ID_MEM_USB; 00223 } 00224 00225 // Use three navigators (0 to explore the src, 1 to explore the dst, 00226 // 2 used by the copy file routine) 00227 nav_src = FS_NAV_ID_COPYFILE_TREE_SRC; 00228 nav_dst = FS_NAV_ID_COPYFILE_TREE_DEST; 00229 00230 // Src init. 00231 nav_select( nav_src ); 00232 if( !nav_drive_set( u8SrcDrv )) 00233 return( FALSE ); 00234 if( !nav_partition_mount() ) 00235 return( FALSE ); 00236 if( !nav_filelist_findname( (FS_STRING )pcdir_name , FALSE) ) // search dir pcdir_name 00237 return( FALSE ); 00238 if( !nav_dir_cd()) 00239 return( FALSE ); 00240 00241 // Dst init. 00242 nav_select( nav_dst ); 00243 if( !nav_drive_set( u8DstDrv )) 00244 return( FALSE ); 00245 if( !nav_partition_mount() ) 00246 return( FALSE ); 00247 // Create folder on the destination disk 00248 if( !nav_dir_make( (FS_STRING )pcdir_name )) 00249 { 00250 if( FS_ERR_FILE_EXIST != fs_g_status ) // !!!! Check available only on last version of FileSystem module package >=1.0.32 00251 return( FALSE ); 00252 // here, error the name exist 00253 } 00254 // Here the navigator have selected the folder on destination 00255 if( !nav_dir_cd()) 00256 return( FALSE ); 00257 00258 00259 // Loop to scan and create ALL folders and files 00260 while(1) 00261 { 00262 // No dir in current dir then go to parent dir on src and dst 00263 while(1) 00264 { // Search files or dir 00265 // Reselect src 00266 nav_select( nav_src ); 00267 if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) 00268 break; // a next file and directory is found 00269 00270 // No other dir or file in current dir then go to parent dir on src and dst 00271 if( 0 == u8_folder_level ) // end of update folder 00272 return TRUE; //********* END OF COPY ************** 00273 00274 // Go to parent 00275 // Remark, nav_dir_gotoparent() routine go to in parent dir and select 00276 // the children dir in list 00277 u8_folder_level--; 00278 if( !nav_dir_gotoparent() ) 00279 return( FALSE ); 00280 // Select dst navigator and go to the same dir of src 00281 nav_select( nav_dst ); 00282 if( !nav_dir_gotoparent() ) 00283 return( FALSE ); 00284 } // end of while (1) 00285 00286 if( nav_file_isdir()) 00287 { // Dir found - create dir & CD 00288 //** here, a new directory is found and is selected 00289 // Get name of current selection (= dir name on src) 00290 if( !nav_file_name( (FS_STRING )ms_str , MAX_FILE_PATH_LENGTH , FS_NAME_GET, FALSE )) 00291 return( FALSE ); 00292 // Enter in dir (on src) 00293 if( !nav_dir_cd()) 00294 return( FALSE ); 00295 u8_folder_level++; 00296 // Select dst 00297 nav_select( nav_dst ); 00298 // Create folder in dst 00299 if( !nav_dir_make( (FS_STRING )ms_str )) 00300 { 00301 if( FS_ERR_FILE_EXIST != fs_g_status ) 00302 return( FALSE ); 00303 // here, error the name exist 00304 } 00305 // Here the navigator have selected the folder on dst 00306 if( !nav_dir_cd()) 00307 { 00308 if( FS_ERR_NO_DIR == fs_g_status ) 00309 { 00310 // Copy impossible, because a file has the same name as folder 00311 } 00312 return( FALSE ); 00313 } 00314 // here, the folder is created and the navigatorS has entered in this dir 00315 } 00316 else 00317 { // File found - copy file 00318 //** here, a new file is found and is selected 00319 // Get name of current selection (= file name on src) 00320 if( !nav_file_name( (FS_STRING )ms_str , MAX_FILE_PATH_LENGTH , FS_NAME_GET , FALSE )) 00321 return( FALSE ); 00322 if( !nav_file_copy()) 00323 return( FALSE ); 00324 00325 // Paste file in current dir of dst 00326 nav_select( nav_dst ); 00327 while( !nav_file_paste_start( (FS_STRING)ms_str ) ) 00328 { 00329 // Error 00330 if( fs_g_status != FS_ERR_FILE_EXIST ) 00331 return( FALSE ); 00332 // del file 00333 // File exist then del this one 00334 if( !nav_file_del( TRUE ) ) 00335 return( FALSE ); 00336 // here, retry PASTE 00337 } 00338 // Copy running 00339 do{ 00340 u8Status = nav_file_paste_state(FALSE); 00341 }while( COPY_BUSY == u8Status ); 00342 00343 if( COPY_FINISH != u8Status ) 00344 return( FALSE ); 00345 00346 if( TRUE == bDeleteSrc ) 00347 { 00348 nav_select( nav_src ); 00349 nav_file_del( FALSE ); // Delete the source file 00350 } 00351 } // if dir OR file 00352 } // end of first while(1) 00353 }
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 b_usbsys_start().
00090 { 00091 sof_cnt = 0; 00092 ms_new_device_connected = FALSE; 00093 ms_connected = FALSE; 00094 00095 xTaskCreate(host_mass_storage_task, 00096 configTSK_USB_HMS_NAME, 00097 configTSK_USB_HMS_STACK_SIZE, 00098 NULL, 00099 configTSK_USB_HMS_PRIORITY, 00100 NULL); 00101 }
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).
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. |
Definition at line 368 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().
00370 { 00371 // First, check the host controller is in full operating mode with the 00372 // B-device attached and enumerated 00373 if (!Is_host_ready()) return FALSE; 00374 00375 fsaccess_take_mutex(); // Take the fs resource. 00376 00377 // First synchronization: USB/OUT -> Local/IN 00378 if (sync_direction & DEVICE_TO_HOST) 00379 { 00380 if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, DEVICE_TO_HOST, bDeleteSrc ) ) 00381 { 00382 00383 fsaccess_give_mutex(); // Release the fs resource. 00384 return FALSE; 00385 } 00386 } 00387 00388 // Second synchronization: Local/pcdir_name -> USB/pcdir_name 00389 if (sync_direction & HOST_TO_DEVICE) 00390 { 00391 if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, HOST_TO_DEVICE, bDeleteSrc ) ) 00392 { 00393 fsaccess_give_mutex(); // Release the fs resource. 00394 return FALSE; 00395 } 00396 } 00397 00398 fsaccess_give_mutex(); // Release the fs resource. 00399 return TRUE; 00400 }
const char log_ms_dev_connected[] = "Mass-storage device connected\n" [static] |
char ms_str[MAX_FILE_PATH_LENGTH] [static] |
Definition at line 79 of file host_mass_storage_task.c.
Referenced by host_mass_storage_task_copy_tree().
U16 sof_cnt [static] |
Definition at line 80 of file host_mass_storage_task.c.