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

SlicingBlockDevice

                                                                           

                                                                SlicingBlockDevice 类层次结构

SlicingBlockDevice 类提供了一种将块设备分解为子单元的方法,而无需手动跟踪偏移。SlicingBlockDevice 充当 ChainingBlockDevice 类的反义词。

构造函数接收主块设备指针以及您希望对子块进行分区的起始和结束地址。通过不指定结束地址,可以创建一个块设备,该设备从提供的起始地址跨越到底层块设备的末尾。

  • bd - 块设备返回 SlicingBlockDevice。
  • start - 起始块地址映射到块 0。负地址从底层块设备的末尾计算。
  • end - 结束块地址以标记块设备的结束。该块未映射;从底层块设备的末尾计算负地址。

SlicingBlockDevice 类参考

SlicingBlockDevice 类参考

公共成员函数
 SlicingBlockDevice (BlockDevice *bd, bd_addr_t start, bd_addr_t end=0)
virtual ~SlicingBlockDevice ()
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
 公共成员函数继承自 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
受保护的属性
BlockDevice_bd
bool _start_from_end
bd_size_t _start
bool _stop_from_end
bd_size_t _stop

SlicingBlockDevice 示例

此 SlicingBlockDevice 示例将 HeapBlockDevice 分区为三个子单元,并通过底层主块设备和切片子单元显示编程和读回数据段。

main.cpp                                                                                                                                            导入到 Mbed IDE

#include "mbed.h"
#include "HeapBlockDevice.h"
#include "SlicingBlockDevice.h"

#define BLOCK 512
#define NUMSLICES 3

char buff[BLOCK];

int main(void) {
    // Create a block device with 64 blocks of size 512
    HeapBlockDevice mem(64*BLOCK, BLOCK);

    SlicingBlockDevice slices[NUMSLICES] = {
        // Create a block device that maps to the first 32 blocks
        SlicingBlockDevice(&mem, 0 *BLOCK, 32*BLOCK),
    
        // Create a block device that maps to the middle 32 blocks
        SlicingBlockDevice(&mem, 16*BLOCK, -16*BLOCK),

        // Create a block device that maps to the last 32 blocks
        SlicingBlockDevice(&mem, 32*BLOCK)
    };

    for (int i = 0; i < NUMSLICES; i++) {
        // Initialize and erase the slice to prepar for programming
        slices[i].init();
        slices[i].erase(0, 32*BLOCK);
        
        // Construct the message for the block and write to the slice
        sprintf((char *)&buff, "test: %d", i);
        slices[i].program(&buff, 0, BLOCK);
    }

    for (int i = 0; i < NUMSLICES; i++) {
        // Read back the programmed blocks through the underlying block device
        mem.read(&buff, (i * 16 * BLOCK), BLOCK);
        printf("%s  --> ", buff);
        
        // Read back the programmed blocks through the sliced block device.
        slices[i].read(&buff,0, BLOCK);
        printf("%s\r\n", buff);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值