SlicingBlockDevice
SlicingBlockDevice 类层次结构
SlicingBlockDevice 类提供了一种将块设备分解为子单元的方法,而无需手动跟踪偏移。SlicingBlockDevice 充当 ChainingBlockDevice 类的反义词。
构造函数接收主块设备指针以及您希望对子块进行分区的起始和结束地址。通过不指定结束地址,可以创建一个块设备,该设备从提供的起始地址跨越到底层块设备的末尾。
- bd - 块设备返回 SlicingBlockDevice。
- start - 起始块地址映射到块 0。负地址从底层块设备的末尾计算。
- end - 结束块地址以标记块设备的结束。该块未映射;从底层块设备的末尾计算负地址。
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 分区为三个子单元,并通过底层主块设备和切片子单元显示编程和读回数据段。
#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);
}
}
相关内容
- ChainingBlockDevice API 参考。
- HeapBlockDevice API 参考。