]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/documents/res/app4.c
1 /*----------------------------------------------------------------------/
2 / Low level disk I/O module function checker /
3 /-----------------------------------------------------------------------/
4 / WARNING: The data on the target drive will be lost!
9 #include "ff.h" /* Declarations of sector size */
10 #include "diskio.h" /* Declarations of disk functions */
14 DWORD
pn ( /* Pseudo random number generator */
15 DWORD pns
/* 0:Initialize, !0:Read */
24 for (n
= 0; n
< 32; n
++) pn(0);
37 BYTE pdrv
, /* Physical drive number to be checked (all data on the drive will be lost) */
38 UINT ncyc
, /* Number of test cycles */
39 DWORD
* buff
, /* Pointer to the working buffer */
40 UINT sz_buff
/* Size of the working buffer in unit of byte */
44 DWORD sz_drv
, lba
, lba2
, sz_eblk
, pns
= 1;
46 BYTE
*pbuff
= (BYTE
*)buff
;
51 printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv
, ncyc
, (UINT
)buff
, sz_buff
);
53 if (sz_buff
< _MAX_SS
+ 4) {
54 printf("Insufficient work area to run program.\n");
58 for (cc
= 1; cc
<= ncyc
; cc
++) {
59 printf("**** Test cycle %u of %u start ****\n", cc
, ncyc
);
61 printf(" disk_initalize(%u)", pdrv
);
62 ds
= disk_initialize(pdrv
);
63 if (ds
& STA_NOINIT
) {
64 printf(" - failed.\n");
70 printf("**** Get drive size ****\n");
71 printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv
, (UINT
)&sz_drv
);
73 dr
= disk_ioctl(pdrv
, GET_SECTOR_COUNT
, &sz_drv
);
77 printf(" - failed.\n");
81 printf("Failed: Insufficient drive size to test.\n");
84 printf(" Number of sectors on the drive %u is %lu.\n", pdrv
, sz_drv
);
86 #if FF_MAX_SS != FF_MIN_SS
87 printf("**** Get sector size ****\n");
88 printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv
, (UINT
)&sz_sect
);
90 dr
= disk_ioctl(pdrv
, GET_SECTOR_SIZE
, &sz_sect
);
94 printf(" - failed.\n");
97 printf(" Size of sector is %u bytes.\n", sz_sect
);
102 printf("**** Get block size ****\n");
103 printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv
, (UINT
)&sz_eblk
);
105 dr
= disk_ioctl(pdrv
, GET_BLOCK_SIZE
, &sz_eblk
);
109 printf(" - failed.\n");
111 if (dr
== RES_OK
|| sz_eblk
>= 2) {
112 printf(" Size of the erase block is %lu sectors.\n", sz_eblk
);
114 printf(" Size of the erase block is unknown.\n");
117 /* Single sector write test */
118 printf("**** Single sector write test 1 ****\n");
120 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
] = (BYTE
)pn(0);
121 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
122 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
126 printf(" - failed.\n");
129 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
130 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
134 printf(" - failed.\n");
137 memset(pbuff
, 0, sz_sect
);
138 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
139 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
143 printf(" - failed.\n");
146 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
] == (BYTE
)pn(0); n
++) ;
148 printf(" Data matched.\n");
150 printf("Failed: Read data differs from the data written.\n");
155 printf("**** Multiple sector write test ****\n");
156 lba
= 1; ns
= sz_buff
/ sz_sect
;
158 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
); n
++) pbuff
[n
] = (BYTE
)pn(0);
159 printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
160 dr
= disk_write(pdrv
, pbuff
, lba
, ns
);
164 printf(" - failed.\n");
167 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
168 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
172 printf(" - failed.\n");
175 memset(pbuff
, 0, sz_sect
* ns
);
176 printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
177 dr
= disk_read(pdrv
, pbuff
, lba
, ns
);
181 printf(" - failed.\n");
184 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
) && pbuff
[n
] == (BYTE
)pn(0); n
++) ;
185 if (n
== (UINT
)(sz_sect
* ns
)) {
186 printf(" Data matched.\n");
188 printf("Failed: Read data differs from the data written.\n");
193 printf("**** Single sector write test (misaligned address) ****\n");
195 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
+3] = (BYTE
)pn(0);
196 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+3), lba
);
197 dr
= disk_write(pdrv
, pbuff
+3, lba
, 1);
201 printf(" - failed.\n");
204 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
205 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
209 printf(" - failed.\n");
212 memset(pbuff
+5, 0, sz_sect
);
213 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+5), lba
);
214 dr
= disk_read(pdrv
, pbuff
+5, lba
, 1);
218 printf(" - failed.\n");
221 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
+5] == (BYTE
)pn(0); n
++) ;
223 printf(" Data matched.\n");
225 printf("Failed: Read data differs from the data written.\n");
230 printf("**** 4GB barrier test ****\n");
231 if (sz_drv
>= 128 + 0x80000000 / (sz_sect
/ 2)) {
232 lba
= 6; lba2
= lba
+ 0x80000000 / (sz_sect
/ 2);
233 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* 2); n
++) pbuff
[n
] = (BYTE
)pn(0);
234 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
235 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
239 printf(" - failed.\n");
242 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
243 dr
= disk_write(pdrv
, pbuff
+sz_sect
, lba2
, 1);
247 printf(" - failed.\n");
250 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
251 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
255 printf(" - failed.\n");
258 memset(pbuff
, 0, sz_sect
* 2);
259 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
260 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
264 printf(" - failed.\n");
267 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
268 dr
= disk_read(pdrv
, pbuff
+sz_sect
, lba2
, 1);
272 printf(" - failed.\n");
275 for (n
= 0, pn(pns
); pbuff
[n
] == (BYTE
)pn(0) && n
< (UINT
)(sz_sect
* 2); n
++) ;
276 if (n
== (UINT
)(sz_sect
* 2)) {
277 printf(" Data matched.\n");
279 printf("Failed: Read data differs from the data written.\n");
283 printf(" Test skipped.\n");
287 printf("**** Test cycle %u of %u completed ****\n\n", cc
, ncyc
);
295 int main (int argc
, char* argv
[])
298 DWORD buff
[FF_MAX_SS
]; /* Working buffer (4 sector in size) */
300 /* Check function/compatibility of the physical drive #0 */
301 rc
= test_diskio(0, 3, buff
, sizeof buff
);
304 printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work with this disk driver.\n", rc
);
306 printf("Congratulations! The disk driver works well.\n");