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 | |
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 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 }
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 208 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().
00210 { 00211 U8 u8_folder_level = 0; 00212 long nav_src = 0; // A navigator for the source 00213 long nav_dst = 0; // A navigator for the destination 00214 // DEVICE_TO_HOST default sync direction 00215 U8 u8SrcDrv = LUN_ID_MEM_USB; 00216 U8 u8DstDrv = LUN_ID_AT45DBX_MEM; 00217 U8 u8Status; 00218 00219 00220 // Eventually change the sync direction. 00221 if( sync_direction & HOST_TO_DEVICE ) 00222 { 00223 u8SrcDrv = LUN_ID_AT45DBX_MEM; 00224 u8DstDrv = LUN_ID_MEM_USB; 00225 } 00226 00227 // Use three navigators (0 to explore the src, 1 to explore the dst, 00228 // 2 used by the copy file routine) 00229 nav_src = FS_NAV_ID_COPYFILE_TREE_SRC; 00230 nav_dst = FS_NAV_ID_COPYFILE_TREE_DEST; 00231 00232 // Src init. 00233 nav_select( nav_src ); 00234 if( !nav_drive_set( u8SrcDrv )) 00235 return( FALSE ); 00236 if( !nav_partition_mount() ) 00237 return( FALSE ); 00238 if( !nav_filelist_findname( (FS_STRING )pcdir_name , FALSE) ) // search dir pcdir_name 00239 return( FALSE ); 00240 if( !nav_dir_cd()) 00241 return( FALSE ); 00242 00243 // Dst init. 00244 nav_select( nav_dst ); 00245 if( !nav_drive_set( u8DstDrv )) 00246 return( FALSE ); 00247 if( !nav_partition_mount() ) 00248 return( FALSE ); 00249 // Create folder on the destination disk 00250 if( !nav_dir_make( (FS_STRING )pcdir_name )) 00251 { 00252 if( FS_ERR_FILE_EXIST != fs_g_status ) // !!!! Check available only on last version of FileSystem module package >=1.0.32 00253 return( FALSE ); 00254 // here, error the name exist 00255 } 00256 // Here the navigator have selected the folder on destination 00257 if( !nav_dir_cd()) 00258 return( FALSE ); 00259 00260 00261 // Loop to scan and create ALL folders and files 00262 while(1) 00263 { 00264 // No dir in current dir then go to parent dir on src and dst 00265 while(1) 00266 { // Search files or dir 00267 // Reselect src 00268 nav_select( nav_src ); 00269 if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) 00270 break; // a next file and directory is found 00271 00272 // No other dir or file in current dir then go to parent dir on src and dst 00273 if( 0 == u8_folder_level ) // end of update folder 00274 return TRUE; //********* END OF COPY ************** 00275 00276 // Go to parent 00277 // Remark, nav_dir_gotoparent() routine go to in parent dir and select 00278 // the children dir in list 00279 u8_folder_level--; 00280 if( !nav_dir_gotoparent() ) 00281 return( FALSE ); 00282 // Select dst navigator and go to the same dir of src 00283 nav_select( nav_dst ); 00284 if( !nav_dir_gotoparent() ) 00285 return( FALSE ); 00286 } // end of while (1) 00287 00288 if( nav_file_isdir()) 00289 { // Dir found - create dir & CD 00290 //** here, a new directory is found and is selected 00291 // Get name of current selection (= dir name on src) 00292 if( !nav_file_name( (FS_STRING )ms_str , MAX_FILE_PATH_LENGTH , FS_NAME_GET, FALSE )) 00293 return( FALSE ); 00294 // Enter in dir (on src) 00295 if( !nav_dir_cd()) 00296 return( FALSE ); 00297 u8_folder_level++; 00298 // Select dst 00299 nav_select( nav_dst ); 00300 // Create folder in dst 00301 if( !nav_dir_make( (FS_STRING )ms_str )) 00302 { 00303 if( FS_ERR_FILE_EXIST != fs_g_status ) 00304 return( FALSE ); 00305 // here, error the name exist 00306 } 00307 // Here the navigator have selected the folder on dst 00308 if( !nav_dir_cd()) 00309 { 00310 if( FS_ERR_NO_DIR == fs_g_status ) 00311 { 00312 // Copy impossible, because a file has the same name as folder 00313 } 00314 return( FALSE ); 00315 } 00316 // here, the folder is created and the navigatorS has entered in this dir 00317 } 00318 else 00319 { // File found - copy file 00320 //** here, a new file is found and is selected 00321 // Get name of current selection (= file name on src) 00322 if( !nav_file_name( (FS_STRING )ms_str , MAX_FILE_PATH_LENGTH , FS_NAME_GET , FALSE )) 00323 return( FALSE ); 00324 if( !nav_file_copy()) 00325 return( FALSE ); 00326 00327 // Paste file in current dir of dst 00328 nav_select( nav_dst ); 00329 while( !nav_file_paste_start( (FS_STRING)ms_str ) ) 00330 { 00331 // Error 00332 if( fs_g_status != FS_ERR_FILE_EXIST ) 00333 return( FALSE ); 00334 // del file 00335 // File exist then del this one 00336 if( !nav_file_del( TRUE ) ) 00337 return( FALSE ); 00338 // here, retry PASTE 00339 } 00340 // Copy running 00341 do{ 00342 u8Status = nav_file_paste_state(FALSE); 00343 }while( COPY_BUSY == u8Status ); 00344 00345 if( COPY_FINISH != u8Status ) 00346 return( FALSE ); 00347 00348 if( TRUE == bDeleteSrc ) 00349 { 00350 nav_select( nav_src ); 00351 nav_file_del( FALSE ); // Delete the source file 00352 } 00353 } // if dir OR file 00354 } // end of first while(1) 00355 }
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_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 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 }
char ms_str[MAX_FILE_PATH_LENGTH] [static] |
Definition at line 81 of file host_mass_storage_task.c.
Referenced by host_mass_storage_task_copy_tree().
U16 sof_cnt [static] |
Definition at line 82 of file host_mass_storage_task.c.