![](/media/cache/profiles/momo.jpg.50x50_q85.jpg)
MemFilesystem_test
Dependencies: SDFileSystem mbed
main.cpp
- Committer:
- mzta
- Date:
- 2015-04-01
- Revision:
- 0:f1015c4245f6
- Child:
- 1:48383762a1ff
File content as of revision 0:f1015c4245f6:
#include "mbed.h" #include "MemFileSystem.h" #include "SDFileSystem.h" SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd"); namespace { const char *mem_file_path = "/ram/out.txt"; const char *sd_file_path = "/sd/fatdump"; const int DATA_SIZE = 10 * 1024; } int main() { uint8_t data_written[DATA_SIZE] = { 0 }; bool result = true; MemFileSystem *ramfs1 = new MemFileSystem("ram"); ramfs1->format(); { FILE *f = fopen(mem_file_path, "w"); printf("Mem: Writing ... "); for (int i = 0; i < DATA_SIZE; i++) { data_written[i] = rand() % 0XFF; fprintf(f, "%c", data_written[i]); } printf("[OK]\r\n"); fclose(f); } { FILE *f = fopen(mem_file_path, "r"); printf("Mem: Reading data ... "); for (int i = 0; i < DATA_SIZE; i++) { uint8_t data = fgetc(f); if (data != data_written[i]) { result = false; break; } } printf("[%s]\r\n", result ? "OK" : "FAIL"); fclose(f); } { FILE *f = fopen(sd_file_path, "w"); printf("Dump from MemFs to SDFs ... "); ramfs1->dump(f); printf("[OK]\r\n"); fclose(f); } delete ramfs1; MemFileSystem *ramfs2 = new MemFileSystem("ram"); { FILE *f = fopen(sd_file_path, "r"); printf("Load from SDFs to MemFs ... "); ramfs2->load(f); printf("[OK]\r\n"); fclose(f); } { FILE *f = fopen(mem_file_path, "r"); printf("Mem: Reading data ... "); for (int i = 0; i < DATA_SIZE; i++) { uint8_t data = fgetc(f); if (data != data_written[i]) { result = false; break; } } printf("[%s]\r\n", result ? "OK" : "FAIL"); fclose(f); } }