nav_utils.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00012 
00013 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * 1. Redistributions of source code must retain the above copyright notice,
00019  * this list of conditions and the following disclaimer.
00020  *
00021  * 2. Redistributions in binary form must reproduce the above copyright notice,
00022  * this list of conditions and the following disclaimer in the documentation
00023  * and/or other materials provided with the distribution.
00024  *
00025  * 3. The name of ATMEL may not be used to endorse or promote products derived
00026  * from this software without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00029  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00030  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00031  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00032  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00033  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00034  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00035  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00036  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00037  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 //_____  I N C L U D E S ___________________________________________________
00041 
00042 #include "config.h"
00043 #include <stdio.h>
00044 #include "nav_utils.h"
00045 
00046 
00047 //_____ M A C R O S ________________________________________________________
00048 #define  SIZE_NAME_COPY    50
00049 
00050 //_____ D E F I N I T I O N S ______________________________________________
00051 
00052 //_____ D E C L A R A T I O N S ____________________________________________
00053 
00054 
00056 U8 str_ram[MAX_FILE_LENGHT];
00057 
00058 
00065 #ifdef __GNUC__
00066 U8 goto_code_name(U8 *str, Bool b_case_sensitive, Bool b_create)
00067 #else
00068 U8 goto_code_name(U8 code *str, Bool b_case_sensitive, Bool b_create)
00069 #endif
00070 {
00071    str_code_to_str_ram( str, str_ram );
00072    return nav_setcwd( (FS_STRING)str_ram, b_case_sensitive, b_create);
00073 }
00074 
00075 
00082 #ifdef __GNUC__
00083 void str_code_to_str_ram(U8 string_code[],U8 str_ram[MAX_FILE_LENGHT])
00084 #else
00085 void str_code_to_str_ram(U8 code string_code[],U8 str_ram[MAX_FILE_LENGHT])
00086 #endif
00087 {
00088    U8 i;
00089    for(i=0;i<MAX_FILE_LENGHT;i++)
00090 #ifndef __GNUC__
00091    {   str_ram[i]=string_code[i];}
00092 #else
00093    {   str_ram[i]=pgm_read_byte_near((unsigned int)string_code+i); }
00094 #endif   
00095 }
00096 
00097 
00100 #ifdef __GNUC__
00101 Bool copy_dir( U8 string_src[], U8 string_dst[], Bool b_print  )
00102 #else
00103 Bool copy_dir( U8 code string_src[], U8 code string_dst[], Bool b_print )
00104 #endif
00105 {
00106    Fs_index sav_index;
00107    char s_name[SIZE_NAME_COPY];
00108    U8 u8_folder_level = 0;
00109 
00110    if( b_print ) printf("\n\r");
00111    // Save the position
00112    sav_index = nav_getindex();
00113 
00114    //** Use three navigators (to explore source, to explore destination, to copy file routine)
00115    // Select source directory
00116    if( b_print ) printf("Select source directory\n\r");
00117    nav_select( FS_NAV_ID_COPY_SRC_DIR );
00118    if( !goto_code_name( string_src, FALSE, FALSE ) )
00119       goto copy_dir_error;
00120    nav_filelist_reset();
00121    // Select destination directory
00122    if( b_print ) printf("Select destination directory\n\r");
00123    nav_select( FS_NAV_ID_COPY_DST_DIR );
00124    if( !goto_code_name( string_dst, FALSE, TRUE ) )
00125       goto copy_dir_error;
00126    nav_filelist_reset();
00127 
00128 
00129    // loop to scan and create ALL folders and files
00130    while(1)
00131    {
00132       // No dir in current dir then go to parent dir on SD and NandFlash disk
00133       while(1)
00134       {
00135          //printf("Search files or dir\n\r");
00136          // Reselect SD
00137          nav_select( FS_NAV_ID_COPY_SRC_DIR );
00138          if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
00139             break;   // a next file and directory is found
00140    
00141          // No other dir or file in current dir then go to parent dir on SD and NandFlash disk
00142          if( 0 == u8_folder_level )
00143          {
00144             // end of update folder
00145             //********* END OF COPY **************
00146             goto copy_dir_finish;
00147          }
00148 
00149          if( b_print ) printf("Go to parent\n\r");
00150          // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list
00151          u8_folder_level--;
00152          if( !nav_dir_gotoparent() )
00153             goto copy_dir_error;
00154          // Select NandFlash navigator and go to the same dir of SD
00155          nav_select( FS_NAV_ID_COPY_DST_DIR );
00156          if( !nav_dir_gotoparent() )
00157             goto copy_dir_error;
00158       } // end of while (1)
00159       
00160       if( nav_file_isdir())
00161       {
00162          if( b_print ) printf("Dir found - create dir: ");
00163          //** here, a new directory is found and is selected
00164          // Get name of current selection (= dir name on SD)
00165          if( !nav_file_name( (FS_STRING)s_name, MAX_FILE_LENGHT, FS_NAME_GET, FALSE ))
00166             goto copy_dir_error;
00167          // Enter in dir (on SD)
00168          if( !nav_dir_cd())
00169             goto copy_dir_error;
00170          u8_folder_level++;
00171          // Select NandFlash disk
00172          nav_select( FS_NAV_ID_COPY_DST_DIR );
00173          // Create folder in NandFlash disk
00174          if( b_print ) printf((char*)s_name);
00175          if( b_print ) printf("\n\r");
00176          if( !nav_dir_make( (FS_STRING )s_name ))
00177          {
00178             if( FS_ERR_FILE_EXIST != fs_g_status )
00179                goto copy_dir_error;
00180             // here, error the name exist
00181          }
00182          // Here the navigator have selected the folder on NandFlash
00183          if( !nav_dir_cd())
00184          {
00185             if( FS_ERR_NO_DIR == fs_g_status )
00186             {
00187                // FYC -> Copy impossible, because a file have the same name of folder
00188             }
00189             goto copy_dir_error;
00190          }
00191          // here, the folder is created and the navigatorS is entered in this dir
00192       }
00193       else
00194       {
00195          if( b_print ) printf("File found - copy file: ");
00196          //** here, a new file is found and is selected
00197          // Get name of current selection (= file name on SD)
00198          if( !nav_file_name( (FS_STRING)s_name, MAX_FILE_LENGHT, FS_NAME_GET, FALSE ))
00199             goto copy_dir_error;
00200          if( b_print ) printf((char*)s_name);
00201          if( b_print ) printf("\n\r");
00202          if( !nav_file_copy())
00203             goto copy_dir_error;
00204 
00205          // Paste file in current dir of NandFlash disk
00206          nav_select( FS_NAV_ID_COPY_DST_DIR );
00207          while( !nav_file_paste_start( (FS_STRING)s_name ) )
00208          {
00209             // Error
00210             if( fs_g_status != FS_ERR_FILE_EXIST )
00211                goto copy_dir_error;
00212             // File exists then deletes this one
00213             if( b_print ) printf("File exists then deletes this one.\n\r");
00214             if( !nav_file_del( TRUE ) )
00215                goto copy_dir_error;
00216             // here, retry PASTE                   
00217          }
00218          // Copy running
00219          {
00220          U8 status;
00221          do{
00222             status = nav_file_paste_state(FALSE);
00223          }while( COPY_BUSY == status );
00224 
00225          if( COPY_FINISH != status )
00226             goto copy_dir_error;
00227          }
00228       } // if dir OR file
00229    } // end of first while(1)
00230  
00231 copy_dir_error:
00232    // Restore the position
00233    nav_select( FS_NAV_ID_USHELL_CMD );
00234    nav_gotoindex(&sav_index);
00235    if( b_print ) printf("!!!copy fail\n\r");
00236    return FALSE;
00237    
00238 copy_dir_finish:
00239    // Restore the position
00240    nav_select( FS_NAV_ID_USHELL_CMD );
00241    nav_gotoindex(&sav_index);
00242    if( b_print ) printf("End of copy\n\r");
00243    return TRUE;
00244 }
00245 
00246 

Generated on Fri May 15 15:41:36 2009 for ATMEL by  doxygen 1.5.3