请选择 进入手机版 | 继续访问电脑版

安富莱电子论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 210|回复: 0
收起左侧

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

[复制链接]

5677

主题

3万

帖子

4万

积分

管理员

做人第一,工作第二

Rank: 9Rank: 9Rank: 9

积分
45712
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. }
复制代码



淘宝小店: https://armfly.taobao.com/
专注,努力,用心的做好每一件事情,Fighting!
回复

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|安富莱电子论坛 ( 鄂ICP备09023347号,公安机关备案号42010602000201 )

GMT+8, 2019-5-26 22:00 , Processed in 0.174688 second(s), 35 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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