-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
50 lines (39 loc) · 1.45 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2017-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#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);
}
}