]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/documents/res/app6.c
Import fatfs R0.15
[z180-stamp.git] / fatfs / documents / res / app6.c
1 /*---------------------------------------------------------------------*/
2 /* Raw Read/Write Throughput Checker */
3 /*---------------------------------------------------------------------*/
4
5 #include <stdio.h>
6 #include <systimer.h>
7 #include "diskio.h"
8 #include "ff.h"
9
10
11 int test_raw_speed (
12 BYTE pdrv, /* Physical drive number */
13 DWORD lba, /* Start LBA for read/write test */
14 DWORD len, /* Number of bytes to read/write (must be multiple of sz_buff) */
15 void* buff, /* Read/write buffer */
16 UINT sz_buff /* Size of read/write buffer (must be multiple of FF_MAX_SS) */
17 )
18 {
19 WORD ss;
20 DWORD ofs, tmr;
21
22
23 #if FF_MIN_SS != FF_MAX_SS
24 if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) {
25 printf("\ndisk_ioctl() failed.\n");
26 return 0;
27 }
28 #else
29 ss = FF_MAX_SS;
30 #endif
31
32 printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
33 tmr = systimer();
34 for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
35 if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
36 printf("\ndisk_write() failed.\n");
37 return 0;
38 }
39 }
40 if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) {
41 printf("\ndisk_ioctl() failed.\n");
42 return 0;
43 }
44 tmr = systimer() - tmr;
45 printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr);
46
47 printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
48 tmr = systimer();
49 for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
50 if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
51 printf("\ndisk_read() failed.\n");
52 return 0;
53 }
54 }
55 tmr = systimer() - tmr;
56 printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr);
57
58 printf("Test completed.\n");
59 return 1;
60 }
61