39 #define MAX_DIRS LIST_MAXITEM
40 #define MAX_LIST_ITEMS_DISP 7
41 #define MAX_PATH_LENGTH 200
43 #define MAXDIRNAMELEN 30
45 #define MAXDIRNAMELEN 17
47 #define BUFSIZE 512 // Size of buffer used for file copy and compare
58 static u8 SDCardfault = 0;
65 u8* FS_PathFilter = 0;
69 u8 Name[MAXDIRNAMELEN];
73 struct DirItem DirItems[MAX_DIRS];
76 tList DirMenu = { 1,
"SD Card", MAX_DIRS, MAXDIRNAMELEN, 0, 0, 0, 0, MAX_LIST_ITEMS_DISP, 0, 0, };
91 extern divider_t Appli_Divider;
92 extern divider_t Appli_DividerBkp;
95 void NVIC_Config_SDIO(
void );
113 NODEBUG
void FillVolInfo(
PVOLINFO volinfo )
115 volinfo->
unit = fs.drv;
125 volinfo->
fat1 = fs.fatbase;
143 NODEBUG
void FillDirInfo(
PDIRINFO dirinfo, DIR* dir )
165 NODEBUG
void FillDirEnt(
PDIRENT dirent )
167 strncpy( dirent->
name, fileInfo.fname,
sizeof( dirent->
name ) );
168 dirent->
name[
sizeof( dirent->
name ) - 1] =
'\0';
169 dirent->
attr = fileInfo.fattrib;
186 NODEBUG
void FillFileInfo(
PFILEINFO fileinfo )
188 FillVolInfo( fileinfo->
volinfo );
191 fileinfo->
mode = file.flag;
193 fileinfo->
filelen = file.fsize;
194 fileinfo->
cluster = file.curr_clust;
224 u32 retVal =
f_mount( 0, &fs );
229 const TCHAR* path =
"";
234 FillVolInfo( &volume_info );
298 u32 retVal = DFS_NOPATH;
305 mode |= FA_OPEN_ALWAYS;
308 retVal =
f_open( &file, path, mode );
311 FillFileInfo( fileinfo );
336 u32 FS_ReadFile(
PFILEINFO fileinfo, u8* buffer, u32* successcount, u32 len )
340 u32 retVal = DFS_NULLPOINTER;
342 if ( buffer && successcount )
344 retVal =
f_read( &file, buffer, len, (
int* ) successcount );
347 FillFileInfo( fileinfo );
391 u32 FS_WriteFile(
PFILEINFO fileinfo, u8* buffer, u32* successcount, u32 len )
395 u32 retVal = DFS_NULLPOINTER;
396 retVal =
f_write( &file, buffer, len, (
int* ) successcount );
398 FillFileInfo( fileinfo );
423 FillFileInfo( fileinfo );
450 u32 FS_Delete(
PVOLINFO volinfo, u8* path )
457 FillVolInfo( volinfo );
495 u32 retVal =
f_readdir( &CurrentDir, &fileInfo );
496 if ( fileInfo.fname[0] == 0 )
500 FillDirEnt( dirent );
533 u32 retVal = FR_NO_PATH;
537 len_t len = my_strlen( dirname );
538 if ( dirname[len - 1] ==
'/' )
539 dirname[len - 1] = 0;
542 retVal =
f_opendir( &CurrentDir, dirname );
545 FillVolInfo( volinfo );
546 FillDirInfo( dirinfo, &CurrentDir );
579 u32 FS_GetVolumeInfo( u8 unit, u32 startsector,
PVOLINFO volinfo )
584 const TCHAR* path =
"";
589 FillVolInfo( volinfo );
615 u8* FS_GetSDCardCurrentPath(
void )
617 return ( u8* ) &CurrentPath;
637 VOLINFO* FS_GetSDCardVolInfo(
void )
654 u8* FS_GetPathFilter(
void )
656 return FS_PathFilter;
674 void FS_SetPathFilter( u8* filter )
677 FS_PathFilter = strupr( filter );
696 u32 FS_Seek(
PFILEINFO fileinfo, u32 offset )
700 u32 retVal =
f_lseek( &file, offset );
703 FillFileInfo( fileinfo );
725 u32 retVal = f_tell( &file );
728 FillFileInfo( fileinfo );
747 u32 FS_Gets(
char* ptr,
int len,
PFILEINFO fileinfo)
749 char* ret_val = f_gets (ptr, len, &file);
752 FillFileInfo( fileinfo );
776 u32 retVal = f_size( &file );
779 FillFileInfo( fileinfo );
800 u32 retVal = f_eof( &file );
803 FillFileInfo( fileinfo );
822 NODEBUG2 u32 FS_FileCopy(
char* dest,
char* src )
824 int total_count_debug ;
825 int count, successcount ;
826 extern FIL file, file2;
830 total_count_debug = 0;
833 if (
f_open( &file, src, FA_READ ) )
836 if (
f_open( &file2, dest, FA_CREATE_ALWAYS | FA_WRITE ) )
842 if ( !
f_read( &file, buf, BUFSIZE, &count ) && count )
847 if ( !
f_write( &file2, buf, count, &successcount ) )
849 total_count_debug += successcount;
876 u32 FS_FileCmp(
char* fn1,
char* fn2 )
878 int total_checked_debug = 0;
880 extern FIL file, file2;
881 char buf1[BUFSIZE+1];
882 char buf2[BUFSIZE+1];
885 total_checked_debug = 0;
887 if (
f_open( &file, fn2, FA_READ ) )
890 if (
f_open( &file2, fn1, FA_READ ) )
896 if (
f_read( &file, buf1, BUFSIZE, &count1 ) )
901 if (
f_read( &file2, buf2, BUFSIZE, &count2 ) )
906 if ( count1 == count2 )
912 ret =
mem_cmp( buf1, buf2, count1 );
914 total_checked_debug += count1;
920 if ( count1 < BUFSIZE )
941 NODEBUG
void FS_Explorer_UpdateList(
void )
946 mem_set( DirItems, 0,
sizeof( DirItems ) );
949 while ( (
f_readdir( &CurrentDir, &fileInfo ) == FR_OK ) && fileInfo.fname[0] )
952 fn = *fileInfo.lfname ? fileInfo.lfname : fileInfo.fname;
956 if ( ( i == 0 ) && strcmp( CurrentPath,
"" ) )
958 mem_set( (
void* )DirItems[i].Name, 0, MAXDIRNAMELEN );
959 strcat( DirItems[i].Name,
"[..]" );
960 DirMenu.Items[i].Text = DirItems[i].Name;
966 if ( fileInfo.fattrib & AM_DIR )
968 if ( strncmp( fn,
". ", 2 ) )
970 strcat( DirItems[i].Name,
"[" );
971 strncat( DirItems[i].Name, fn, MAXDIRNAMELEN );
972 strcat( DirItems[i].Name,
"]" );
974 DirMenu.Items[i].Text = DirItems[i].Name;
982 u8* ext = strrchr( fn,
'.' );
986 if ( ( FS_PathFilter == 0 ) || ( strncmp( ext, FS_PathFilter, 3 ) == 0 ) )
988 mem_cpy( DirItems[i].Name, fn, MAXDIRNAMELEN - 1 );
989 DirMenu.Items[i].Text = DirItems[i].Name;
1001 if ( ( i == 0 ) && strcmp( CurrentPath,
"" ) )
1003 mem_set( (
void* )DirItems[i].Name, 0, MAXDIRNAMELEN );
1004 mem_cpy( DirItems[i].Name,
"[..]", 4 );
1005 DirMenu.Items[i].Text = DirItems[i].Name;
1011 DirMenu.Items[i].Text =
"Quit";
1013 DirMenu.NbItems = i;
1014 DirMenu.NbDisp = i > MAX_LIST_ITEMS_DISP ? MAX_LIST_ITEMS_DISP : i;
1018 DirMenu.XSize = 128;
1019 DirMenu.YSize = 140;
1035 NODEBUG2
enum MENU_code FS_Explorer_Ini(
void )
1037 DirMenu.fdispTitle = 1;
1038 DirMenu.Title =
" SDCard ";
1039 DirMenu.NbItems = 30;
1042 DirMenu.XPos = DirMenu.YPos = 0;
1043 DirMenu.XSize = DirMenu.YSize = 0;
1044 DirMenu.NbDisp = MAX_LIST_ITEMS_DISP;
1045 DirMenu.SelectedItem = 0;
1046 DirMenu.FirstDisplayItem = 0;
1048 mem_set( CurrentPath, 0,
sizeof( CurrentPath ) );
1056 if ( StartMBR != FR_OK )
1060 if ( StartMBR != FR_OK )
1062 DirMenu.Items[0].Text =
"No SD Card";
1070 if ( FS_GetVolumeInfo( 0, StartMBR, &volume_info ) )
1072 DirMenu.Items[0].Text =
"Err: GetVolInfo";
1080 if ( FS_OpenDirectory( &volume_info,
"", &directory_info ) )
1082 DirMenu.Items[0].Text =
"Err: Open Root";
1090 DirMenu.NbItems = 2;
1091 DirMenu.Items[1].Text =
"Quit";
1098 fileInfo.lfname = ( TCHAR* ) LfnBuf;
1099 fileInfo.lfsize =
sizeof( LfnBuf );
1102 FS_Explorer_UpdateList();
1105 Appli_DividerBkp = Appli_Divider;
1137 NODEBUG2 s32 FS_Explorer(
void )
1151 if ( ( i != ( DirMenu.NbItems - 1 ) ) && !SDCardfault )
1154 mem_set( dir, 0,
sizeof( dir ) );
1160 if ( !( strncmp( DirItems[i].Name + 1,
"..", 2 ) ) )
1162 u8* ptr = CurrentPath + (
sizeof( CurrentPath ) - 1 );
1168 if ( ( *ptr ==
'/' ) && ( !EOP ) )
1173 else if ( ( *ptr ==
'/' ) && ( EOP ) )
1185 len_t strLen = my_strlen( DirItems[i].Name );
1186 strncat( dir, DirItems[i].Name + 1, strLen - 2 );
1190 if ( (retval = FS_OpenDirectory( &volume_info, dir, &directory_info )) )
1194 if ( ( retval == FR_NO_PATH ) ||
1195 ( retval == FR_INVALID_NAME ) )
1197 FS_OpenDirectory( &volume_info,
"", &directory_info );
1200 mem_set( CurrentPath, 0,
sizeof( CurrentPath ) );
1207 u8 len = my_strlen( CurrentPath );
1211 for ( j = len; j > 0; j-- )
1213 if ( CurrentPath[j] == 0x20 )
1218 len_t strLen = my_strlen( DirItems[i].Name );
1219 strncat( CurrentPath, DirItems[i].Name + 1, strLen - 2 );
1222 len = my_strlen( CurrentPath );
1223 for ( j = len; j > 0; j-- )
1225 if ( CurrentPath[j] == 0x20 )
1230 strcat( CurrentPath,
"/" );
1235 FS_Explorer_UpdateList();
1241 DirMenu.NbDisp = MAX_LIST_ITEMS_DISP;
1249 len_t strLen = my_strlen( DirItems[i].Name );
1250 strncat( CurrentPath, DirItems[i].Name, strLen + 1 );
1281 NODEBUG
void NVIC_Config_SDIO(
void )
1284 NVIC_InitTypeDef NVIC_InitStructure;
1287 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );
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 );
1295 NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
1296 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
1297 NVIC_Init( &NVIC_InitStructure );