Subdirectory provided by Embedded Artists
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Dependents: lpc4088_displaymodule_hello_world_Sept_2018
Fork of DMSupport by
FileSystems/RAMFileSystem.cpp@9:a33326afd686, 2014-12-11 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Dec 11 18:23:07 2014 +0000
- Revision:
- 9:a33326afd686
- Parent:
- 0:6b68dac0d986
- Child:
- 34:fc366bab393f
Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 9:a33326afd686 | 1 | /* |
embeddedartists | 9:a33326afd686 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 9:a33326afd686 | 3 | * |
embeddedartists | 9:a33326afd686 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 9:a33326afd686 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 9:a33326afd686 | 6 | * You may obtain a copy of the License at |
embeddedartists | 9:a33326afd686 | 7 | * |
embeddedartists | 9:a33326afd686 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 9:a33326afd686 | 9 | * |
embeddedartists | 9:a33326afd686 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 9:a33326afd686 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 9:a33326afd686 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 9:a33326afd686 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 9:a33326afd686 | 14 | * limitations under the License. |
embeddedartists | 9:a33326afd686 | 15 | */ |
embeddedartists | 9:a33326afd686 | 16 | |
embeddedartists | 0:6b68dac0d986 | 17 | #include "RAMFileSystem.h" |
embeddedartists | 0:6b68dac0d986 | 18 | #include "mbed_debug.h" |
embeddedartists | 0:6b68dac0d986 | 19 | |
embeddedartists | 0:6b68dac0d986 | 20 | #define RAMFS_DBG 0 |
embeddedartists | 0:6b68dac0d986 | 21 | |
embeddedartists | 0:6b68dac0d986 | 22 | #define SECTOR_SIZE 512 |
embeddedartists | 0:6b68dac0d986 | 23 | |
embeddedartists | 0:6b68dac0d986 | 24 | RAMFileSystem::RAMFileSystem(uint32_t addr, uint32_t size, const char* name) : |
embeddedartists | 0:6b68dac0d986 | 25 | FATFileSystem(name) { |
embeddedartists | 0:6b68dac0d986 | 26 | memStart = addr; |
embeddedartists | 0:6b68dac0d986 | 27 | memSize = size - (size % SECTOR_SIZE); |
embeddedartists | 0:6b68dac0d986 | 28 | status = 1; //1: disk not initialized |
embeddedartists | 0:6b68dac0d986 | 29 | } |
embeddedartists | 0:6b68dac0d986 | 30 | |
embeddedartists | 0:6b68dac0d986 | 31 | int RAMFileSystem::disk_initialize() { |
embeddedartists | 0:6b68dac0d986 | 32 | debug_if(RAMFS_DBG, "init RAM fs\n"); |
embeddedartists | 0:6b68dac0d986 | 33 | status = 0; //OK |
embeddedartists | 0:6b68dac0d986 | 34 | return status; |
embeddedartists | 0:6b68dac0d986 | 35 | } |
embeddedartists | 0:6b68dac0d986 | 36 | |
embeddedartists | 0:6b68dac0d986 | 37 | int RAMFileSystem::disk_write(const uint8_t *buffer, uint64_t sector, uint8_t count) { |
embeddedartists | 0:6b68dac0d986 | 38 | debug_if(RAMFS_DBG, "write to sector(s) %llu..%llu\n", sector, sector+count); |
embeddedartists | 0:6b68dac0d986 | 39 | if ((sector+count-1) >= disk_sectors()) { |
embeddedartists | 0:6b68dac0d986 | 40 | return 1; |
embeddedartists | 0:6b68dac0d986 | 41 | } |
embeddedartists | 0:6b68dac0d986 | 42 | |
embeddedartists | 0:6b68dac0d986 | 43 | memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE*count); |
embeddedartists | 0:6b68dac0d986 | 44 | return 0; |
embeddedartists | 0:6b68dac0d986 | 45 | } |
embeddedartists | 0:6b68dac0d986 | 46 | |
embeddedartists | 0:6b68dac0d986 | 47 | int RAMFileSystem::disk_read(uint8_t *buffer, uint64_t sector, uint8_t count) { |
embeddedartists | 0:6b68dac0d986 | 48 | debug_if(RAMFS_DBG, "read from sector(s) %llu..%llu\n", sector, sector+count); |
embeddedartists | 0:6b68dac0d986 | 49 | if ((sector+count-1) >= disk_sectors()) { |
embeddedartists | 0:6b68dac0d986 | 50 | return 1; |
embeddedartists | 0:6b68dac0d986 | 51 | } |
embeddedartists | 0:6b68dac0d986 | 52 | |
embeddedartists | 0:6b68dac0d986 | 53 | memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE*count); |
embeddedartists | 0:6b68dac0d986 | 54 | return 0; |
embeddedartists | 0:6b68dac0d986 | 55 | } |
embeddedartists | 0:6b68dac0d986 | 56 | |
embeddedartists | 0:6b68dac0d986 | 57 | int RAMFileSystem::disk_status() { |
embeddedartists | 0:6b68dac0d986 | 58 | debug_if(RAMFS_DBG, "disk status %d\n", status); |
embeddedartists | 0:6b68dac0d986 | 59 | return status; |
embeddedartists | 0:6b68dac0d986 | 60 | } |
embeddedartists | 0:6b68dac0d986 | 61 | int RAMFileSystem::disk_sync() { |
embeddedartists | 0:6b68dac0d986 | 62 | return 0; |
embeddedartists | 0:6b68dac0d986 | 63 | } |
embeddedartists | 0:6b68dac0d986 | 64 | uint64_t RAMFileSystem::disk_sectors() { |
embeddedartists | 0:6b68dac0d986 | 65 | debug_if(RAMFS_DBG, "returning fs has %u sectors\n", memSize/SECTOR_SIZE); |
embeddedartists | 0:6b68dac0d986 | 66 | return memSize/SECTOR_SIZE; |
embeddedartists | 0:6b68dac0d986 | 67 | } |
embeddedartists | 0:6b68dac0d986 | 68 | |
embeddedartists | 0:6b68dac0d986 | 69 | uint64_t RAMFileSystem::disk_size() { |
embeddedartists | 0:6b68dac0d986 | 70 | return memSize; |
embeddedartists | 0:6b68dac0d986 | 71 | } |