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