]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/doc/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!
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
;
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 test.\n");
58 for (cc
= 1; cc
<= ncyc
; cc
++) {
59 printf("**** Test cycle %u of %u start ****\n", cc
, ncyc
);
62 printf(" disk_initalize(%u)", pdrv
);
63 ds
= disk_initialize(pdrv
);
64 if (ds
& STA_NOINIT
) {
65 printf(" - failed.\n");
72 printf("**** Get drive size ****\n");
73 printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv
, (UINT
)&sz_drv
);
75 dr
= disk_ioctl(pdrv
, GET_SECTOR_COUNT
, &sz_drv
);
79 printf(" - failed.\n");
83 printf("Failed: Insufficient drive size to test.\n");
86 printf(" Number of sectors on the drive %u is %lu.\n", pdrv
, sz_drv
);
88 #if _MAX_SS != _MIN_SS
90 printf("**** Get sector size ****\n");
91 printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv
, (UINT
)&sz_sect
);
93 dr
= disk_ioctl(pdrv
, GET_SECTOR_SIZE
, &sz_sect
);
97 printf(" - failed.\n");
100 printf(" Size of sector is %u bytes.\n", sz_sect
);
105 /* Get erase block size */
106 printf("**** Get block size ****\n");
107 printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv
, (UINT
)&sz_eblk
);
109 dr
= disk_ioctl(pdrv
, GET_BLOCK_SIZE
, &sz_eblk
);
113 printf(" - failed.\n");
115 if (dr
== RES_OK
|| sz_eblk
>= 2) {
116 printf(" Size of the erase block is %u sectors.\n", sz_eblk
);
118 printf(" Size of the erase block is unknown.\n");
121 /* Single sector write test */
122 printf("**** Single sector write test 1 ****\n");
124 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
] = (BYTE
)pn(0);
125 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
126 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
130 printf(" - failed.\n");
133 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
134 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
138 printf(" - failed.\n");
141 memset(pbuff
, 0, sz_sect
);
142 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
143 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
147 printf(" - failed.\n");
150 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
] == (BYTE
)pn(0); n
++) ;
152 printf(" Data matched.\n");
154 printf("Failed: Read data differs from the data written.\n");
159 /* Multiple sector write test */
160 printf("**** Multiple sector write test ****\n");
161 lba
= 1; ns
= sz_buff
/ sz_sect
;
163 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
); n
++) pbuff
[n
] = (BYTE
)pn(0);
164 printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
165 dr
= disk_write(pdrv
, pbuff
, lba
, ns
);
169 printf(" - failed.\n");
172 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
173 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
177 printf(" - failed.\n");
180 memset(pbuff
, 0, sz_sect
* ns
);
181 printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
182 dr
= disk_read(pdrv
, pbuff
, lba
, ns
);
186 printf(" - failed.\n");
189 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
) && pbuff
[n
] == (BYTE
)pn(0); n
++) ;
190 if (n
== (UINT
)(sz_sect
* ns
)) {
191 printf(" Data matched.\n");
193 printf("Failed: Read data differs from the data written.\n");
198 /* Single sector write test (misaligned memory address) */
199 printf("**** Single sector write test 2 ****\n");
201 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
+3] = (BYTE
)pn(0);
202 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+3), lba
);
203 dr
= disk_write(pdrv
, pbuff
+3, lba
, 1);
207 printf(" - failed.\n");
210 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
211 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
215 printf(" - failed.\n");
218 memset(pbuff
+5, 0, sz_sect
);
219 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+5), lba
);
220 dr
= disk_read(pdrv
, pbuff
+5, lba
, 1);
224 printf(" - failed.\n");
227 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
+5] == (BYTE
)pn(0); n
++) ;
229 printf(" Data matched.\n");
231 printf("Failed: Read data differs from the data written.\n");
236 /* 4GB barrier test */
237 printf("**** 4GB barrier test ****\n");
238 if (sz_drv
>= 128 + 0x80000000 / (sz_sect
/ 2)) {
239 lba
= 6; lba2
= lba
+ 0x80000000 / (sz_sect
/ 2);
240 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* 2); n
++) pbuff
[n
] = (BYTE
)pn(0);
241 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
242 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
246 printf(" - failed.\n");
249 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
250 dr
= disk_write(pdrv
, pbuff
+sz_sect
, lba2
, 1);
254 printf(" - failed.\n");
257 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
258 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
262 printf(" - failed.\n");
265 memset(pbuff
, 0, sz_sect
* 2);
266 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
267 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
271 printf(" - failed.\n");
274 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
275 dr
= disk_read(pdrv
, pbuff
+sz_sect
, lba2
, 1);
279 printf(" - failed.\n");
282 for (n
= 0, pn(pns
); pbuff
[n
] == (BYTE
)pn(0) && n
< (UINT
)(sz_sect
* 2); n
++) ;
283 if (n
== (UINT
)(sz_sect
* 2)) {
284 printf(" Data matched.\n");
286 printf("Failed: Read data differs from the data written.\n");
290 printf(" Test skipped.\n");
294 printf("**** Test cycle %u of %u completed ****\n\n", cc
, ncyc
);
302 int main (int argc
, char* argv
[])
305 DWORD buff
[512]; /* 2048 byte working buffer */
307 /* Check function/compatibility of the physical drive #0 */
308 rc
= test_diskio(0, 3, buff
, sizeof buff
);
310 printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work on this disk driver.\n", rc
);
312 printf("Congratulations! The disk driver works well.\n");