CircleOS  1
fs.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2012 KEOLABS S.A.S. *****************/
19 /*******************************************************************************/
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "circle.h"
23 
24 #if SDCARD_SDIO
25 #include "sdio_sd.h"
26 #else
27 #include "spi_sd.h"
28 #endif
29 #include "diskio.h"
30 #include "fs.h"
31 #include <string.h>
32 #include <stdio.h>
33 
35 
36 /* Private typedef -----------------------------------------------------------*/
37 
38 /* Private define ------------------------------------------------------------*/
39 #define MAX_DIRS LIST_MAXITEM
40 #define MAX_LIST_ITEMS_DISP 7
41 #define MAX_PATH_LENGTH 200
42 #if LCD_HIGH_DEF
43 #define MAXDIRNAMELEN 30
44 #else
45 #define MAXDIRNAMELEN 17
46 #endif
47 #define BUFSIZE 512 // Size of buffer used for file copy and compare
48 
49 /* Private macro -------------------------------------------------------------*/
50 
51 /* Private variables ---------------------------------------------------------*/
52 static union array
53 {
54  u8 sector[SECTOR_SIZE]; // the char array
55  unsigned int i; // force 32-bit int alignment
56 } u;
57 static u32 StartMBR;
58 static u8 SDCardfault = 0;
59 
60 /* Public variables ----------------------------------------------------------*/
61 // The variables are kept to respect the API of CircleOS
62 VOLINFO volume_info;
63 DIRINFO directory_info;
64 DIRENT directory_entry;
65 u8* FS_PathFilter = 0;
66 
67 struct DirItem
68 {
69  u8 Name[MAXDIRNAMELEN];
70  u8 flags;
71 };
72 
73 struct DirItem DirItems[MAX_DIRS];
74 
75 //YRT13065tList DirMenu = { 1, "SD Card", 30, 20, 0, 0, 0, 0, 6, 0, 0, };
76 tList DirMenu = { 1, "SD Card", MAX_DIRS, MAXDIRNAMELEN, 0, 0, 0, 0, MAX_LIST_ITEMS_DISP, 0, 0, };
77 
78 u8 level = 0;
79 u8 CurrentPath[MAX_PATH_LENGTH];
80 
81 // These variables contain all informations about the file system, current directory, ...
82 FATFS fs;
83 DIR CurrentDir;
84 FIL file, file2;
85 FILINFO fileInfo;
86 
87 
88 /* External variables ---------------------------------------------------------*/
89 extern WCHAR LfnBuf[_MAX_LFN + 1];
90 extern BYTE sfn[12];
91 extern divider_t Appli_Divider;
92 extern divider_t Appli_DividerBkp;
93 
94 /* Private functions ----------------------------------------------------------*/
95 void NVIC_Config_SDIO( void );
96 
97 
98 
99 
100 /*******************************************************************************
101 *
102 * FillVolInfo
103 *
104 *******************************************************************************/
112 /*******************************************************************************/
113 NODEBUG void FillVolInfo( PVOLINFO volinfo )
114 {
115  volinfo->unit = fs.drv;
116  volinfo->filesystem = fs.fs_type;
117  //~ volinfo->label = ;
118  volinfo->startsector = fs.fatbase;
119  volinfo->secperclus = fs.csize;
120  //~ volinfo->reservedsecs = ;
121  //~ volinfo->numsecs = ;
122  volinfo->secperfat = fs.fsize;
123  volinfo->rootentries = fs.n_rootdir;
124  //~ volinfo->numclusters = ;
125  volinfo->fat1 = fs.fatbase;
126  volinfo->rootdir = fs.dirbase;
127  volinfo->dataarea = fs.database;
128 }
129 
130 /*******************************************************************************
131 *
132 * FillDirInfo
133 *
134 *******************************************************************************/
142 /*******************************************************************************/
143 NODEBUG void FillDirInfo( PDIRINFO dirinfo, DIR* dir )
144 {
145  dirinfo->currentcluster = dir->clust;
146  dirinfo->currentsector = dir->sect;
147  dirinfo->currententry = dir->index;
148  // dirinfo->scratch = ; This field is prepopulated in FS_OpenDir for example
149  dirinfo->flags = 0; // Picked at the beginning of DFS_OpenDir
150 }
151 
152 /*******************************************************************************
153 *
154 * FillDirEnt
155 *
156 *******************************************************************************/
164 /*******************************************************************************/
165 NODEBUG void FillDirEnt( PDIRENT dirent )
166 {
167  strncpy( dirent->name, fileInfo.fname, sizeof( dirent->name ) );
168  dirent->name[sizeof( dirent->name ) - 1] = '\0';
169  dirent->attr = fileInfo.fattrib;
170  dirent->reserved = 0; // Must be 0
171 }
172 
173 /*******************************************************************************
174 *
175 * FillFileInfo
176 *
177 *******************************************************************************/
185 /*******************************************************************************/
186 NODEBUG void FillFileInfo( PFILEINFO fileinfo )
187 {
188  FillVolInfo( fileinfo->volinfo );
189  fileinfo->dirsector = file.dir_sect;
190  fileinfo->diroffset = *file.dir_ptr;
191  fileinfo->mode = file.flag;
192  fileinfo->firstcluster = file.org_clust;
193  fileinfo->filelen = file.fsize;
194  fileinfo->cluster = file.curr_clust;
195  fileinfo->pointer = file.fptr;
196 }
197 
198 
199 
200 /* Public functions ----------------------------------------------------------*/
201 
202 /*******************************************************************************
203 *
204 * FS_Mount
205 *
206 *******************************************************************************/
216 /*******************************************************************************/
217 u32 FS_Mount( enum STORAGE_device device )
218 {
219 #if SDCARD_SDIO
220  NVIC_Config_SDIO();
221 #endif
222  //~ return DFS_Mount( device );
223 
224  u32 retVal = f_mount( 0, &fs );
225 
226  if (retVal == FR_OK)
227  {
228  // Check if the device is mounted
229  const TCHAR* path = "";
230  FATFS* tmpFs = &fs;
231  retVal = chk_mounted( &path, &tmpFs, 0 );
232 
233  // Fill the VOLINFO structure for compatibility
234  FillVolInfo( &volume_info );
235  }
236 
237  return retVal;
238 }
239 
240 
241 /*******************************************************************************
242 *
243 * FS_Unmount
244 *
245 *******************************************************************************/
253 /*******************************************************************************/
254 u32 FS_Unmount( enum STORAGE_device device )
255 {
256  return f_mount( 0, NULL );
257 }
258 
259 
260 /*******************************************************************************
261 *
262 * FS_OpenFile
263 *
264 *******************************************************************************/
293 /*******************************************************************************/
294 u32 FS_OpenFile( PVOLINFO volinfo, char* path, u8 mode, PFILEINFO fileinfo )
295 {
296  //~ return DFS_OpenFile( volinfo, path, mode, u.sector, fileinfo );
297 
298  u32 retVal = DFS_NOPATH;
299  fileinfo->volinfo = volinfo;
300 
301  if ( path )
302  {
303  // If the file does not exists, create it (for compatibility)
304  if (mode & FS_WRITE)
305  mode |= FA_OPEN_ALWAYS;
306 
307  // Open the file
308  retVal = f_open( &file, path, mode );
309 
310  // Fill the FILEINFO structure for compatibility
311  FillFileInfo( fileinfo );
312  }
313 
314  return retVal;
315 }
316 
317 
318 
319 /*******************************************************************************
320 *
321 * FS_ReadFile
322 *
323 *******************************************************************************/
335 /*******************************************************************************/
336 u32 FS_ReadFile( PFILEINFO fileinfo, u8* buffer, u32* successcount, u32 len )
337 {
338  //~ return DFS_ReadFile( fileinfo, u.sector, buffer, successcount, len );
339 
340  u32 retVal = DFS_NULLPOINTER;
341 
342  if ( buffer && successcount )
343  {
344  retVal = f_read( &file, buffer, len, ( int* ) successcount );
345 
346  // Fill the FILEINFO structure for compatibility
347  FillFileInfo( fileinfo );
348  }
349 
350  return retVal;
351 }
352 
353 
354 /*******************************************************************************
355 *
356 * FS_WriteFile
357 *
358 *******************************************************************************/
390 /*******************************************************************************/
391 u32 FS_WriteFile( PFILEINFO fileinfo, u8* buffer, u32* successcount, u32 len )
392 {
393  //~ return DFS_WriteFile( fileinfo, u.sector, buffer, successcount, len );
394 
395  u32 retVal = DFS_NULLPOINTER;
396  retVal = f_write( &file, buffer, len, ( int* ) successcount );
397 
398  FillFileInfo( fileinfo );
399 
400  return retVal;
401 }
402 
403 
404 /*******************************************************************************
405 *
406 * FS_Close
407 *
408 *******************************************************************************/
416 /*******************************************************************************/
417 u32 FS_Close( PFILEINFO fileinfo )
418 {
419 
420  u32 retVal = f_close( &file );
421 
422  // Fill the FILEINFO structure for compatibility
423  FillFileInfo( fileinfo );
424 
425  return retVal;
426 }
427 
428 
429 
430 
431 /*******************************************************************************
432 *
433 * FS_Delete
434 *
435 *******************************************************************************/
449 /*******************************************************************************/
450 u32 FS_Delete( PVOLINFO volinfo, u8* path )
451 {
452  //~ return DFS_UnlinkFile( volinfo, path, u.sector );
453 
454  u32 retVal = f_unlink( path );
455 
456  // Fill the VOLINFO structure for compatibility
457  FillVolInfo( volinfo );
458 
459  return retVal;
460 }
461 
462 
463 /*******************************************************************************
464 *
465 * FS_GetNextEntry
466 *
467 *******************************************************************************/
490 /*******************************************************************************/
491 u32 FS_GetNextEntry( PVOLINFO volinfo, PDIRINFO dirinfo, PDIRENT dirent )
492 {
493  //~ return DFS_GetNext( volinfo, dirinfo, dirent );
494 
495  u32 retVal = f_readdir( &CurrentDir, &fileInfo );
496  if ( fileInfo.fname[0] == 0 )
497  retVal = FR_NO_FILE;
498 
499  // Fill the DIRENT structure for compatibility
500  FillDirEnt( dirent );
501 
502  return retVal;
503 }
504 
505 
506 /*******************************************************************************
507 *
508 * FS_OpenDirectory
509 *
510 *******************************************************************************/
526 /*******************************************************************************/
527 u32 FS_OpenDirectory( PVOLINFO volinfo, u8* dirname, PDIRINFO dirinfo )
528 {
529  //~ dirinfo->scratch = u.sector; /* DFS Note - you must PREPOPULATE*/
530  //~ /* the DIRINFO.scratch field with a pointer to a sector scratch buffer.*/
531  //~ return DFS_OpenDir( volinfo, dirname, dirinfo );
532 
533  u32 retVal = FR_NO_PATH;
534  dirinfo->scratch = u.sector; // DFS Note - you must PREPOPULATE
535 
536  // If there is a trailing slash, remove it
537  len_t len = my_strlen( dirname );
538  if ( dirname[len - 1] == '/' )
539  dirname[len - 1] = 0;
540 
541  if ( dirname )
542  retVal = f_opendir( &CurrentDir, dirname );
543 
544  // Fill the VOLINFO/DIRINFO structure for compatibility
545  FillVolInfo( volinfo );
546  FillDirInfo( dirinfo, &CurrentDir );
547  switch ( retVal )
548  {
549  case FR_OK: break;
550  default:
551  break;
552  }
553 
554  return retVal;
555 }
556 
557 
558 /*******************************************************************************
559 *
560 * FS_GetVolumeInfo
561 *
562 *******************************************************************************/
578 /*******************************************************************************/
579 u32 FS_GetVolumeInfo( u8 unit, u32 startsector, PVOLINFO volinfo )
580 {
581  //~ return DFS_GetVolInfo( unit, u.sector, startsector, volinfo );
582 
583  // Check if the device is mounted
584  const TCHAR* path = "";
585  FATFS* tmpFs = &fs;
586  u32 retVal = chk_mounted( &path, &tmpFs, 0 );
587 
588  // Fill the VOLINFO structure for compatibility
589  FillVolInfo( volinfo );
590  switch ( retVal )
591  {
592  case FR_OK: break;
593  default:
594  break;
595  }
596 
597  return retVal;
598 }
599 
600 
601 /*******************************************************************************
602 *
603 * FS_GetSDCardCurrentPath
604 *
605 *******************************************************************************/
615 u8* FS_GetSDCardCurrentPath( void )
616 {
617  return ( u8* ) &CurrentPath;
618 }
619 
620 
621 /*******************************************************************************
622 *
623 * FS_GetSDCardVolInfo
624 *
625 *******************************************************************************/
637 VOLINFO* FS_GetSDCardVolInfo( void )
638 {
639  return &volume_info;
640 }
641 
642 /*******************************************************************************
643 *
644 * FS_GetPathFilter
645 *
646 *******************************************************************************/
654 u8* FS_GetPathFilter( void )
655 {
656  return FS_PathFilter;
657 }
658 
659 /*******************************************************************************
660 *
661 * FS_SetPathFilter
662 *
663 *******************************************************************************/
674 void FS_SetPathFilter( u8* filter )
675 {
676  if ( filter )
677  FS_PathFilter = strupr( filter );
678  else
679  FS_PathFilter = 0;
680 }
681 
682 /*******************************************************************************
683 *
684 * FS_Seek
685 *
686 *******************************************************************************/
695 /*******************************************************************************/
696 u32 FS_Seek( PFILEINFO fileinfo, u32 offset )
697 {
698  //~ DFS_Seek( fileinfo, offset, u.sector );
699 
700  u32 retVal = f_lseek( &file, offset );
701 
702  // Fill the FILEINFO structure for compatibility
703  FillFileInfo( fileinfo );
704 
705  return retVal;
706 }
707 
708 
709 /*******************************************************************************
710 *
711 * FS_Tell
712 *
713 *******************************************************************************/
721 /*******************************************************************************/
722 u32 FS_Tell( PFILEINFO fileinfo )
723 {
724  // Tell from file system
725  u32 retVal = f_tell( &file );
726 
727  // Fill the FILEINFO structure for compatibility
728  FillFileInfo( fileinfo );
729 
730  return retVal;
731 }
732 
733 /*******************************************************************************
734 *
735 * FS_Gets
736 *
737 *******************************************************************************/
746 /*******************************************************************************/
747 u32 FS_Gets(char* ptr, int len, PFILEINFO fileinfo)
748 {
749  char* ret_val = f_gets (ptr, len, &file);
750 
751  // Fill the FILEINFO structure for compatibility
752  FillFileInfo( fileinfo );
753 
754  if (!ret_val)
755  return FR_DISK_ERR;
756  else
757  return FR_OK;
758 }
759 
760 /*******************************************************************************
761 *
762 * FS_Size
763 *
764 *******************************************************************************/
772 /*******************************************************************************/
773 u32 FS_Size( PFILEINFO fileinfo )
774 {
775  // Tell from file system
776  u32 retVal = f_size( &file );
777 
778  // Fill the FILEINFO structure for compatibility
779  FillFileInfo( fileinfo );
780 
781  return retVal;
782 }
783 
784 /*******************************************************************************
785 *
786 * FS_Eof
787 *
788 *******************************************************************************/
796 /*******************************************************************************/
797 u32 FS_Eof( PFILEINFO fileinfo )
798 {
799  // Tell from file system
800  u32 retVal = f_eof( &file );
801 
802  // Fill the FILEINFO structure for compatibility
803  FillFileInfo( fileinfo );
804 
805  return retVal;
806 }
807 
808 /*******************************************************************************
809 *
810 * FS_FileCopy
811 *
812 *******************************************************************************/
821 /*******************************************************************************/
822 NODEBUG2 u32 FS_FileCopy( char* dest, char* src )
823 {
824  int total_count_debug ;
825  int count, successcount ;
826  extern FIL file, file2;
827  char buf[BUFSIZE+1];
828  int ret = FR_OK;
829 
830  total_count_debug = 0;
831 
832  // Open the files
833  if ( f_open( &file, src, FA_READ ) )
834  return FR_NO_FILE;
835 
836  if ( f_open( &file2, dest, FA_CREATE_ALWAYS | FA_WRITE ) )
837  return FR_NO_FILE;
838 
839  // Copy the contents
840  while ( 1 )
841  {
842  if ( !f_read( &file, buf, BUFSIZE, &count ) && count )
843  {
844  if ( count == 0 )
845  break;
846 
847  if ( !f_write( &file2, buf, count, &successcount ) )
848  {
849  total_count_debug += successcount;
850  continue;
851  }
852  ret = FR_DISK_ERR;
853  }
854  f_close( &file2 );
855  break;
856  }
857  f_close( &file );
858 
859  return ret;
860 }
861 
862 /*******************************************************************************
863 *
864 * FS_FileCmp
865 *
866 *******************************************************************************/
875 /*******************************************************************************/
876 u32 FS_FileCmp( char* fn1, char* fn2 )
877 {
878  int total_checked_debug = 0;
879  int count1, count2;
880  extern FIL file, file2;
881  char buf1[BUFSIZE+1];
882  char buf2[BUFSIZE+1];
883  int ret = FR_OK;
884 
885  total_checked_debug = 0;
886 
887  if ( f_open( &file, fn2, FA_READ ) )
888  return 1;
889 
890  if ( f_open( &file2, fn1, FA_READ ) )
891  return 1;
892 
893  //Copy the contents
894  while ( ret == 0 )
895  {
896  if ( f_read( &file, buf1, BUFSIZE, &count1 ) )
897  {
898  ret = 1;
899  break;
900  }
901  if ( f_read( &file2, buf2, BUFSIZE, &count2 ) )
902  {
903  ret = 1;
904  break;
905  }
906  if ( count1 == count2 )
907  {
908  if ( !count1 )
909  break;
910  else
911  {
912  ret = mem_cmp( buf1, buf2, count1 );
913  if ( !ret )
914  total_checked_debug += count1;
915  }
916  }
917  else
918  ret = 1;
919 
920  if ( count1 < BUFSIZE )
921  break;
922  }
923  f_close( &file );
924  f_close( &file2 );
925 
926  return ret;
927 }
928 
929 /*******************************************************************************
930 *
931 * FS_Explorer_UpdateList
932 *
933 *******************************************************************************/
941 NODEBUG void FS_Explorer_UpdateList( void )
942 {
943  u8 i = 0;
944  char* fn;
945 
946  mem_set( DirItems, 0, sizeof( DirItems ) );
947 
948  /* Loop through root dir and display files / dirs*/
949  while ( ( f_readdir( &CurrentDir, &fileInfo ) == FR_OK ) && fileInfo.fname[0] )
950  {
951  // Retrieve the file name
952  fn = *fileInfo.lfname ? fileInfo.lfname : fileInfo.fname;
953 
954  {
955  // Add a link to the parent directory if we are not in the root directory
956  if ( ( i == 0 ) && strcmp( CurrentPath, "" ) )
957  {
958  mem_set( ( void* )DirItems[i].Name, 0, MAXDIRNAMELEN );
959  strcat( DirItems[i].Name, "[..]" );
960  DirMenu.Items[i].Text = DirItems[i].Name;
961  DirItems[i].flags |= FS_ATTR_DIRECTORY; /* set flag in local list*/
962  i++;
963  }
964 
965  /* Directory*/
966  if ( fileInfo.fattrib & AM_DIR )
967  {
968  if ( strncmp( fn, ". ", 2 ) ) /* don't display current "." directory*/
969  {
970  strcat( DirItems[i].Name, "[" );
971  strncat( DirItems[i].Name, fn, MAXDIRNAMELEN );
972  strcat( DirItems[i].Name, "]" );
973 
974  DirMenu.Items[i].Text = DirItems[i].Name;
975  DirItems[i].flags |= FS_ATTR_DIRECTORY; /* set flag in local list*/
976  i++;
977  }
978  }
979  else /* File*/
980  {
981  /* Check if matches the type filter*/
982  u8* ext = strrchr( fn, '.' );
983  if ( ext )
984  ext++;
985  strupr( ext );
986  if ( ( FS_PathFilter == 0 ) || ( strncmp( ext, FS_PathFilter, 3 ) == 0 ) )
987  {
988  mem_cpy( DirItems[i].Name, fn, MAXDIRNAMELEN - 1 );
989  DirMenu.Items[i].Text = DirItems[i].Name;
990  i++;
991  }
992  }
993 
994  if ( i >= MAX_DIRS )
995  break;
996  }
997 
998 
999  }
1000 
1001  if ( ( i == 0 ) && strcmp( CurrentPath, "" ) ) /* empty dir ?*/
1002  {
1003  mem_set( ( void* )DirItems[i].Name, 0, MAXDIRNAMELEN );
1004  mem_cpy( DirItems[i].Name, "[..]", 4 );
1005  DirMenu.Items[i].Text = DirItems[i].Name;
1006  DirItems[i].flags |= FS_ATTR_DIRECTORY; /* set flag in local list*/
1007  i++;
1008  }
1009 
1010  /* Set number of items in list (i + cde "Quit")*/
1011  DirMenu.Items[i].Text = "Quit";
1012  i++;
1013  DirMenu.NbItems = i;
1014  DirMenu.NbDisp = i > MAX_LIST_ITEMS_DISP ? MAX_LIST_ITEMS_DISP : i;
1015 
1016  DirMenu.XPos = 0;
1017  DirMenu.YPos = 150;
1018  DirMenu.XSize = 128;
1019  DirMenu.YSize = 140;
1020 }
1021 
1022 /*******************************************************************************
1023 *
1024 * FS_Explorer_Ini
1025 *
1026 *******************************************************************************/
1035 NODEBUG2 enum MENU_code FS_Explorer_Ini( void )
1036 {
1037  DirMenu.fdispTitle = 1;
1038  DirMenu.Title = " SDCard ";
1039  DirMenu.NbItems = 30;
1040 //YRT130605 DirMenu.LgMax = 20;
1041  DirMenu.LgMax = MAX_PATH_LENGTH;
1042  DirMenu.XPos = DirMenu.YPos = 0;
1043  DirMenu.XSize = DirMenu.YSize = 0;
1044  DirMenu.NbDisp = MAX_LIST_ITEMS_DISP; /* Number of lines to be displayed*/
1045  DirMenu.SelectedItem = 0; /* Current selected item*/
1046  DirMenu.FirstDisplayItem = 0; /* Index of the first displayed item*/
1047 
1048  mem_set( CurrentPath, 0, sizeof( CurrentPath ) );
1049 
1050  SDCardfault = 0;
1051  SD_DeInit();
1052 
1053  /* Mount MMCSD if necessary */
1054  StartMBR = FS_Mount( MMCSD_SDIO );
1055 
1056  if ( StartMBR != FR_OK )
1057  {
1058  // Try another time (pb in SPI mode)
1059  StartMBR = FS_Mount( MMCSD_SDIO );
1060  if ( StartMBR != FR_OK )
1061  {
1062  DirMenu.Items[0].Text = "No SD Card";
1063  SDCardfault = 1;
1064  }
1065  }
1066 
1067  if ( !SDCardfault )
1068  {
1069  // Open volume on first partition (0)
1070  if ( FS_GetVolumeInfo( 0, StartMBR, &volume_info ) )
1071  {
1072  DirMenu.Items[0].Text = "Err: GetVolInfo";
1073  SDCardfault = 1;
1074  }
1075  }
1076 
1077  if ( !SDCardfault )
1078  {
1079  // Open root directory
1080  if ( FS_OpenDirectory( &volume_info, "", &directory_info ) )
1081  {
1082  DirMenu.Items[0].Text = "Err: Open Root";
1083  SDCardfault = 1;
1084  }
1085  }
1086 
1087  if ( SDCardfault )
1088  {
1089  // 2 items : error msg + quit
1090  DirMenu.NbItems = 2;
1091  DirMenu.Items[1].Text = "Quit";
1092 
1093  // Show list
1094  LIST_Set( &DirMenu, 0, 0, 1 );
1095  }
1096  else
1097  {
1098  fileInfo.lfname = ( TCHAR* ) LfnBuf;
1099  fileInfo.lfsize = sizeof( LfnBuf );
1100 
1101  // Populate the list
1102  FS_Explorer_UpdateList();
1103 
1104  // Accelerate the menu divider
1105  Appli_DividerBkp = Appli_Divider;
1106  MENU_SetAppliDivider( 1 );
1107 
1108  // Show list
1109  LIST_Set( &DirMenu, 0, 0, 1 );
1110 
1111  }
1112 
1113  return MENU_CONTINUE_COMMAND;
1114 
1115 }
1116 
1117 
1118 /*******************************************************************************
1119 *
1120 * FS_Explorer
1121 *
1122 *******************************************************************************/
1137 NODEBUG2 s32 FS_Explorer( void )
1138 {
1139  s32 i;
1140  u32 retval;
1141  u8 EOP = 0;
1142 
1143  /* Call the List manager of the current list*/
1144  i = LIST_Manager();
1145 
1146  /* If item selected*/
1147  if ( i != -1 )
1148  {
1149 
1150  /* If choice different than quit and card OK*/
1151  if ( ( i != ( DirMenu.NbItems - 1 ) ) && !SDCardfault )
1152  {
1153  u8 dir[MAX_PATH_LENGTH];
1154  mem_set( dir, 0, sizeof( dir ) );
1155 
1156  /* Directory selected from list*/
1157  if ( DirItems[i].flags & FS_ATTR_DIRECTORY )
1158  {
1159  /* Check if we want to go up a level*/
1160  if ( !( strncmp( DirItems[i].Name + 1, "..", 2 ) ) )
1161  {
1162  u8* ptr = CurrentPath + ( sizeof( CurrentPath ) - 1 );
1163 
1164 
1165  /* Remove directory name from CurrentPath*/
1166  for ( i = MAX_PATH_LENGTH; i > 0; i-- )
1167  {
1168  if ( ( *ptr == '/' ) && ( !EOP ) )
1169  {
1170  /* Found end of current path */
1171  EOP = 1;
1172  }
1173  else if ( ( *ptr == '/' ) && ( EOP ) )
1174  {
1175  break; /* erased subdir and found //*/
1176  }
1177  *ptr-- = 0;
1178  }
1179  //~ DFS_strcpy( dir, CurrentPath );
1180  str_cpy( dir, CurrentPath );
1181  }
1182  else
1183  {
1184  str_cpy( dir, CurrentPath );
1185  len_t strLen = my_strlen( DirItems[i].Name );
1186  strncat( dir, DirItems[i].Name + 1, strLen - 2 ); /* strip '[ ]'*/
1187  }
1188 
1189  /* Open directory*/
1190  if ( (retval = FS_OpenDirectory( &volume_info, dir, &directory_info )) )
1191  {
1192  /* Cannot open dir*/
1193  /* add error handling. Go back to root for now*/
1194  if ( ( retval == FR_NO_PATH ) ||
1195  ( retval == FR_INVALID_NAME ) )
1196  {
1197  FS_OpenDirectory( &volume_info, "", &directory_info );
1198  }
1199  /* Reset CurrentPath */
1200  mem_set( CurrentPath, 0, sizeof( CurrentPath ) );
1201  }
1202  else
1203  {
1204  /* Check if we didn't go up*/
1205  if ( !EOP )
1206  {
1207  u8 len = my_strlen( CurrentPath );
1208  u8 j;
1209 
1210  /* Remove trailing spaces*/
1211  for ( j = len; j > 0; j-- )
1212  {
1213  if ( CurrentPath[j] == 0x20 )
1214  CurrentPath[j] = 0;
1215  }
1216 
1217  /* Add new dir to current path*/
1218  len_t strLen = my_strlen( DirItems[i].Name );
1219  strncat( CurrentPath, DirItems[i].Name + 1, strLen - 2 ); /* strip '[ ]'*/
1220 
1221  /* Remove trailing spaces again*/
1222  len = my_strlen( CurrentPath );
1223  for ( j = len; j > 0; j-- )
1224  {
1225  if ( CurrentPath[j] == 0x20 )
1226  CurrentPath[j] = 0;
1227  }
1228 
1229  /* Add dir seperator*/
1230  strcat( CurrentPath, "/" );
1231  }
1232  }
1233 
1234  /* Update directory list*/
1235  FS_Explorer_UpdateList();
1236 
1237  /* Clear display*/
1238  DRAW_Clear();
1239 
1240  /* Show list*/
1241  DirMenu.NbDisp = MAX_LIST_ITEMS_DISP;
1242  LIST_Set( &DirMenu, 0, 0, 1 );
1243 
1244  } /* end (DirItems[i].flags & FS_ATTR_DIRECTORY)*/
1245  else
1246  /* File selected from list*/
1247  {
1248  // Add file name to the path
1249  len_t strLen = my_strlen( DirItems[i].Name );
1250  strncat( CurrentPath, DirItems[i].Name, strLen + 1 );
1251  //FS_Unmount( MMCSD_SDIO ); //YRT130605 Let the file system mounted for the calling app
1252 
1253  // MENU_RestoreAppliDivider(); //YRT1307123 Let the divider restored by the calling app
1254  return 1;
1255  }
1256 
1257  } /* end (i != (DirMenu.NbItems - 1) ) && !SDCardfault)*/
1258  else
1259  {
1260  /* Quit requested*/
1261  //FS_Unmount( MMCSD_SDIO ); //YRT130605 Let the file system mounted for the calling app
1262 
1263  // Restore application divider
1264  //MENU_RestoreAppliDivider(); //YRT1307123 Let the divider restored by the calling app
1265 
1266  return 0;
1267  }
1268 
1269  } /* end (i != -1)*/
1270 
1271  return -1;
1272 }
1273 
1274 /*******************************************************************************
1275 * Function Name : NVIC_Config_SDIO
1276 * Description : Configures SDIO IRQ channel.
1277 * Input : None
1278 * Output : None
1279 * Return : None
1280 *******************************************************************************/
1281 NODEBUG void NVIC_Config_SDIO( void )
1282 {
1283 #if SDCARD_SDIO
1284  NVIC_InitTypeDef NVIC_InitStructure;
1285 
1286  /* Configure the NVIC Preemption Priority Bits */
1287  NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );
1288 
1289  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
1290  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
1291  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
1292  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
1293  NVIC_Init( &NVIC_InitStructure );
1294 
1295  NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
1296  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
1297  NVIC_Init( &NVIC_InitStructure );
1298 #endif
1299 }
1300 
1301