t

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos

Fork of DMSupport by Embedded Artists

Committer:
embeddedartists
Date:
Fri Nov 21 11:42:51 2014 +0000
Revision:
0:6b68dac0d986
Child:
9:a33326afd686
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:6b68dac0d986 1 #include "RAMFileSystem.h"
embeddedartists 0:6b68dac0d986 2 #include "mbed_debug.h"
embeddedartists 0:6b68dac0d986 3
embeddedartists 0:6b68dac0d986 4 #define RAMFS_DBG 0
embeddedartists 0:6b68dac0d986 5
embeddedartists 0:6b68dac0d986 6 #define SECTOR_SIZE 512
embeddedartists 0:6b68dac0d986 7
embeddedartists 0:6b68dac0d986 8 RAMFileSystem::RAMFileSystem(uint32_t addr, uint32_t size, const char* name) :
embeddedartists 0:6b68dac0d986 9 FATFileSystem(name) {
embeddedartists 0:6b68dac0d986 10 memStart = addr;
embeddedartists 0:6b68dac0d986 11 memSize = size - (size % SECTOR_SIZE);
embeddedartists 0:6b68dac0d986 12 status = 1; //1: disk not initialized
embeddedartists 0:6b68dac0d986 13 }
embeddedartists 0:6b68dac0d986 14
embeddedartists 0:6b68dac0d986 15 int RAMFileSystem::disk_initialize() {
embeddedartists 0:6b68dac0d986 16 debug_if(RAMFS_DBG, "init RAM fs\n");
embeddedartists 0:6b68dac0d986 17 status = 0; //OK
embeddedartists 0:6b68dac0d986 18 return status;
embeddedartists 0:6b68dac0d986 19 }
embeddedartists 0:6b68dac0d986 20
embeddedartists 0:6b68dac0d986 21 int RAMFileSystem::disk_write(const uint8_t *buffer, uint64_t sector, uint8_t count) {
embeddedartists 0:6b68dac0d986 22 debug_if(RAMFS_DBG, "write to sector(s) %llu..%llu\n", sector, sector+count);
embeddedartists 0:6b68dac0d986 23 if ((sector+count-1) >= disk_sectors()) {
embeddedartists 0:6b68dac0d986 24 return 1;
embeddedartists 0:6b68dac0d986 25 }
embeddedartists 0:6b68dac0d986 26
embeddedartists 0:6b68dac0d986 27 memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE*count);
embeddedartists 0:6b68dac0d986 28 return 0;
embeddedartists 0:6b68dac0d986 29 }
embeddedartists 0:6b68dac0d986 30
embeddedartists 0:6b68dac0d986 31 int RAMFileSystem::disk_read(uint8_t *buffer, uint64_t sector, uint8_t count) {
embeddedartists 0:6b68dac0d986 32 debug_if(RAMFS_DBG, "read from sector(s) %llu..%llu\n", sector, sector+count);
embeddedartists 0:6b68dac0d986 33 if ((sector+count-1) >= disk_sectors()) {
embeddedartists 0:6b68dac0d986 34 return 1;
embeddedartists 0:6b68dac0d986 35 }
embeddedartists 0:6b68dac0d986 36
embeddedartists 0:6b68dac0d986 37 memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE*count);
embeddedartists 0:6b68dac0d986 38 return 0;
embeddedartists 0:6b68dac0d986 39 }
embeddedartists 0:6b68dac0d986 40
embeddedartists 0:6b68dac0d986 41 int RAMFileSystem::disk_status() {
embeddedartists 0:6b68dac0d986 42 debug_if(RAMFS_DBG, "disk status %d\n", status);
embeddedartists 0:6b68dac0d986 43 return status;
embeddedartists 0:6b68dac0d986 44 }
embeddedartists 0:6b68dac0d986 45 int RAMFileSystem::disk_sync() {
embeddedartists 0:6b68dac0d986 46 return 0;
embeddedartists 0:6b68dac0d986 47 }
embeddedartists 0:6b68dac0d986 48 uint64_t RAMFileSystem::disk_sectors() {
embeddedartists 0:6b68dac0d986 49 debug_if(RAMFS_DBG, "returning fs has %u sectors\n", memSize/SECTOR_SIZE);
embeddedartists 0:6b68dac0d986 50 return memSize/SECTOR_SIZE;
embeddedartists 0:6b68dac0d986 51 }
embeddedartists 0:6b68dac0d986 52
embeddedartists 0:6b68dac0d986 53 uint64_t RAMFileSystem::disk_size() {
embeddedartists 0:6b68dac0d986 54 return memSize;
embeddedartists 0:6b68dac0d986 55 }
embeddedartists 0:6b68dac0d986 56