]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/documents/res/app4.c
Import fatfs R0.15
[z180-stamp.git] / fatfs / documents / res / app4.c
index 4209f39aea29a7f1a1e2008bb61a4302bfa936c5..c46d1a05db97269dd8846b7bf0dabdd6036f116d 100644 (file)
@@ -10,9 +10,9 @@
 #include "diskio.h"     /* Declarations of disk functions */\r
 \r
 \r
-static\r
-DWORD pn (             /* Pseudo random number generator */\r
-    DWORD pns  /* 0:Initialize, !0:Read */\r
+\r
+static DWORD pn (       /* Pseudo random number generator */\r
+    DWORD pns   /* 0:Initialize, !0:Read */\r
 )\r
 {\r
     static DWORD lfsr;\r
@@ -50,8 +50,8 @@ int test_diskio (
 \r
     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 run program.\n");\r
+    if (sz_buff < FF_MAX_SS + 8) {\r
+        printf("Insufficient work area to run the program.\n");\r
         return 1;\r
     }\r
 \r
@@ -115,7 +115,7 @@ int test_diskio (
         }\r
 \r
         /* Single sector write test */\r
-        printf("**** Single sector write test ****\n");\r
+        printf("**** Single sector write test ****\n");\r
         lba = 0;\r
         for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0);\r
         printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);\r
@@ -145,52 +145,56 @@ int test_diskio (
         }\r
         for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;\r
         if (n == sz_sect) {\r
-            printf(" Data matched.\n");\r
+            printf(" Read data matched.\n");\r
         } else {\r
-            printf("Failed: Read data differs from the data written.\n");\r
+            printf(" Read data differs from the data written.\n");\r
             return 10;\r
         }\r
         pns++;\r
 \r
         printf("**** Multiple sector write test ****\n");\r
-        lba = 1; ns = sz_buff / sz_sect;\r
+        lba = 5; ns = sz_buff / sz_sect;\r
         if (ns > 4) ns = 4;\r
-        for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);\r
-        printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);\r
-        dr = disk_write(pdrv, pbuff, lba, ns);\r
-        if (dr == RES_OK) {\r
-            printf(" - ok.\n");\r
-        } else {\r
-            printf(" - failed.\n");\r
-            return 11;\r
-        }\r
-        printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);\r
-        dr = disk_ioctl(pdrv, CTRL_SYNC, 0);\r
-        if (dr == RES_OK) {\r
-            printf(" - ok.\n");\r
-        } else {\r
-            printf(" - failed.\n");\r
-            return 12;\r
-        }\r
-        memset(pbuff, 0, sz_sect * ns);\r
-        printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);\r
-        dr = disk_read(pdrv, pbuff, lba, ns);\r
-        if (dr == RES_OK) {\r
-            printf(" - ok.\n");\r
-        } else {\r
-            printf(" - failed.\n");\r
-            return 13;\r
-        }\r
-        for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;\r
-        if (n == (UINT)(sz_sect * ns)) {\r
-            printf(" Data matched.\n");\r
+        if (ns > 1) {\r
+            for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);\r
+            printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);\r
+            dr = disk_write(pdrv, pbuff, lba, ns);\r
+            if (dr == RES_OK) {\r
+                printf(" - ok.\n");\r
+            } else {\r
+                printf(" - failed.\n");\r
+                return 11;\r
+            }\r
+            printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);\r
+            dr = disk_ioctl(pdrv, CTRL_SYNC, 0);\r
+            if (dr == RES_OK) {\r
+                printf(" - ok.\n");\r
+            } else {\r
+                printf(" - failed.\n");\r
+                return 12;\r
+            }\r
+            memset(pbuff, 0, sz_sect * ns);\r
+            printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);\r
+            dr = disk_read(pdrv, pbuff, lba, ns);\r
+            if (dr == RES_OK) {\r
+                printf(" - ok.\n");\r
+            } else {\r
+                printf(" - failed.\n");\r
+                return 13;\r
+            }\r
+            for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;\r
+            if (n == (UINT)(sz_sect * ns)) {\r
+                printf(" Read data matched.\n");\r
+            } else {\r
+                printf(" Read data differs from the data written.\n");\r
+                return 14;\r
+            }\r
         } else {\r
-            printf("Failed: Read data differs from the data written.\n");\r
-            return 14;\r
+            printf(" Test skipped.\n");\r
         }\r
         pns++;\r
 \r
-        printf("**** Single sector write test (misaligned address) ****\n");\r
+        printf("**** Single sector write test (unaligned buffer 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
@@ -220,9 +224,9 @@ int test_diskio (
         }\r
         for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;\r
         if (n == sz_sect) {\r
-            printf(" Data matched.\n");\r
+            printf(" Read data matched.\n");\r
         } else {\r
-            printf("Failed: Read data differs from the data written.\n");\r
+            printf(" Read data differs from the data written.\n");\r
             return 18;\r
         }\r
         pns++;\r
@@ -274,9 +278,9 @@ int test_diskio (
             }\r
             for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;\r
             if (n == (UINT)(sz_sect * 2)) {\r
-                printf(" Data matched.\n");\r
+                printf(" Read data matched.\n");\r
             } else {\r
-                printf("Failed: Read data differs from the data written.\n");\r
+                printf(" Read data differs from the data written.\n");\r
                 return 24;\r
             }\r
         } else {\r