800*320工程文件+初始demo提交
44
SW/components/modules/fatfs/documents/res/app1.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*------------------------------------------------------------/
|
||||
/ Open or create a file in append mode
|
||||
/ (This function was sperseded by FA_OPEN_APPEND flag at FatFs R0.12a)
|
||||
/------------------------------------------------------------*/
|
||||
|
||||
FRESULT open_append (
|
||||
FIL* fp, /* [OUT] File object to create */
|
||||
const char* path /* [IN] File name to be opened */
|
||||
)
|
||||
{
|
||||
FRESULT fr;
|
||||
|
||||
/* Opens an existing file. If not exist, creates a new file. */
|
||||
fr = f_open(fp, path, FA_WRITE | FA_OPEN_ALWAYS);
|
||||
if (fr == FR_OK) {
|
||||
/* Seek to end of the file to append data */
|
||||
fr = f_lseek(fp, f_size(fp));
|
||||
if (fr != FR_OK)
|
||||
f_close(fp);
|
||||
}
|
||||
return fr;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
FRESULT fr;
|
||||
FATFS fs;
|
||||
FIL fil;
|
||||
|
||||
/* Open or create a log file and ready to append */
|
||||
f_mount(&fs, "", 0);
|
||||
fr = open_append(&fil, "logfile.txt");
|
||||
if (fr != FR_OK) return 1;
|
||||
|
||||
/* Append a line */
|
||||
f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);
|
||||
|
||||
/* Close the file */
|
||||
f_close(&fil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
81
SW/components/modules/fatfs/documents/res/app2.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*------------------------------------------------------------/
|
||||
/ 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.
|
||||
*/
|
||||
|
||||
|
||||
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); /* 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; /* 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) /* How to use */
|
||||
{
|
||||
FRESULT fr;
|
||||
FATFS fs;
|
||||
TCHAR buff[256];
|
||||
FILINFO fno;
|
||||
|
||||
|
||||
f_mount(&fs, _T("5:"), 0);
|
||||
|
||||
/* Directory to be deleted */
|
||||
_tcscpy(buff, _T("5:dir"));
|
||||
|
||||
/* Delete the directory */
|
||||
fr = delete_node(buff, sizeof buff / sizeof buff[0], &fno);
|
||||
|
||||
/* Check the result */
|
||||
if (fr) {
|
||||
_tprintf(_T("Failed to delete the directory. (%u)\n"), fr);
|
||||
return fr;
|
||||
} else {
|
||||
_tprintf(_T("The directory and the contents have successfully been deleted.\n"), buff);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
109
SW/components/modules/fatfs/documents/res/app3.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*----------------------------------------------------------------------/
|
||||
/ Allocate a contiguous area to the file
|
||||
/-----------------------------------------------------------------------/
|
||||
/ This function checks if the file is contiguous with desired size.
|
||||
/ If not, a block of contiguous sectors is allocated to the file.
|
||||
/ If the file has been opened without FA_WRITE flag, it only checks if
|
||||
/ the file is contiguous and returns the resulut.
|
||||
/-----------------------------------------------------------------------/
|
||||
/ This function can work with FatFs R0.09 - R0.11a.
|
||||
/ It is incompatible with R0.12+. Use f_expand function instead.
|
||||
/----------------------------------------------------------------------*/
|
||||
|
||||
/* Declarations of FatFs internal functions accessible from applications.
|
||||
/ This is intended to be used for disk checking/fixing or dirty hacks :-) */
|
||||
DWORD clust2sect (FATFS* fs, DWORD clst);
|
||||
DWORD get_fat (FATFS* fs, DWORD clst);
|
||||
FRESULT put_fat (FATFS* fs, DWORD clst, DWORD val);
|
||||
|
||||
|
||||
DWORD allocate_contiguous_clusters ( /* Returns the first sector in LBA (0:error or not contiguous) */
|
||||
FIL* fp, /* Pointer to the open file object */
|
||||
DWORD len /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
DWORD csz, tcl, ncl, ccl, cl;
|
||||
|
||||
|
||||
if (f_lseek(fp, 0) || !len) /* Check if the given parameters are valid */
|
||||
return 0;
|
||||
csz = 512UL * fp->fs->csize; /* Cluster size in unit of byte (assuming 512 bytes/sector) */
|
||||
tcl = (len + csz - 1) / csz; /* Total number of clusters required */
|
||||
len = tcl * csz; /* Round-up file size to the cluster boundary */
|
||||
|
||||
/* Check if the existing cluster chain is contiguous */
|
||||
if (len == fp->fsize) {
|
||||
ncl = 0; ccl = fp->sclust;
|
||||
do {
|
||||
cl = get_fat(fp->fs, ccl); /* Get the cluster status */
|
||||
if (cl + 1 < 3) return 0; /* Hard error? */
|
||||
if (cl != ccl + 1 && cl < fp->fs->n_fatent) break; /* Not contiguous? */
|
||||
ccl = cl;
|
||||
} while (++ncl < tcl);
|
||||
if (ncl == tcl) /* Is the file contiguous? */
|
||||
return clust2sect(fp->fs, fp->sclust); /* File is contiguous. Return the start sector */
|
||||
}
|
||||
|
||||
/* File is not contiguous */
|
||||
#if _FS_READONLY
|
||||
return 0; /* Exit if in read-only cfg. */
|
||||
#else
|
||||
if (!(fp->flag & FA_WRITE)) return 0; /* Exit if the file object is for read-only */
|
||||
|
||||
if (f_truncate(fp)) return 0; /* Remove the non-contiguous chain */
|
||||
|
||||
/* Find a free contiguous area */
|
||||
ccl = cl = 2; ncl = 0;
|
||||
do {
|
||||
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
|
||||
if (get_fat(fp->fs, cl)) { /* Encounterd a cluster in use */
|
||||
do { /* Skip the block of used clusters */
|
||||
cl++;
|
||||
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
|
||||
} while (get_fat(fp->fs, cl));
|
||||
ccl = cl; ncl = 0;
|
||||
}
|
||||
cl++; ncl++;
|
||||
} while (ncl < tcl);
|
||||
|
||||
/* Create a contiguous cluster chain */
|
||||
fp->fs->last_clust = ccl - 1;
|
||||
if (f_lseek(fp, len)) return 0;
|
||||
|
||||
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
FRESULT fr;
|
||||
DRESULT dr;
|
||||
FATFS fs;
|
||||
FIL fil;
|
||||
DWORD org;
|
||||
|
||||
|
||||
/* Open or create a file to write */
|
||||
f_mount(&fs, "", 0);
|
||||
fr = f_open(&fil, "fastrec.log", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
|
||||
if (fr) return 1;
|
||||
|
||||
/* Check if the file is 256MB in size and occupies a contiguous area.
|
||||
/ If not, a contiguous area will be re-allocated to the file. */
|
||||
org = allocate_contiguous_clusters(&fil, 0x10000000);
|
||||
if (!org) {
|
||||
printf("Function failed due to any error or insufficient contiguous area.\n");
|
||||
f_close(&fil);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Now you can read/write the file without filesystem layer. */
|
||||
...
|
||||
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512KiB from top of the file */
|
||||
...
|
||||
|
||||
f_close(&fil);
|
||||
return 0;
|
||||
}
|
||||
|
315
SW/components/modules/fatfs/documents/res/app4.c
Normal file
@ -0,0 +1,315 @@
|
||||
/*----------------------------------------------------------------------/
|
||||
/ Low level disk I/O module function checker /
|
||||
/-----------------------------------------------------------------------/
|
||||
/ WARNING: The data on the target drive will be lost!
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "ff.h" /* Declarations of sector size */
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
|
||||
|
||||
|
||||
static DWORD pn ( /* Pseudo random number generator */
|
||||
DWORD pns /* 0:Initialize, !0:Read */
|
||||
)
|
||||
{
|
||||
static DWORD lfsr;
|
||||
UINT n;
|
||||
|
||||
|
||||
if (pns) {
|
||||
lfsr = pns;
|
||||
for (n = 0; n < 32; n++) pn(0);
|
||||
}
|
||||
if (lfsr & 1) {
|
||||
lfsr >>= 1;
|
||||
lfsr ^= 0x80200003;
|
||||
} else {
|
||||
lfsr >>= 1;
|
||||
}
|
||||
return lfsr;
|
||||
}
|
||||
|
||||
|
||||
int test_diskio (
|
||||
BYTE pdrv, /* Physical drive number to be checked (all data on the drive will be lost) */
|
||||
UINT ncyc, /* Number of test cycles */
|
||||
DWORD* buff, /* Pointer to the working buffer */
|
||||
UINT sz_buff /* Size of the working buffer in unit of byte */
|
||||
)
|
||||
{
|
||||
UINT n, cc, ns;
|
||||
DWORD sz_drv, lba, lba2, sz_eblk, pns = 1;
|
||||
WORD sz_sect;
|
||||
BYTE *pbuff = (BYTE*)buff;
|
||||
DSTATUS ds;
|
||||
DRESULT dr;
|
||||
|
||||
|
||||
printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);
|
||||
|
||||
if (sz_buff < FF_MAX_SS + 8) {
|
||||
printf("Insufficient work area to run the program.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (cc = 1; cc <= ncyc; cc++) {
|
||||
printf("**** Test cycle %u of %u start ****\n", cc, ncyc);
|
||||
|
||||
printf(" disk_initalize(%u)", pdrv);
|
||||
ds = disk_initialize(pdrv);
|
||||
if (ds & STA_NOINIT) {
|
||||
printf(" - failed.\n");
|
||||
return 2;
|
||||
} else {
|
||||
printf(" - ok.\n");
|
||||
}
|
||||
|
||||
printf("**** Get drive size ****\n");
|
||||
printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv, (UINT)&sz_drv);
|
||||
sz_drv = 0;
|
||||
dr = disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_drv);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 3;
|
||||
}
|
||||
if (sz_drv < 128) {
|
||||
printf("Failed: Insufficient drive size to test.\n");
|
||||
return 4;
|
||||
}
|
||||
printf(" Number of sectors on the drive %u is %lu.\n", pdrv, sz_drv);
|
||||
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
printf("**** Get sector size ****\n");
|
||||
printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv, (UINT)&sz_sect);
|
||||
sz_sect = 0;
|
||||
dr = disk_ioctl(pdrv, GET_SECTOR_SIZE, &sz_sect);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 5;
|
||||
}
|
||||
printf(" Size of sector is %u bytes.\n", sz_sect);
|
||||
#else
|
||||
sz_sect = FF_MAX_SS;
|
||||
#endif
|
||||
|
||||
printf("**** Get block size ****\n");
|
||||
printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv, (UINT)&sz_eblk);
|
||||
sz_eblk = 0;
|
||||
dr = disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_eblk);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
}
|
||||
if (dr == RES_OK || sz_eblk >= 2) {
|
||||
printf(" Size of the erase block is %lu sectors.\n", sz_eblk);
|
||||
} else {
|
||||
printf(" Size of the erase block is unknown.\n");
|
||||
}
|
||||
|
||||
/* Single sector write test */
|
||||
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);
|
||||
dr = disk_write(pdrv, pbuff, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 6;
|
||||
}
|
||||
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 7;
|
||||
}
|
||||
memset(pbuff, 0, sz_sect);
|
||||
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
|
||||
dr = disk_read(pdrv, pbuff, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 8;
|
||||
}
|
||||
for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;
|
||||
if (n == sz_sect) {
|
||||
printf(" Read data matched.\n");
|
||||
} else {
|
||||
printf(" Read data differs from the data written.\n");
|
||||
return 10;
|
||||
}
|
||||
pns++;
|
||||
|
||||
printf("**** Multiple sector write test ****\n");
|
||||
lba = 5; ns = sz_buff / sz_sect;
|
||||
if (ns > 4) ns = 4;
|
||||
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(" Test skipped.\n");
|
||||
}
|
||||
pns++;
|
||||
|
||||
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);
|
||||
dr = disk_write(pdrv, pbuff+3, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 15;
|
||||
}
|
||||
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 16;
|
||||
}
|
||||
memset(pbuff+5, 0, sz_sect);
|
||||
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+5), lba);
|
||||
dr = disk_read(pdrv, pbuff+5, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 17;
|
||||
}
|
||||
for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;
|
||||
if (n == sz_sect) {
|
||||
printf(" Read data matched.\n");
|
||||
} else {
|
||||
printf(" Read data differs from the data written.\n");
|
||||
return 18;
|
||||
}
|
||||
pns++;
|
||||
|
||||
printf("**** 4GB barrier test ****\n");
|
||||
if (sz_drv >= 128 + 0x80000000 / (sz_sect / 2)) {
|
||||
lba = 6; lba2 = lba + 0x80000000 / (sz_sect / 2);
|
||||
for (n = 0, pn(pns); n < (UINT)(sz_sect * 2); n++) pbuff[n] = (BYTE)pn(0);
|
||||
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
|
||||
dr = disk_write(pdrv, pbuff, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 19;
|
||||
}
|
||||
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
|
||||
dr = disk_write(pdrv, pbuff+sz_sect, lba2, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 20;
|
||||
}
|
||||
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 21;
|
||||
}
|
||||
memset(pbuff, 0, sz_sect * 2);
|
||||
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
|
||||
dr = disk_read(pdrv, pbuff, lba, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 22;
|
||||
}
|
||||
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
|
||||
dr = disk_read(pdrv, pbuff+sz_sect, lba2, 1);
|
||||
if (dr == RES_OK) {
|
||||
printf(" - ok.\n");
|
||||
} else {
|
||||
printf(" - failed.\n");
|
||||
return 23;
|
||||
}
|
||||
for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;
|
||||
if (n == (UINT)(sz_sect * 2)) {
|
||||
printf(" Read data matched.\n");
|
||||
} else {
|
||||
printf(" Read data differs from the data written.\n");
|
||||
return 24;
|
||||
}
|
||||
} else {
|
||||
printf(" Test skipped.\n");
|
||||
}
|
||||
pns++;
|
||||
|
||||
printf("**** Test cycle %u of %u completed ****\n\n", cc, ncyc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
int rc;
|
||||
DWORD buff[FF_MAX_SS]; /* Working buffer (4 sector in size) */
|
||||
|
||||
/* Check function/compatibility of the physical drive #0 */
|
||||
rc = test_diskio(0, 3, buff, sizeof buff);
|
||||
|
||||
if (rc) {
|
||||
printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work with this disk driver.\n", rc);
|
||||
} else {
|
||||
printf("Congratulations! The disk driver works well.\n");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
38
SW/components/modules/fatfs/documents/res/app5.c
Normal file
@ -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_lseek(fp, 0); /* 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;
|
||||
}
|
61
SW/components/modules/fatfs/documents/res/app6.c
Normal file
@ -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;
|
||||
}
|
||||
|
BIN
SW/components/modules/fatfs/documents/res/f1.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
SW/components/modules/fatfs/documents/res/f2.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
SW/components/modules/fatfs/documents/res/f3.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
SW/components/modules/fatfs/documents/res/f4.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
SW/components/modules/fatfs/documents/res/f5.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
SW/components/modules/fatfs/documents/res/f6.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
SW/components/modules/fatfs/documents/res/f7.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
SW/components/modules/fatfs/documents/res/funcs.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
SW/components/modules/fatfs/documents/res/layers.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
SW/components/modules/fatfs/documents/res/layers1.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
SW/components/modules/fatfs/documents/res/layers2.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
SW/components/modules/fatfs/documents/res/layers3.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
SW/components/modules/fatfs/documents/res/mkfatimg.zip
Normal file
BIN
SW/components/modules/fatfs/documents/res/mkfs.xlsx
Normal file
BIN
SW/components/modules/fatfs/documents/res/modules.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
SW/components/modules/fatfs/documents/res/rwtest1.png
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
SW/components/modules/fatfs/documents/res/rwtest2.png
Normal file
After Width: | Height: | Size: 8.0 KiB |
BIN
SW/components/modules/fatfs/documents/res/rwtest3.png
Normal file
After Width: | Height: | Size: 2.9 KiB |