]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/documents/res/app4.c
Import fatfs R0.13b
[z180-stamp.git] / fatfs / documents / res / app4.c
similarity index 89%
rename from fatfs/doc/res/app4.c
rename to fatfs/documents/res/app4.c
index 03d124deef4c2c16870d90dbdff5440622435827..4209f39aea29a7f1a1e2008bb61a4302bfa936c5 100644 (file)
@@ -1,18 +1,18 @@
 /*----------------------------------------------------------------------/\r
-/ Low level disk I/O module function checker\r
+/ Low level disk I/O module function checker                            /\r
 /-----------------------------------------------------------------------/\r
 / WARNING: The data on the target drive will be lost!\r
 */\r
 \r
 #include <stdio.h>\r
 #include <string.h>\r
-#include "ff.h"\r
-#include "diskio.h"\r
+#include "ff.h"         /* Declarations of sector size */\r
+#include "diskio.h"     /* Declarations of disk functions */\r
 \r
 \r
 static\r
-DWORD pn (\r
-    DWORD pns\r
+DWORD pn (             /* Pseudo random number generator */\r
+    DWORD pns  /* 0:Initialize, !0:Read */\r
 )\r
 {\r
     static DWORD lfsr;\r
@@ -41,8 +41,8 @@ int test_diskio (
 )\r
 {\r
     UINT n, cc, ns;\r
-    DWORD sz_drv, lba, lba2, pns = 1;\r
-    WORD sz_sect, sz_eblk;\r
+    DWORD sz_drv, lba, lba2, sz_eblk, pns = 1;\r
+    WORD sz_sect;\r
     BYTE *pbuff = (BYTE*)buff;\r
     DSTATUS ds;\r
     DRESULT dr;\r
@@ -51,14 +51,13 @@ int test_diskio (
     printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);\r
 \r
     if (sz_buff < _MAX_SS + 4) {\r
-        printf("Insufficient work area to test.\n");\r
+        printf("Insufficient work area to run program.\n");\r
         return 1;\r
     }\r
 \r
     for (cc = 1; cc <= ncyc; cc++) {\r
         printf("**** Test cycle %u of %u start ****\n", cc, ncyc);\r
 \r
-        /* Initialization */\r
         printf(" disk_initalize(%u)", pdrv);\r
         ds = disk_initialize(pdrv);\r
         if (ds & STA_NOINIT) {\r
@@ -68,7 +67,6 @@ int test_diskio (
             printf(" - ok.\n");\r
         }\r
 \r
-        /* Get drive size */\r
         printf("**** Get drive size ****\n");\r
         printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv, (UINT)&sz_drv);\r
         sz_drv = 0;\r
@@ -85,8 +83,7 @@ int test_diskio (
         }\r
         printf(" Number of sectors on the drive %u is %lu.\n", pdrv, sz_drv);\r
 \r
-#if _MAX_SS != _MIN_SS\r
-        /* Get sector size */\r
+#if FF_MAX_SS != FF_MIN_SS\r
         printf("**** Get sector size ****\n");\r
         printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv, (UINT)&sz_sect);\r
         sz_sect = 0;\r
@@ -99,10 +96,9 @@ int test_diskio (
         }\r
         printf(" Size of sector is %u bytes.\n", sz_sect);\r
 #else\r
-        sz_sect = _MAX_SS;\r
+        sz_sect = FF_MAX_SS;\r
 #endif\r
 \r
-        /* Get erase block size */\r
         printf("**** Get block size ****\n");\r
         printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv, (UINT)&sz_eblk);\r
         sz_eblk = 0;\r
@@ -113,7 +109,7 @@ int test_diskio (
             printf(" - failed.\n");\r
         }\r
         if (dr == RES_OK || sz_eblk >= 2) {\r
-            printf(" Size of the erase block is %u sectors.\n", sz_eblk);\r
+            printf(" Size of the erase block is %lu sectors.\n", sz_eblk);\r
         } else {\r
             printf(" Size of the erase block is unknown.\n");\r
         }\r
@@ -156,7 +152,6 @@ int test_diskio (
         }\r
         pns++;\r
 \r
-        /* Multiple sector write test */\r
         printf("**** Multiple sector write test ****\n");\r
         lba = 1; ns = sz_buff / sz_sect;\r
         if (ns > 4) ns = 4;\r
@@ -195,8 +190,7 @@ int test_diskio (
         }\r
         pns++;\r
 \r
-        /* Single sector write test (misaligned memory address) */\r
-        printf("**** Single sector write test 2 ****\n");\r
+        printf("**** Single sector write test (misaligned address) ****\n");\r
         lba = 5;\r
         for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0);\r
         printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba);\r
@@ -233,7 +227,6 @@ int test_diskio (
         }\r
         pns++;\r
 \r
-        /* 4GB barrier test */\r
         printf("**** 4GB barrier test ****\n");\r
         if (sz_drv >= 128 + 0x80000000 / (sz_sect / 2)) {\r
             lba = 6; lba2 = lba + 0x80000000 / (sz_sect / 2);\r
@@ -302,12 +295,13 @@ int test_diskio (
 int main (int argc, char* argv[])\r
 {\r
     int rc;\r
-    DWORD buff[512];  /* 2048 byte working buffer */\r
+    DWORD buff[FF_MAX_SS];  /* Working buffer (4 sector in size) */\r
 \r
     /* Check function/compatibility of the physical drive #0 */\r
     rc = test_diskio(0, 3, buff, sizeof buff);\r
+\r
     if (rc) {\r
-        printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work on this disk driver.\n", rc);\r
+        printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work with this disk driver.\n", rc);\r
     } else {\r
         printf("Congratulations! The disk driver works well.\n");\r
     }\r