精简项目
删除了不需要的文件,并整理了文件夹
67
PORTING/FATFS/doc/css_e.css
Normal file
@@ -0,0 +1,67 @@
|
||||
* {margin: 0; padding: 0; border-width: 0;}
|
||||
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}
|
||||
a:link {color: blue;}
|
||||
a:visited {color: darkmagenta;}
|
||||
a:hover {background-color: #a0ffff;}
|
||||
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
|
||||
abbr {border-width: 1px;}
|
||||
|
||||
p {margin: 0 0 0.3em 1em;}
|
||||
i {margin: 0 0.3em 0 0;}
|
||||
b {margin: 0 0.1em;}
|
||||
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
|
||||
strong {}
|
||||
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;}
|
||||
pre span.c {color: green;}
|
||||
pre span.k {color: blue;}
|
||||
pre span.arg {font-style: italic;}
|
||||
tt {margin: 0 0.2em; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
|
||||
tt.arg {font-style: italic;}
|
||||
ol {margin: 0.5em 2.5em;}
|
||||
ul {margin: 0.5em 2em;}
|
||||
ul ul {margin: 0 2em 0.5em 1em;}
|
||||
dl {margin: 0.5em 1em;}
|
||||
dd {margin: 0 2em;}
|
||||
dt {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
|
||||
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; }
|
||||
dl.ret dt {margin: 0.5em 0 0 0 ; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
|
||||
hr {border-width: 1px; margin: 1em;}
|
||||
div.abst {font-family: sans-serif;}
|
||||
div.para {clear: both; font-family: serif;}
|
||||
div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
|
||||
.equ {text-indent: 0; margin: 1em 2em 1em;}
|
||||
.indent {margin-left: 2em;}
|
||||
.rset {float: right; margin: 0.3em 0 0.5em 0.5em;}
|
||||
.lset {float: left; margin: 0.3em 0.5em 0.5em 0.5em;}
|
||||
ul.flat li {list-style-type: none; margin: 0;}
|
||||
a.imglnk img {border: 1px solid;}
|
||||
.iequ {white-space: nowrap; font-weight: bold;}
|
||||
.clr {clear: both;}
|
||||
.it {font-style: italic;}
|
||||
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
|
||||
.ral {text-align: right; }
|
||||
.lal {text-align: left; }
|
||||
.cal {text-align: center; }
|
||||
|
||||
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
|
||||
h2 {font-size: 2em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.5em 0.5em; margin: 0 0 0.5em;}
|
||||
h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;}
|
||||
div.doc h3 {border-color: #b0d8d8; border-style: solid; border-width: 0px 0px 4px 12px; padding: 4px; margin-top: 3em;}
|
||||
h4 {font-size: 1.2em; font-family: sans-serif; margin: 2em 0 0.2em;}
|
||||
h5 {font-size: 1em; font-family: sans-serif; margin: 1em 0 0em;}
|
||||
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
|
||||
hr.hds {clear: both; margin-bottom: 1em;}
|
||||
kbd {letter-spacing: 0;}
|
||||
small {font-size: 80%;}
|
||||
.indent {margin-left: 2em;}
|
||||
|
||||
/* Tables */
|
||||
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
|
||||
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
|
||||
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
|
||||
table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
|
||||
table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
|
||||
table caption {font-family: sans-serif; font-weight: bold;}
|
||||
tr.lst3 td { border-width: 2px 1px 1px; }
|
||||
|
||||
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}
|
||||
70
PORTING/FATFS/doc/css_j.css
Normal file
@@ -0,0 +1,70 @@
|
||||
@charset "Shift_JIS";
|
||||
/* Common style sheet for Tech Notes */
|
||||
|
||||
* {margin: 0; padding: 0; border-width: 0;}
|
||||
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family:"<22>l<EFBFBD>r <20>o<EFBFBD><6F><EFBFBD><EFBFBD>", serif; line-height: 150%; letter-spacing: 1px; max-width: 1024px;}
|
||||
a:link {color: blue;}
|
||||
a:visited {color: darkmagenta;}
|
||||
a:hover {background-color: #a0ffff;}
|
||||
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
|
||||
abbr {border-width: 1px;}
|
||||
|
||||
p {text-indent: 0.8em; margin: 0 0 0.3em 0.5em;}
|
||||
i {margin: 0 0.3em 0 0;}
|
||||
b {margin: 0 0.1em;}
|
||||
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
|
||||
strong {}
|
||||
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; letter-spacing: 0; font-size: 0.85em; font-family: "Consolas", "Courier New", "<22>l<EFBFBD>r <20>S<EFBFBD>V<EFBFBD>b<EFBFBD>N", monospace; background-color: white;}
|
||||
pre span.c {color: green;}
|
||||
pre span.k {color: blue;}
|
||||
pre span.arg {font-style: italic;}
|
||||
tt {margin: 0 0.2em; letter-spacing: 0; font-size: 0.85em; font-family: "Consolas", "Courier New", "<22>l<EFBFBD>r <20>S<EFBFBD>V<EFBFBD>b<EFBFBD>N", monospace;}
|
||||
tt.arg {font-style: italic;}
|
||||
ol {margin: 0.5em 2.5em;}
|
||||
ul {margin: 0.5em 2em;}
|
||||
ul ul {margin: 0 2em 0.5em 1em;}
|
||||
dl {margin: 0.5em 1em;}
|
||||
dd {margin: 0em 2em;}
|
||||
dt {font-size: 0.85em; font-family: "Consolas", "Courier New", "<22>l<EFBFBD>r <20>S<EFBFBD>V<EFBFBD>b<EFBFBD>N", monospace;}
|
||||
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; letter-spacing: 0;}
|
||||
dl.ret dt {margin: 0.5em 0 0 0 ; font-size: 0.85em; font-family: "Consolas", "Courier New", "<22>l<EFBFBD>r <20>S<EFBFBD>V<EFBFBD>b<EFBFBD>N", monospace; letter-spacing: 0; }
|
||||
hr {border-width: 1px; margin: 1em;}
|
||||
div.abst {font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif;}
|
||||
div.para {clear: both; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD><6F><EFBFBD><EFBFBD>",serif;}
|
||||
div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
|
||||
.equ {text-indent: 0; margin: 1em 2em 1em;}
|
||||
.indent {margin-left: 2em;}
|
||||
.rset {float: right; margin: 0.3em 0 0.5em 0.5em;}
|
||||
.lset {float: left; margin: 0.3em 0.5em 0.5em 0.5em;}
|
||||
ul.flat li {list-style-type: none; margin: 0;}
|
||||
a.imglnk img {border: 1px solid;}
|
||||
.iequ {white-space: nowrap; font-weight: bold;}
|
||||
.clr {clear: both;}
|
||||
.it {font-style: italic;}
|
||||
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
|
||||
.ral {text-align: right; }
|
||||
.lal {text-align: left; }
|
||||
.cal {text-align: center; }
|
||||
|
||||
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
|
||||
h2 {font-size: 2em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; background-color: #d8d8FF; padding: 0.5em 0.5em; margin: 0 0 0.5em;}
|
||||
h3 {font-size: 1.5em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 1.5em 0 0.5em;}
|
||||
div.doc h3 {border-color: #b0d8d8; border-style: solid; border-width: 0px 0px 4px 12px; padding: 4px; margin-top: 3em;}
|
||||
h4 {font-size: 1.2em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 2em 0 0.2em;}
|
||||
h5 {font-size: 1em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 1em 0 0em;}
|
||||
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
|
||||
hr.hds {clear: both; margin-bottom: 1em;}
|
||||
kbd {letter-spacing: 0;}
|
||||
small {font-size: 80%;}
|
||||
.indent {margin-left: 2em;}
|
||||
|
||||
/* Tables */
|
||||
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; letter-spacing: 0;}
|
||||
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top;}
|
||||
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
|
||||
table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
|
||||
table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
|
||||
table caption {font-family: sans-serif; font-weight: bold;}
|
||||
tr.lst3 td {border-width: 2px 1px 1px; }
|
||||
|
||||
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}
|
||||
43
PORTING/FATFS/doc/img/app1.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*------------------------------------------------------------/
|
||||
/ Open or create a file in append mode
|
||||
/------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
70
PORTING/FATFS/doc/img/app2.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*------------------------------------------------------------/
|
||||
/ Remove all contents of a directory
|
||||
/ This function works regardless of _FS_RPATH.
|
||||
/------------------------------------------------------------*/
|
||||
|
||||
|
||||
FRESULT empty_directory (
|
||||
char* path /* Working buffer filled with start directory */
|
||||
)
|
||||
{
|
||||
UINT i, j;
|
||||
FRESULT fr;
|
||||
DIR dir;
|
||||
FILINFO fno;
|
||||
|
||||
#if _USE_LFN
|
||||
fno.lfname = 0; /* Disable LFN output */
|
||||
#endif
|
||||
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_unlink(path);
|
||||
if (fr != FR_OK) break;
|
||||
}
|
||||
path[--i] = '\0';
|
||||
closedir(&dir);
|
||||
}
|
||||
|
||||
return fr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
FRESULT fr;
|
||||
FATFS fs;
|
||||
char buff[64]; /* Working buffer */
|
||||
|
||||
|
||||
|
||||
f_mount(&fs, "", 0);
|
||||
|
||||
strcpy(buff, "/"); /* Directory to be emptied */
|
||||
fr = empty_directory(buff);
|
||||
|
||||
if (fr) {
|
||||
printf("Function failed. (%u)\n", fr);
|
||||
return fr;
|
||||
} else {
|
||||
printf("All contents in the %s are successfully removed.\n", buff);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
109
PORTING/FATFS/doc/img/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 file system layer. */
|
||||
...
|
||||
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512KiB from top of the file */
|
||||
...
|
||||
|
||||
f_close(&fil);
|
||||
return 0;
|
||||
}
|
||||
|
||||
317
PORTING/FATFS/doc/img/app4.c
Normal file
@@ -0,0 +1,317 @@
|
||||
/*----------------------------------------------------------------------/
|
||||
/ 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"
|
||||
#include "diskio.h"
|
||||
|
||||
|
||||
static
|
||||
DWORD pn (
|
||||
DWORD pns
|
||||
)
|
||||
{
|
||||
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, pns = 1;
|
||||
WORD sz_sect, sz_eblk;
|
||||
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 < _MAX_SS + 4) {
|
||||
printf("Insufficient work area to test.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (cc = 1; cc <= ncyc; cc++) {
|
||||
printf("**** Test cycle %u of %u start ****\n", cc, ncyc);
|
||||
|
||||
/* Initialization */
|
||||
printf(" disk_initalize(%u)", pdrv);
|
||||
ds = disk_initialize(pdrv);
|
||||
if (ds & STA_NOINIT) {
|
||||
printf(" - failed.\n");
|
||||
return 2;
|
||||
} else {
|
||||
printf(" - ok.\n");
|
||||
}
|
||||
|
||||
/* Get drive size */
|
||||
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 _MAX_SS != _MIN_SS
|
||||
/* Get sector size */
|
||||
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 = _MAX_SS;
|
||||
#endif
|
||||
|
||||
/* Get erase block size */
|
||||
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 %u sectors.\n", sz_eblk);
|
||||
} else {
|
||||
printf(" Size of the erase block is unknown.\n");
|
||||
}
|
||||
|
||||
/* Single sector write test */
|
||||
printf("**** Single sector write test 1 ****\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(" Data matched.\n");
|
||||
} else {
|
||||
printf("Failed: Read data differs from the data written.\n");
|
||||
return 10;
|
||||
}
|
||||
pns++;
|
||||
|
||||
/* Multiple sector write test */
|
||||
printf("**** Multiple sector write test ****\n");
|
||||
lba = 1; 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");
|
||||
} else {
|
||||
printf("Failed: Read data differs from the data written.\n");
|
||||
return 14;
|
||||
}
|
||||
pns++;
|
||||
|
||||
/* Single sector write test (misaligned memory address) */
|
||||
printf("**** Single sector write test 2 ****\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(" Data matched.\n");
|
||||
} else {
|
||||
printf("Failed: Read data differs from the data written.\n");
|
||||
return 18;
|
||||
}
|
||||
pns++;
|
||||
|
||||
/* 4GB barrier test */
|
||||
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(" Data matched.\n");
|
||||
} else {
|
||||
printf("Failed: 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[512]; /* 2048 byte working buffer */
|
||||
|
||||
/* 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 on this disk driver.\n", rc);
|
||||
} else {
|
||||
printf("Congratulations! The disk driver works well.\n");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
BIN
PORTING/FATFS/doc/img/f1.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
PORTING/FATFS/doc/img/f2.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
PORTING/FATFS/doc/img/f3.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
PORTING/FATFS/doc/img/f4.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
PORTING/FATFS/doc/img/f5.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
PORTING/FATFS/doc/img/f6.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
PORTING/FATFS/doc/img/f7.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
PORTING/FATFS/doc/img/funcs.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
PORTING/FATFS/doc/img/layers.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
PORTING/FATFS/doc/img/layers1.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
PORTING/FATFS/doc/img/layers2.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
PORTING/FATFS/doc/img/layers3.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
PORTING/FATFS/doc/img/mkfatimg.zip
Normal file
BIN
PORTING/FATFS/doc/img/modules.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
PORTING/FATFS/doc/img/rwtest.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
PORTING/FATFS/doc/img/rwtest2.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
PORTING/FATFS/doc/img/rwtest3.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
142
PORTING/FATFS/doc/updates.txt
Normal file
@@ -0,0 +1,142 @@
|
||||
R0.10a, Jan 15,'14
|
||||
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
|
||||
Added a configuration option of minimum sector size. (_MIN_SS)
|
||||
2nd argument of f_rename() can have a drive number and it will be ignored.
|
||||
Fixed f_mount() with forced mount fails when drive number is >= 1.
|
||||
Fixed f_close() invalidates the file object without volume lock.
|
||||
Fixed f_closedir() returns but the volume lock is left acquired.
|
||||
Fixed creation of an entry with LFN fails on too many SFN collisions.
|
||||
|
||||
R0.10, Oct 02,'13
|
||||
Added selection of character encoding on the file. (_STRF_ENCODE)
|
||||
Added f_closedir().
|
||||
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
|
||||
Added forced mount feature with changes of f_mount().
|
||||
Improved behavior of volume auto detection.
|
||||
Improved write throughput of f_puts() and f_printf().
|
||||
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
|
||||
Fixed f_write() can be truncated when the file size is close to 4GB.
|
||||
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
|
||||
|
||||
R0.09b, Jan 24, 2013
|
||||
Added f_getlabel() and f_setlabel(). (_USE_LABEL = 1)
|
||||
|
||||
R0.09a, Aug 27, 2012
|
||||
Fixed assertion failure due to OS/2 EA on FAT12/16.
|
||||
Changed API rejects null object pointer to avoid crash.
|
||||
Changed option name _FS_SHARE to _FS_LOCK.
|
||||
|
||||
R0.09, Sep 06, 2011
|
||||
f_mkfs() supports multiple partition to finish the multiple partition feature.
|
||||
Added f_fdisk(). (_MULTI_PARTITION = 2)
|
||||
|
||||
R0.08b, Jan 15, 2011
|
||||
Fast seek feature is also applied to f_read() and f_write().
|
||||
f_lseek() reports required table size on creating CLMP.
|
||||
Extended format syntax of f_printf().
|
||||
Ignores duplicated directory separators in given path names.
|
||||
|
||||
R0.08a, Aug 16, 2010
|
||||
Added f_getcwd(). (_FS_RPATH = 2)
|
||||
Added sector erase feature. (_USE_ERASE)
|
||||
Moved file lock semaphore table from fs object to the bss.
|
||||
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
|
||||
Fixed f_mkfs() creates wrong FAT32 volume.
|
||||
|
||||
R0.08, May 15, 2010
|
||||
Added a memory configuration option. (_USE_LFN)
|
||||
Added file lock feature. (_FS_SHARE)
|
||||
Added fast seek feature. (_USE_FASTSEEK)
|
||||
Changed some types on the API, XCHAR->TCHAR.
|
||||
Changed fname member in the FILINFO structure on Unicode cfg.
|
||||
String functions support UTF-8 encoding files on Unicode cfg.
|
||||
|
||||
R0.07e, Nov 3, 2009
|
||||
Separated out configuration options from ff.h to ffconf.h.
|
||||
Added a configuration option, _LFN_UNICODE.
|
||||
Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH.
|
||||
Fixed name matching error on the 13 char boundary.
|
||||
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
|
||||
|
||||
R0.07c, Jun 21, 2009
|
||||
Fixed f_unlink() may return FR_OK on error.
|
||||
Fixed wrong cache control in f_lseek().
|
||||
Added relative path feature.
|
||||
Added f_chdir().
|
||||
Added f_chdrive().
|
||||
Added proper case conversion to extended characters.
|
||||
|
||||
R0.07a, Apr 14, 2009
|
||||
Separated out OS dependent code on re-entrant configuration.
|
||||
Added multiple sector size support.
|
||||
|
||||
R0.07, Apr 01, 2009
|
||||
Merged Tiny-FatFs into FatFs as a buffer configuration option.
|
||||
Added long file name support.
|
||||
Added multiple code page support.
|
||||
Added re-entrancy for multitask operation.
|
||||
Added auto cluster size selection to f_mkfs().
|
||||
Added rewind option to f_readdir().
|
||||
Changed result code of critical errors.
|
||||
Renamed string functions to avoid name collision.
|
||||
|
||||
R0.06, Apr 01, 2008
|
||||
Added f_forward. (Tiny-FatFs)
|
||||
Added string functions: fgets, fputc, fputs and fprintf.
|
||||
Improved performance of f_lseek on moving to the same or following cluster.
|
||||
|
||||
R0.05a, Feb 03, 2008
|
||||
Added f_truncate.
|
||||
Added f_utime.
|
||||
Fixed off by one error at FAT sub-type determination.
|
||||
Fixed btr in f_read can be mistruncated.
|
||||
Fixed cached sector is left not flushed when create and close without write.
|
||||
|
||||
R0.05, Aug 26, 2007
|
||||
Changed arguments of f_read, f_write.
|
||||
Changed arguments of f_mkfs. (FatFs)
|
||||
Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
|
||||
Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs)
|
||||
|
||||
R0.04b, May 05, 2007
|
||||
Added _USE_NTFLAG option.
|
||||
Added FSInfo support.
|
||||
Fixed some problems corresponds to FAT32. (Tiny-FatFs)
|
||||
Fixed DBCS name can result FR_INVALID_NAME.
|
||||
Fixed short seek (<= csize) collapses the file object.
|
||||
|
||||
R0.04a, Apr 01, 2007
|
||||
Supported multiple partitions on a plysical drive. (FatFs)
|
||||
Added minimization level 3.
|
||||
Added a capability of extending file size to f_lseek.
|
||||
Fixed an endian sensitive code in f_mkfs. (FatFs)
|
||||
Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)
|
||||
|
||||
R0.04, Feb 04, 2007
|
||||
Supported multiple drive system. (FatFs)
|
||||
Changed some APIs for multiple drive system.
|
||||
Added f_mkfs. (FatFs)
|
||||
Added _USE_FAT32 option. (Tiny-FatFs)
|
||||
|
||||
R0.03a, Dec 11, 2006
|
||||
Improved cluster scan algolithm to write files fast.
|
||||
Fixed f_mkdir creates incorrect directory on FAT32.
|
||||
|
||||
R0.03, Sep 22, 2006
|
||||
Added f_rename.
|
||||
Changed option _FS_MINIMUM to _FS_MINIMIZE.
|
||||
|
||||
R0.02a, Jun 10, 2006
|
||||
Added a configuration option _FS_MINIMUM.
|
||||
|
||||
R0.02, Jun 01, 2006
|
||||
Added FAT12.
|
||||
Removed unbuffered mode.
|
||||
Fixed a problem on small (<32M) patition.
|
||||
|
||||
R0.01, Apr 29, 2006
|
||||
First release
|
||||
|
||||
R0.00, Feb 26, 2006
|
||||
Prototype (not released)
|
||||
|
||||