]>
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 static 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
< FF_MAX_SS
+ 8) {
54 printf("Insufficient work area to run the 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 ****\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(" Read data matched.\n");
150 printf(" Read data differs from the data written.\n");
155 printf("**** Multiple sector write test ****\n");
156 lba
= 5; ns
= sz_buff
/ sz_sect
;
159 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
); n
++) pbuff
[n
] = (BYTE
)pn(0);
160 printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
161 dr
= disk_write(pdrv
, pbuff
, lba
, ns
);
165 printf(" - failed.\n");
168 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
169 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
173 printf(" - failed.\n");
176 memset(pbuff
, 0, sz_sect
* ns
);
177 printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv
, (UINT
)pbuff
, lba
, ns
);
178 dr
= disk_read(pdrv
, pbuff
, lba
, ns
);
182 printf(" - failed.\n");
185 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* ns
) && pbuff
[n
] == (BYTE
)pn(0); n
++) ;
186 if (n
== (UINT
)(sz_sect
* ns
)) {
187 printf(" Read data matched.\n");
189 printf(" Read data differs from the data written.\n");
193 printf(" Test skipped.\n");
197 printf("**** Single sector write test (unaligned buffer address) ****\n");
199 for (n
= 0, pn(pns
); n
< sz_sect
; n
++) pbuff
[n
+3] = (BYTE
)pn(0);
200 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+3), lba
);
201 dr
= disk_write(pdrv
, pbuff
+3, lba
, 1);
205 printf(" - failed.\n");
208 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
209 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
213 printf(" - failed.\n");
216 memset(pbuff
+5, 0, sz_sect
);
217 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+5), lba
);
218 dr
= disk_read(pdrv
, pbuff
+5, lba
, 1);
222 printf(" - failed.\n");
225 for (n
= 0, pn(pns
); n
< sz_sect
&& pbuff
[n
+5] == (BYTE
)pn(0); n
++) ;
227 printf(" Read data matched.\n");
229 printf(" Read data differs from the data written.\n");
234 printf("**** 4GB barrier test ****\n");
235 if (sz_drv
>= 128 + 0x80000000 / (sz_sect
/ 2)) {
236 lba
= 6; lba2
= lba
+ 0x80000000 / (sz_sect
/ 2);
237 for (n
= 0, pn(pns
); n
< (UINT
)(sz_sect
* 2); n
++) pbuff
[n
] = (BYTE
)pn(0);
238 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
239 dr
= disk_write(pdrv
, pbuff
, lba
, 1);
243 printf(" - failed.\n");
246 printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
247 dr
= disk_write(pdrv
, pbuff
+sz_sect
, lba2
, 1);
251 printf(" - failed.\n");
254 printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv
);
255 dr
= disk_ioctl(pdrv
, CTRL_SYNC
, 0);
259 printf(" - failed.\n");
262 memset(pbuff
, 0, sz_sect
* 2);
263 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)pbuff
, lba
);
264 dr
= disk_read(pdrv
, pbuff
, lba
, 1);
268 printf(" - failed.\n");
271 printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv
, (UINT
)(pbuff
+sz_sect
), lba2
);
272 dr
= disk_read(pdrv
, pbuff
+sz_sect
, lba2
, 1);
276 printf(" - failed.\n");
279 for (n
= 0, pn(pns
); pbuff
[n
] == (BYTE
)pn(0) && n
< (UINT
)(sz_sect
* 2); n
++) ;
280 if (n
== (UINT
)(sz_sect
* 2)) {
281 printf(" Read data matched.\n");
283 printf(" Read data differs from the data written.\n");
287 printf(" Test skipped.\n");
291 printf("**** Test cycle %u of %u completed ****\n\n", cc
, ncyc
);
299 int main (int argc
, char* argv
[])
302 DWORD buff
[FF_MAX_SS
]; /* Working buffer (4 sector in size) */
304 /* Check function/compatibility of the physical drive #0 */
305 rc
= test_diskio(0, 3, buff
, sizeof buff
);
308 printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work with this disk driver.\n", rc
);
310 printf("Congratulations! The disk driver works well.\n");