summaryrefslogtreecommitdiff
path: root/fatfs/documents/res
diff options
context:
space:
mode:
Diffstat (limited to 'fatfs/documents/res')
-rw-r--r--fatfs/documents/res/app2.c77
-rw-r--r--fatfs/documents/res/app4.c94
-rw-r--r--fatfs/documents/res/app5.c38
-rw-r--r--fatfs/documents/res/app6.c61
-rw-r--r--fatfs/documents/res/f4.pngbin2335 -> 1973 bytes
-rw-r--r--fatfs/documents/res/f5.pngbin2479 -> 2224 bytes
-rw-r--r--fatfs/documents/res/funcs.pngbin22722 -> 26839 bytes
-rw-r--r--fatfs/documents/res/layers2.pngbin3741 -> 4950 bytes
-rw-r--r--fatfs/documents/res/mkfatimg.zipbin686683 -> 778875 bytes
-rw-r--r--fatfs/documents/res/mkfs.xlsbin3238912 -> 0 bytes
-rw-r--r--fatfs/documents/res/mkfs.xlsxbin0 -> 1491997 bytes
-rw-r--r--fatfs/documents/res/modules.pngbin17469 -> 15396 bytes
-rw-r--r--fatfs/documents/res/uniconv.zipbin0 -> 4175 bytes
13 files changed, 193 insertions, 77 deletions
diff --git a/fatfs/documents/res/app2.c b/fatfs/documents/res/app2.c
index 3de3eee..415c4bc 100644
--- a/fatfs/documents/res/app2.c
+++ b/fatfs/documents/res/app2.c
@@ -1,65 +1,78 @@
/*------------------------------------------------------------/
-/ Remove all contents of a directory
-/ This function works regardless of FF_FS_RPATH.
-/------------------------------------------------------------*/
+/ Delete a sub-directory even if it contains any file
+/-------------------------------------------------------------/
+/ The delete_node() function is for R0.12+.
+/ It works regardless of FF_FS_RPATH.
+*/
-FILINFO fno;
-
-FRESULT empty_directory (
- char* path /* Working buffer filled with start directory */
+FRESULT delete_node (
+ TCHAR* path, /* Path name buffer with the sub-directory to delete */
+ UINT sz_buff, /* Size of path name buffer (items) */
+ FILINFO* fno /* Name read buffer */
)
{
UINT i, j;
FRESULT fr;
DIR dir;
- fr = f_opendir(&dir, path);
- if (fr == FR_OK) {
- for (i = 0; path[i]; i++) ;
- path[i++] = '/';
- for (;;) {
- fr = f_readdir(&dir, &fno);
- if (fr != FR_OK || !fno.fname[0]) break;
- if (_FS_RPATH && fno.fname[0] == '.') continue;
- j = 0;
- do
- path[i+j] = fno.fname[j];
- while (fno.fname[j++]);
- if (fno.fattrib & AM_DIR) {
- fr = empty_directory(path);
- if (fr != FR_OK) break;
+
+ fr = f_opendir(&dir, path); /* Open the sub-directory to make it empty */
+ if (fr != FR_OK) return fr;
+
+ for (i = 0; path[i]; i++) ; /* Get current path length */
+ path[i++] = _T('/');
+
+ for (;;) {
+ fr = f_readdir(&dir, fno); /* Get a directory item */
+ if (fr != FR_OK || !fno->fname[0]) break; /* End of directory? */
+ j = 0;
+ do { /* Make a path name */
+ if (i + j >= sz_buff) { /* Buffer over flow? */
+ fr = 100; break; /* Fails with 100 when buffer overflow */
}
+ path[i + j] = fno->fname[j];
+ } while (fno->fname[j++]);
+ if (fno->fattrib & AM_DIR) { /* Item is a sub-directory */
+ fr = delete_node(path, sz_buff, fno);
+ } else { /* Item is a file */
fr = f_unlink(path);
- if (fr != FR_OK) break;
}
- path[--i] = '\0';
- closedir(&dir);
+ if (fr != FR_OK) break;
}
+ path[--i] = 0; /* Restore the path name */
+ f_closedir(&dir);
+
+ if (fr == FR_OK) fr = f_unlink(path); /* Delete the empty sub-directory */
return fr;
}
-int main (void)
+
+int main (void) /* How to use */
{
FRESULT fr;
FATFS fs;
- char buff[256]; /* Working buffer */
+ TCHAR buff[256];
+ FILINFO fno;
+ f_mount(&fs, _T("5:"), 0);
- f_mount(&fs, "", 0);
+ /* Directory to be deleted */
+ _tcscpy(buff, _T("5:dir"));
- strcpy(buff, "/"); /* Directory to be emptied */
- fr = empty_directory(buff);
+ /* Delete the directory */
+ fr = delete_node(buff, sizeof buff / sizeof buff[0], &fno);
+ /* Check the result */
if (fr) {
- printf("Function failed. (%u)\n", fr);
+ _tprintf(_T("Failed to delete the directory. (%u)\n"), fr);
return fr;
} else {
- printf("All contents in the %s are successfully removed.\n", buff);
+ _tprintf(_T("The directory and the contents have successfully been deleted.\n"), buff);
return 0;
}
}
diff --git a/fatfs/documents/res/app4.c b/fatfs/documents/res/app4.c
index 4209f39..c46d1a0 100644
--- a/fatfs/documents/res/app4.c
+++ b/fatfs/documents/res/app4.c
@@ -10,9 +10,9 @@
#include "diskio.h" /* Declarations of disk functions */
-static
-DWORD pn ( /* Pseudo random number generator */
- DWORD pns /* 0:Initialize, !0:Read */
+
+static DWORD pn ( /* Pseudo random number generator */
+ DWORD pns /* 0:Initialize, !0:Read */
)
{
static DWORD lfsr;
@@ -50,8 +50,8 @@ int test_diskio (
printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);
- if (sz_buff < _MAX_SS + 4) {
- printf("Insufficient work area to run program.\n");
+ if (sz_buff < FF_MAX_SS + 8) {
+ printf("Insufficient work area to run the program.\n");
return 1;
}
@@ -115,7 +115,7 @@ int test_diskio (
}
/* Single sector write test */
- printf("**** Single sector write test 1 ****\n");
+ printf("**** Single sector write test ****\n");
lba = 0;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
@@ -145,52 +145,56 @@ int test_diskio (
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 10;
}
pns++;
printf("**** Multiple sector write test ****\n");
- lba = 1; ns = sz_buff / sz_sect;
+ lba = 5; ns = sz_buff / sz_sect;
if (ns > 4) ns = 4;
- for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
- printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
- dr = disk_write(pdrv, pbuff, lba, ns);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 11;
- }
- printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
- dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 12;
- }
- memset(pbuff, 0, sz_sect * ns);
- printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
- dr = disk_read(pdrv, pbuff, lba, ns);
- if (dr == RES_OK) {
- printf(" - ok.\n");
- } else {
- printf(" - failed.\n");
- return 13;
- }
- for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
- if (n == (UINT)(sz_sect * ns)) {
- printf(" Data matched.\n");
+ if (ns > 1) {
+ for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
+ printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
+ dr = disk_write(pdrv, pbuff, lba, ns);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 11;
+ }
+ printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
+ dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 12;
+ }
+ memset(pbuff, 0, sz_sect * ns);
+ printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
+ dr = disk_read(pdrv, pbuff, lba, ns);
+ if (dr == RES_OK) {
+ printf(" - ok.\n");
+ } else {
+ printf(" - failed.\n");
+ return 13;
+ }
+ for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
+ if (n == (UINT)(sz_sect * ns)) {
+ printf(" Read data matched.\n");
+ } else {
+ printf(" Read data differs from the data written.\n");
+ return 14;
+ }
} else {
- printf("Failed: Read data differs from the data written.\n");
- return 14;
+ printf(" Test skipped.\n");
}
pns++;
- printf("**** Single sector write test (misaligned address) ****\n");
+ printf("**** Single sector write test (unaligned buffer address) ****\n");
lba = 5;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba);
@@ -220,9 +224,9 @@ int test_diskio (
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 18;
}
pns++;
@@ -274,9 +278,9 @@ int test_diskio (
}
for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;
if (n == (UINT)(sz_sect * 2)) {
- printf(" Data matched.\n");
+ printf(" Read data matched.\n");
} else {
- printf("Failed: Read data differs from the data written.\n");
+ printf(" Read data differs from the data written.\n");
return 24;
}
} else {
diff --git a/fatfs/documents/res/app5.c b/fatfs/documents/res/app5.c
new file mode 100644
index 0000000..2739019
--- /dev/null
+++ b/fatfs/documents/res/app5.c
@@ -0,0 +1,38 @@
+/*----------------------------------------------------------------------/
+/ Test if the file is contiguous /
+/----------------------------------------------------------------------*/
+
+FRESULT test_contiguous_file (
+ FIL* fp, /* [IN] Open file object to be checked */
+ int* cont /* [OUT] 1:Contiguous, 0:Fragmented or zero-length */
+)
+{
+ DWORD clst, clsz, step;
+ FSIZE_t fsz;
+ FRESULT fr;
+
+
+ *cont = 0;
+ fr = f_rewind(fp); /* Validates and prepares the file */
+ if (fr != FR_OK) return fr;
+
+#if FF_MAX_SS == FF_MIN_SS
+ clsz = (DWORD)fp->obj.fs->csize * FF_MAX_SS; /* Cluster size */
+#else
+ clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize;
+#endif
+ fsz = f_size(fp);
+ if (fsz > 0) {
+ clst = fp->obj.sclust - 1; /* A cluster leading the first cluster for first test */
+ while (fsz) {
+ step = (fsz >= clsz) ? clsz : (DWORD)fsz;
+ fr = f_lseek(fp, f_tell(fp) + step); /* Advances file pointer a cluster */
+ if (fr != FR_OK) return fr;
+ if (clst + 1 != fp->clust) break; /* Is not the cluster next to previous one? */
+ clst = fp->clust; fsz -= step; /* Get current cluster for next test */
+ }
+ if (fsz == 0) *cont = 1; /* All done without fail? */
+ }
+
+ return FR_OK;
+}
diff --git a/fatfs/documents/res/app6.c b/fatfs/documents/res/app6.c
new file mode 100644
index 0000000..4a3565e
--- /dev/null
+++ b/fatfs/documents/res/app6.c
@@ -0,0 +1,61 @@
+/*---------------------------------------------------------------------*/
+/* Raw Read/Write Throughput Checker */
+/*---------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <systimer.h>
+#include "diskio.h"
+#include "ff.h"
+
+
+int test_raw_speed (
+ BYTE pdrv, /* Physical drive number */
+ DWORD lba, /* Start LBA for read/write test */
+ DWORD len, /* Number of bytes to read/write (must be multiple of sz_buff) */
+ void* buff, /* Read/write buffer */
+ UINT sz_buff /* Size of read/write buffer (must be multiple of FF_MAX_SS) */
+)
+{
+ WORD ss;
+ DWORD ofs, tmr;
+
+
+#if FF_MIN_SS != FF_MAX_SS
+ if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) {
+ printf("\ndisk_ioctl() failed.\n");
+ return 0;
+ }
+#else
+ ss = FF_MAX_SS;
+#endif
+
+ printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
+ tmr = systimer();
+ for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
+ if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
+ printf("\ndisk_write() failed.\n");
+ return 0;
+ }
+ }
+ if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) {
+ printf("\ndisk_ioctl() failed.\n");
+ return 0;
+ }
+ tmr = systimer() - tmr;
+ printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr);
+
+ printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
+ tmr = systimer();
+ for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
+ if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
+ printf("\ndisk_read() failed.\n");
+ return 0;
+ }
+ }
+ tmr = systimer() - tmr;
+ printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr);
+
+ printf("Test completed.\n");
+ return 1;
+}
+
diff --git a/fatfs/documents/res/f4.png b/fatfs/documents/res/f4.png
index f9a6b46..2c00ddc 100644
--- a/fatfs/documents/res/f4.png
+++ b/fatfs/documents/res/f4.png
Binary files differ
diff --git a/fatfs/documents/res/f5.png b/fatfs/documents/res/f5.png
index b110b29..bc0171a 100644
--- a/fatfs/documents/res/f5.png
+++ b/fatfs/documents/res/f5.png
Binary files differ
diff --git a/fatfs/documents/res/funcs.png b/fatfs/documents/res/funcs.png
index 022cd74..f381ec5 100644
--- a/fatfs/documents/res/funcs.png
+++ b/fatfs/documents/res/funcs.png
Binary files differ
diff --git a/fatfs/documents/res/layers2.png b/fatfs/documents/res/layers2.png
index 406c453..c7dbef4 100644
--- a/fatfs/documents/res/layers2.png
+++ b/fatfs/documents/res/layers2.png
Binary files differ
diff --git a/fatfs/documents/res/mkfatimg.zip b/fatfs/documents/res/mkfatimg.zip
index 67d423b..63e6ad7 100644
--- a/fatfs/documents/res/mkfatimg.zip
+++ b/fatfs/documents/res/mkfatimg.zip
Binary files differ
diff --git a/fatfs/documents/res/mkfs.xls b/fatfs/documents/res/mkfs.xls
deleted file mode 100644
index ee6b2bf..0000000
--- a/fatfs/documents/res/mkfs.xls
+++ /dev/null
Binary files differ
diff --git a/fatfs/documents/res/mkfs.xlsx b/fatfs/documents/res/mkfs.xlsx
new file mode 100644
index 0000000..6024888
--- /dev/null
+++ b/fatfs/documents/res/mkfs.xlsx
Binary files differ
diff --git a/fatfs/documents/res/modules.png b/fatfs/documents/res/modules.png
index b1ab987..d7e69a3 100644
--- a/fatfs/documents/res/modules.png
+++ b/fatfs/documents/res/modules.png
Binary files differ
diff --git a/fatfs/documents/res/uniconv.zip b/fatfs/documents/res/uniconv.zip
new file mode 100644
index 0000000..be7d84f
--- /dev/null
+++ b/fatfs/documents/res/uniconv.zip
Binary files differ