ATMEL: nav_utils.c Source File

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# nav_utils.c

Go to the documentation of this file.

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