ChainingBlockDevice example to showcase programming and reading from a chained group of HeapBlockDevices.

Fork of ChainingBlockDevice_ex_1 by mbed_example

Committer:
kgilbert
Date:
Wed Oct 18 20:03:25 2017 +0000
Revision:
1:8ad9777787ba
Parent:
0:daa62d7aa9f9
Child:
2:70419b9d778a
Add source for example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kgilbert 0:daa62d7aa9f9 1 #include "mbed.h"
kgilbert 0:daa62d7aa9f9 2 #include "HeapBlockDevice.h"
kgilbert 1:8ad9777787ba 3 #include "ChainingBlockDevice.h"
kgilbert 1:8ad9777787ba 4 #include "FATFileSystem.h"
kgilbert 0:daa62d7aa9f9 5
kgilbert 0:daa62d7aa9f9 6 int main(void) {
kgilbert 1:8ad9777787ba 7 // Create two smaller block devices with
kgilbert 1:8ad9777787ba 8 // 64 and 32 blocks of size 512 bytes
kgilbert 1:8ad9777787ba 9 HeapBlockDevice mem1(64*512, 512);
kgilbert 1:8ad9777787ba 10 HeapBlockDevice mem2(32*512, 512);
kgilbert 0:daa62d7aa9f9 11
kgilbert 1:8ad9777787ba 12 // Create a block device backed by mem1 and mem2
kgilbert 1:8ad9777787ba 13 // contains 96 blocks of size 512 bytes
kgilbert 1:8ad9777787ba 14 BlockDevice *bds[] = {&mem1, &mem2};
kgilbert 1:8ad9777787ba 15 ChainingBlockDevice chainmem(bds);
kgilbert 0:daa62d7aa9f9 16
kgilbert 1:8ad9777787ba 17 // Format the new chained block device with a FAT filesystem
kgilbert 1:8ad9777787ba 18 FATFileSystem::format(&chainmem);
kgilbert 1:8ad9777787ba 19
kgilbert 1:8ad9777787ba 20 // Create the FAT filesystem instance, files can now be written to
kgilbert 1:8ad9777787ba 21 // the FAT filesystem as if to a single 96 x 512 byte storage device
kgilbert 1:8ad9777787ba 22 FATFileSystem fat("fat", &chainmem);
kgilbert 0:daa62d7aa9f9 23 }