Implementation of a LocalFileSystem using S25FL216K serial flash memory. Currently only 256kB available!

Dependencies:   S25FL216K USBFileSystem

Dependents:   S25FL216K_HelloWorld

Committer:
Sissors
Date:
Tue Nov 19 15:10:46 2013 +0000
Revision:
2:ec125501d68f
Parent:
0:9056eb697726
New USBFileSystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:9056eb697726 1 /* mbed USBMSD_Ram Library
Sissors 0:9056eb697726 2 *
Sissors 0:9056eb697726 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
Sissors 0:9056eb697726 4 * of this software and associated documentation files (the "Software"), to deal
Sissors 0:9056eb697726 5 * in the Software without restriction, including without limitation the rights
Sissors 0:9056eb697726 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Sissors 0:9056eb697726 7 * copies of the Software, and to permit persons to whom the Software is
Sissors 0:9056eb697726 8 * furnished to do so, subject to the following conditions:
Sissors 0:9056eb697726 9 *
Sissors 0:9056eb697726 10 * The above copyright notice and this permission notice shall be included in
Sissors 0:9056eb697726 11 * all copies or substantial portions of the Software.
Sissors 0:9056eb697726 12 *
Sissors 0:9056eb697726 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Sissors 0:9056eb697726 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Sissors 0:9056eb697726 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Sissors 0:9056eb697726 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Sissors 0:9056eb697726 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Sissors 0:9056eb697726 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Sissors 0:9056eb697726 19 * THE SOFTWARE.
Sissors 0:9056eb697726 20 */
Sissors 0:9056eb697726 21
Sissors 0:9056eb697726 22 #include "Flash_USBFileSystem.h"
Sissors 0:9056eb697726 23
Sissors 0:9056eb697726 24 FlashUSB::FlashUSB(PinName mosi, PinName miso, PinName sclk, PinName cs) : USBFileSystem("USB"), flash(mosi, miso, sclk, cs) {
Sissors 0:9056eb697726 25 //no init
Sissors 0:9056eb697726 26 _status = 0x01;
Sissors 0:9056eb697726 27 }
Sissors 0:9056eb697726 28
Sissors 0:9056eb697726 29 int FlashUSB::disk_initialize() {
Sissors 0:9056eb697726 30 // OK
Sissors 0:9056eb697726 31 _status = 0x00;
Sissors 0:9056eb697726 32 return 0;
Sissors 0:9056eb697726 33 }
Sissors 0:9056eb697726 34
Sissors 0:9056eb697726 35 int FlashUSB::_disk_write(const uint8_t * buffer, uint64_t block_number) {
Sissors 0:9056eb697726 36 flash.eraseSector(block_number*4096);
Sissors 0:9056eb697726 37 flash.write(block_number*4096, (char*) buffer, 256);
Sissors 0:9056eb697726 38 flash.write(block_number*4096+256, (char*) buffer+256, 256);
Sissors 0:9056eb697726 39 return 0;
Sissors 0:9056eb697726 40 }
Sissors 0:9056eb697726 41
Sissors 0:9056eb697726 42 int FlashUSB::disk_read(uint8_t * buffer, uint64_t block_number) {
Sissors 0:9056eb697726 43 flash.read(block_number*4096, (char*) buffer, 512);
Sissors 0:9056eb697726 44 return 0;
Sissors 0:9056eb697726 45 }
Sissors 0:9056eb697726 46
Sissors 0:9056eb697726 47 int FlashUSB::_disk_status() { return _status; }
Sissors 0:9056eb697726 48 int FlashUSB::disk_sync() { return 0; }
Sissors 0:9056eb697726 49 uint64_t FlashUSB::disk_sectors() { return 512; }
Sissors 0:9056eb697726 50
Sissors 0:9056eb697726 51