ATMEL: nav_utils.c File Reference

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

# nav_utils.c File Reference

`#include "config.h"`
`#include <stdio.h>`
`#include "nav_utils.h"`

Include dependency graph for nav_utils.c:

Go to the source code of this file.

## Defines

#define | SIZE_NAME_COPY 50

## Functions

U8 | goto_code_name (U8 code *str, Bool b_case_sensitive, Bool b_create)
void | str_code_to_str_ram (U8 code string_code[], U8 str_ram[30])
Bool | copy_dir (U8 code string_src[], U8 code string_dst[], Bool b_print)

## Variables

U8 | str_ram [30]
| Intermediate ram unicode file name buffer.

## Detailed Description

This file provides other related file name management for file system navigation - Compiler: IAR EWAVR and GNU GCC for AVR

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file nav_utils.c.

## Define Documentation

#define SIZE_NAME_COPY 50

Definition at line 51 of file nav_utils.c.

Referenced by copy_dir().

## Function Documentation

U8 goto_code_name | ( | U8 code * | str,
|  | Bool | b_case_sensitive,
|  | Bool | b_create |
| ) |  |  |

set the explorer navigator to the corresponding file or directory name stored in flash.

Parameters:

  | *str,: | the file or directory name to found
  | case_sensitive |

Returns:
  status: TRUE for ok, FALSE if the name is not found

Definition at line 71 of file nav_utils.c.

Referenced by copy_dir(), and host_dfu_task().

    00073 {
    00074    str_code_to_str_ram( str, str_ram );
    00075    return nav_setcwd( (FS_STRING)str_ram, b_case_sensitive, b_create);
    00076 }

Here is the caller graph for this function:

void str_code_to_str_ram | ( | U8 code | string_code[],
|  | U8 | str_ram[30] |
| ) |  |  |

copy an string code to a ram buffer

Parameters:

  | U8 | code string_code: the string code pointer
  | U8 | *str_ram: the ram buffer pointer

Returns:
  none

Definition at line 88 of file nav_utils.c.

Referenced by goto_code_name().

    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 }

Here is the caller graph for this function:

Bool copy_dir | ( | U8 code | string_src[],
|  | U8 code | string_dst[],
|  | Bool | b_print |
| ) |  |  |

This function copys a source directory to an other directory

Definition at line 106 of file nav_utils.c.

Referenced by host_ms_task().

    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 }

Here is the caller graph for this function:

## Variable Documentation

U8 str_ram[30]

Intermediate ram unicode file name buffer.

Definition at line 59 of file nav_utils.c.

Referenced by goto_code_name(), and str_code_to_str_ram().