The purpose of this application is to allow easy manipulation of the QSPI file system from a PC
Dependencies: EALib USBDevice mbed
RAMFileSystem.cpp
00001 #include "RAMFileSystem.h" 00002 #include "mbed_debug.h" 00003 00004 #define RAMFS_DBG 0 00005 00006 #define SECTOR_SIZE 512 00007 00008 RAMFileSystem::RAMFileSystem(uint32_t addr, uint32_t size, const char* name) : 00009 FATFileSystem(name) { 00010 memStart = addr; 00011 memSize = size - (size % SECTOR_SIZE); 00012 status = 1; //1: disk not initialized 00013 } 00014 00015 int RAMFileSystem::disk_initialize() { 00016 debug_if(RAMFS_DBG, "init RAM fs\n"); 00017 status = 0; //OK 00018 return status; 00019 } 00020 00021 int RAMFileSystem::disk_write(const uint8_t *buffer, uint64_t sector) { 00022 debug_if(RAMFS_DBG, "write to sector %llu\n", sector); 00023 if (sector >= disk_sectors()) { 00024 return 1; 00025 } 00026 00027 memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE); 00028 return 0; 00029 } 00030 00031 int RAMFileSystem::disk_read(uint8_t *buffer, uint64_t sector) { 00032 debug_if(RAMFS_DBG, "read from sector %llu\n", sector); 00033 if (sector >= disk_sectors()) { 00034 return 1; 00035 } 00036 00037 memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE); 00038 return 0; 00039 } 00040 00041 int RAMFileSystem::disk_nwrite(const uint8_t *buffer, uint64_t sector, uint8_t count) { 00042 debug_if(RAMFS_DBG, "write to sector(s) %llu..%llu\n", sector, sector+count); 00043 if ((sector+count-1) >= disk_sectors()) { 00044 return 1; 00045 } 00046 00047 memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE*count); 00048 return 0; 00049 } 00050 00051 int RAMFileSystem::disk_nread(uint8_t *buffer, uint64_t sector, uint8_t count) { 00052 debug_if(RAMFS_DBG, "read from sector(s) %llu..%llu\n", sector, sector+count); 00053 if ((sector+count-1) >= disk_sectors()) { 00054 return 1; 00055 } 00056 00057 memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE*count); 00058 return 0; 00059 } 00060 00061 int RAMFileSystem::disk_status() { 00062 debug_if(RAMFS_DBG, "disk status %d\n", status); 00063 return status; 00064 } 00065 int RAMFileSystem::disk_sync() { 00066 return 0; 00067 } 00068 uint64_t RAMFileSystem::disk_sectors() { 00069 debug_if(RAMFS_DBG, "returning fs has %u sectors\n", memSize/SECTOR_SIZE); 00070 return memSize/SECTOR_SIZE; 00071 } 00072 00073 uint64_t RAMFileSystem::disk_size() { 00074 return memSize; 00075 } 00076
Generated on Wed Jul 13 2022 17:18:12 by 1.7.2