硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2050|回复: 0
收起左侧

[FatFs] FatFS测量底层性能方法

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106718
QQ
发表于 2019-2-21 00:40:14 | 显示全部楼层 |阅读模式
http://elm-chan.org/fsw/ff/res/app6.c


  1. /*---------------------------------------------------------------------*/
  2. /* Raw Read/Write Throughput Checker                                   */
  3. /*---------------------------------------------------------------------*/

  4. #include <stdio.h>
  5. #include <systimer.h>
  6. #include "diskio.h"
  7. #include "ff.h"


  8. int test_raw_speed (
  9.     BYTE pdrv,      /* Physical drive number */
  10.     DWORD lba,      /* Start LBA for read/write test */
  11.     DWORD len,      /* Number of bytes to read/write (must be multiple of sz_buff) */
  12.     void* buff,     /* Read/write buffer */
  13.     UINT sz_buff    /* Size of read/write buffer (must be multiple of FF_MAX_SS) */
  14. )
  15. {
  16.     WORD ss;
  17.     DWORD ofs, tmr;


  18. #if FF_MIN_SS != FF_MAX_SS
  19.     if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) {
  20.         printf("\ndisk_ioctl() failed.\n");
  21.         return 0;
  22.     }
  23. #else
  24.     ss = FF_MAX_SS;
  25. #endif

  26.     printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
  27.     tmr = systimer();
  28.     for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
  29.         if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
  30.             printf("\ndisk_write() failed.\n");
  31.             return 0;
  32.         }
  33.     }
  34.     if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) {
  35.         printf("\ndisk_ioctl() failed.\n");
  36.         return 0;
  37.     }
  38.     tmr = systimer() - tmr;
  39.     printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr);

  40.     printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
  41.     tmr = systimer();
  42.     for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
  43.         if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
  44.             printf("\ndisk_read() failed.\n");
  45.             return 0;
  46.         }
  47.     }
  48.     tmr = systimer() - tmr;
  49.     printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr);

  50.     printf("Test completed.\n");
  51.     return 1;
  52. }
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-30 20:55 , Processed in 0.142888 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表