Mbed OS 文档翻译 之 参考(API(存储(ProfilingBlockDevice)))

ProfilingBlockDevice

                                                                               

                                                                     ProfilingBlockDevice 类层次结构

ProfilingBlockDevice 类为现有块设备对象提供装饰器,以记录读取,写入和擦除。

ProfilingBlockDevices 接收指向被分析的块设备的指针,作为唯一可配置的参数。如果要计算存储操作(如编程,读取或写入块设备),则应使用 ProfilingBlockDevice 对象作为存储块的接口而不是底层设备。以下示例突出显示了此用例。

ProfilingBlockDevice 类参考

ProfilingBlockDevice 类参考

公共成员函数
 ProfilingBlockDevice (BlockDevice *bd)
virtual ~ProfilingBlockDevice ()
virtual int init ()
virtual int deinit ()
virtual int sync ()
virtual int read (void *buffer, bd_addr_t addr, bd_size_t size)
virtual int program (const void *buffer, bd_addr_t addr, bd_size_t size)
virtual int erase (bd_addr_t addr, bd_size_t size)
virtual bd_size_t get_read_size () const
virtual bd_size_t get_program_size () const
virtual bd_size_t get_erase_size () const
virtual bd_size_t get_erase_size (bd_addr_t addr) const
virtual int get_erase_value () const
virtual bd_size_t size () const
void reset ()
bd_size_t get_read_count () const
bd_size_t get_program_count () const
bd_size_t get_erase_count () const
 公共成员函数继承自 BlockDevice
virtual ~BlockDevice ()
virtual int trim (bd_addr_t addr, bd_size_t size)
bool is_valid_read (bd_addr_t addr, bd_size_t size) const
bool is_valid_program (bd_addr_t addr, bd_size_t size) const
bool is_valid_erase (bd_addr_t addr, bd_size_t size) const

ProfilingBlockDevice 示例

创建 ProfilingBlockDevice,执行存储操作并报告读取,写入和擦除计数。

main.cpp                                                                                                                                                 导入到 Mbed IDE

#include "mbed.h"
#include "HeapBlockDevice.h"
#include "ProfilingBlockDevice.h"

#define BLOCK_SIZE 512

HeapBlockDevice bd(2048, BLOCK_SIZE); // 2048 bytes with a block size of 512 bytes
uint8_t block[BLOCK_SIZE] = "Hello World!\n";

int main() {
    ProfilingBlockDevice profiler(&bd);
    profiler.init();
    profiler.erase(0, BLOCK_SIZE);
    profiler.program(block, 0, BLOCK_SIZE);
    profiler.read(block, 0, BLOCK_SIZE);
    
    printf("%s", block);
    printf("read count: %lld\n", profiler.get_read_count());
    printf("program count: %lld\n", profiler.get_program_count());
    printf("erase count: %lld\n", profiler.get_erase_count());
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值