]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/doc/img/app4.c
1 /*----------------------------------------------------------------------/
2 / Low level disk I/O module function checker
3 /-----------------------------------------------------------------------/
4 / WARNING: The data on the target drive will be lost!
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
, pns
= 1;
45 WORD sz_sect
, sz_eblk
;
46 BYTE
*pbuff
= (BYTE
*)buff
;
52 printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv
, ncyc
, (UINT
)buff
, sz_buff
);
54 if (sz_buff
< _MAX_SS
+ 4) {
55 printf("Insufficient work area to test.\n");
59 for (cc
= 1; cc
<= ncyc
; cc
++) {
60 printf("**** Test cycle %u of %u start ****\n", cc
, ncyc
);
63 printf(" disk_initalize(%u)", pdrv
);
64 ds
= disk_initialize(pdrv
);
65 if (ds
& STA_NOINIT
) {
66 printf(" - failed.\n");
73 printf("**** Get drive size ****\n");
74 printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv
, (UINT
)&sz_drv
);
76 dr
= disk_ioctl(pdrv
, GET_SECTOR_COUNT
, &sz_drv
);
80 printf(" - failed.\n");
84 printf("Failed: Insufficient drive size to test.\n");
87 printf(" Number of sectors on the drive %u is %lu.\n", pdrv
, sz_drv
);
89 #if _MAX_SS != _MIN_SS
91 printf("**** Get sector size ****\n");
92 printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv
, (UINT
)&sz_sect
);
94 dr
= disk_ioctl(pdrv
, GET_SECTOR_SIZE
, &sz_sect
);
98 printf(" - failed.\n");
101 printf(" Size of sector is %u bytes.\n", sz_sect
);
106 /* Get erase block size */
107 printf("**** Get block size ****\n");
108 printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv
, (UINT
)&sz_eblk
);
110 dr
= disk_ioctl(pdrv
, GET_BLOCK_SIZE
, &sz_eblk
);
114 printf(" - failed.\n");
116 if (dr
== RES_OK
|| sz_eblk
>= 2) {
117 printf(" Size of the erase block is %u sectors.\n", sz_eblk
);
119 printf(" Size of the erase block is unknown.\n");
122 /* Single sector write test */
123 printf("**** Single sector write test 1 ****\n");
125 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
] = (BYTE
)pn(0);
126 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
127 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
131 printf(" - failed.\n");
134 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
135 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
139 printf(" - failed.\n");
142 memset(pbuff
, 0, sz_sect
);
143 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
144 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
148 printf(" - failed.\n");
151 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
] == (BYTE
)pn(0); n
++) ;
153 printf(" Data matched.\n");
155 printf("Failed: Read data differs from the data written.\n");
160 /* Multiple sector write test */
161 printf("**** Multiple sector write test ****\n");
162 lba
= 1; ns
= sz_buff
/ sz_sect
;
164 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
); n
++) pbuff
[n
] = (BYTE
)pn(0);
165 printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
166 dr
= disk_write(pdrv
, pbuff
, lba
, ns
);
170 printf(" - failed.\n");
173 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
174 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
178 printf(" - failed.\n");
181 memset(pbuff
, 0, sz_sect
* ns
);
182 printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
183 dr
= disk_read(pdrv
, pbuff
, lba
, ns
);
187 printf(" - failed.\n");
190 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
) && pbuff
[n
] == (BYTE
)pn(0); n
++) ;
191 if (n
== (UINT
)(sz_sect
* ns
)) {
192 printf(" Data matched.\n");
194 printf("Failed: Read data differs from the data written.\n");
199 /* Single sector write test (misaligned memory address) */
200 printf("**** Single sector write test 2 ****\n");
202 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
+3] = (BYTE
)pn(0);
203 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+3), lba
);
204 dr
= disk_write(pdrv
, pbuff
+3, lba
, 1);
208 printf(" - failed.\n");
211 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
212 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
216 printf(" - failed.\n");
219 memset(pbuff
+5, 0, sz_sect
);
220 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+5), lba
);
221 dr
= disk_read(pdrv
, pbuff
+5, lba
, 1);
225 printf(" - failed.\n");
228 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
+5] == (BYTE
)pn(0); n
++) ;
230 printf(" Data matched.\n");
232 printf("Failed: Read data differs from the data written.\n");
237 /* 4GB barrier test */
238 printf("**** 4GB barrier test ****\n");
239 if (sz_drv
>= 128 + 0x80000000 / (sz_sect
/ 2)) {
240 lba
= 6; lba2
= lba
+ 0x80000000 / (sz_sect
/ 2);
241 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* 2); n
++) pbuff
[n
] = (BYTE
)pn(0);
242 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
243 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
247 printf(" - failed.\n");
250 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
251 dr
= disk_write(pdrv
, pbuff
+sz_sect
, lba2
, 1);
255 printf(" - failed.\n");
258 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
259 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
263 printf(" - failed.\n");
266 memset(pbuff
, 0, sz_sect
* 2);
267 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
268 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
272 printf(" - failed.\n");
275 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
276 dr
= disk_read(pdrv
, pbuff
+sz_sect
, lba2
, 1);
280 printf(" - failed.\n");
283 for (n
= 0, pn(pns
); pbuff
[n
] == (BYTE
)pn(0) && n
< (UINT
)(sz_sect
* 2); n
++) ;
284 if (n
== (UINT
)(sz_sect
* 2)) {
285 printf(" Data matched.\n");
287 printf("Failed: Read data differs from the data written.\n");
291 printf(" Test skipped.\n");
295 printf("**** Test cycle %u of %u completed ****\n\n", cc
, ncyc
);
303 int main (int argc
, char* argv
[])
306 DWORD buff
[512]; /* 2048 byte working buffer */
308 /* Check function/compatibility of the physical drive #0 */
309 rc
= test_diskio(0, 1, buff
, sizeof buff
);
311 printf("Sorry the function/compatibility test failed.\nFatFs will not work on this disk driver.\n");
313 printf("Congratulations! The disk I/O layer works well.\n");