Changeset 75 for ctrl/firmware/Main/SES/Core
- Timestamp:
- Jan 30, 2025, 8:24:51 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ctrl/firmware/Main/SES/Core/Src/main_task.cpp
r74 r75 19 19 //UINT ret; 20 20 21 static FATFS fs; // Filesystem object21 static FATFS fs;// __attribute__((section(".DTCM_RAM"))); // Filesystem object 22 22 23 FRESULT scan_files (TCHAR* path); 24 FRESULT list_dir (const char* path); 23 25 24 26 //------------------------------------------------------------------------------ … … 26 28 [[noreturn]] void mainTaskStart(void *argument) 27 29 { 30 (void)argument; 31 28 32 FRESULT r = f_mount(&fs, (const TCHAR*)"", 1); // Mount the default drive 29 33 if (r != FR_OK) printf("Cannot mount SD-card!\n"); 30 else printf("SD-card was mounted.\n"); 34 else 35 { 36 printf("SD-card was mounted.\n"); 37 38 static TCHAR buff[256]; 39 strcpy (buff, "/"); 40 list_dir(buff); 41 } 31 42 32 43 while(1) … … 37 48 } 38 49 } 50 51 //------------------------------------------------------------------------------ 52 53 /* List contents of a directory */ 54 55 FRESULT list_dir (const TCHAR *path) 56 { 57 FRESULT res; 58 DIR dir; 59 FILINFO fno; 60 int nfile, ndir; 61 62 63 res = f_opendir(&dir, path); /* Open the directory */ 64 if (res == FR_OK) { 65 nfile = ndir = 0; 66 for (;;) { 67 res = f_readdir(&dir, &fno); /* Read a directory item */ 68 if (res != FR_OK || fno.fname[0] == 0) break; /* Error or end of dir */ 69 if (fno.fattrib & AM_DIR) { /* Directory */ 70 printf(" <DIR> %s\n", fno.fname); 71 ndir++; 72 } else { /* File */ 73 printf("%10u %s\n", fno.fsize, fno.fname); 74 nfile++; 75 } 76 } 77 f_closedir(&dir); 78 printf("%d dirs, %d files.\n", ndir, nfile); 79 } else { 80 printf("Failed to open \"%s\". (%u)\n", path, res); 81 } 82 return res; 83 } 84 85 //------------------------------------------------------------------------------ 86 87 /* Recursive scan of all items in the directory */ 88 89 FRESULT scan_files ( 90 TCHAR* path /* Start node to be scanned (***also used as work area***) */ 91 ) 92 { 93 FRESULT res; 94 DIR dir; 95 UINT i; 96 static FILINFO fno; 97 98 99 res = f_opendir(&dir, path); /* Open the directory */ 100 if (res == FR_OK) { 101 for (;;) { 102 res = f_readdir(&dir, &fno); /* Read a directory item */ 103 if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ 104 if (fno.fattrib & AM_DIR) { /* It is a directory */ 105 i = strlen(path); 106 sprintf(&path[i], "/%s", fno.fname); 107 res = scan_files(path); /* Enter the directory */ 108 if (res != FR_OK) break; 109 path[i] = 0; 110 } else { /* It is a file. */ 111 printf("%s/%s\n", path, fno.fname); 112 } 113 } 114 f_closedir(&dir); 115 } 116 117 return res; 118 }
Note: See TracChangeset
for help on using the changeset viewer.