just updated FATFileSystem as latest revision

Dependencies:   FATFileSystem

Dependents:   FlashAir_iSDIO_test_program_on_OS5 SD_Card_Control AKASHIKOSEN Mic_Recorder ... more

Fork of SDFileSystem by mbed official

Committer:
emilmont
Date:
Tue Nov 27 17:32:38 2012 +0000
Revision:
1:7153ee70df01
Parent:
0:b87bae1534bb
Child:
3:7b35d1709458
Commit SDFileSystem code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:7153ee70df01 1 /* mbed Microcontroller Library
emilmont 1:7153ee70df01 2 * Copyright (c) 2006-2012 ARM Limited
emilmont 1:7153ee70df01 3 *
emilmont 1:7153ee70df01 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
emilmont 1:7153ee70df01 5 * of this software and associated documentation files (the "Software"), to deal
emilmont 1:7153ee70df01 6 * in the Software without restriction, including without limitation the rights
emilmont 1:7153ee70df01 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emilmont 1:7153ee70df01 8 * copies of the Software, and to permit persons to whom the Software is
emilmont 1:7153ee70df01 9 * furnished to do so, subject to the following conditions:
emilmont 1:7153ee70df01 10 *
emilmont 1:7153ee70df01 11 * The above copyright notice and this permission notice shall be included in
emilmont 1:7153ee70df01 12 * all copies or substantial portions of the Software.
emilmont 1:7153ee70df01 13 *
emilmont 1:7153ee70df01 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emilmont 1:7153ee70df01 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emilmont 1:7153ee70df01 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emilmont 1:7153ee70df01 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emilmont 1:7153ee70df01 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 1:7153ee70df01 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
emilmont 1:7153ee70df01 20 * SOFTWARE.
emilmont 1:7153ee70df01 21 */
emilmont 1:7153ee70df01 22 #ifndef MBED_SDFILESYSTEM_H
emilmont 1:7153ee70df01 23 #define MBED_SDFILESYSTEM_H
emilmont 1:7153ee70df01 24
emilmont 1:7153ee70df01 25 #include "mbed.h"
emilmont 1:7153ee70df01 26 #include "FATFileSystem.h"
emilmont 1:7153ee70df01 27 #include <stdint.h>
emilmont 1:7153ee70df01 28
emilmont 1:7153ee70df01 29 /** Access the filesystem on an SD Card using SPI
emilmont 1:7153ee70df01 30 *
emilmont 1:7153ee70df01 31 * @code
emilmont 1:7153ee70df01 32 * #include "mbed.h"
emilmont 1:7153ee70df01 33 * #include "SDFileSystem.h"
emilmont 1:7153ee70df01 34 *
emilmont 1:7153ee70df01 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
emilmont 1:7153ee70df01 36 *
emilmont 1:7153ee70df01 37 * int main() {
emilmont 1:7153ee70df01 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
emilmont 1:7153ee70df01 39 * fprintf(fp, "Hello World!\n");
emilmont 1:7153ee70df01 40 * fclose(fp);
emilmont 1:7153ee70df01 41 * }
emilmont 1:7153ee70df01 42 */
emilmont 1:7153ee70df01 43 class SDFileSystem : public FATFileSystem {
emilmont 1:7153ee70df01 44 public:
emilmont 1:7153ee70df01 45
emilmont 1:7153ee70df01 46 /** Create the File System for accessing an SD Card using SPI
emilmont 1:7153ee70df01 47 *
emilmont 1:7153ee70df01 48 * @param mosi SPI mosi pin connected to SD Card
emilmont 1:7153ee70df01 49 * @param miso SPI miso pin conencted to SD Card
emilmont 1:7153ee70df01 50 * @param sclk SPI sclk pin connected to SD Card
emilmont 1:7153ee70df01 51 * @param cs DigitalOut pin used as SD Card chip select
emilmont 1:7153ee70df01 52 * @param name The name used to access the virtual filesystem
emilmont 1:7153ee70df01 53 */
emilmont 1:7153ee70df01 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
emilmont 1:7153ee70df01 55 virtual int disk_initialize();
emilmont 1:7153ee70df01 56 virtual int disk_status();
emilmont 1:7153ee70df01 57 virtual int disk_read(uint8_t * buffer, uint64_t block_number);
emilmont 1:7153ee70df01 58 virtual int disk_write(const uint8_t * buffer, uint64_t block_number);
emilmont 1:7153ee70df01 59 virtual int disk_sync();
emilmont 1:7153ee70df01 60 virtual uint64_t disk_sectors();
emilmont 1:7153ee70df01 61
emilmont 1:7153ee70df01 62 protected:
emilmont 1:7153ee70df01 63
emilmont 1:7153ee70df01 64 int _cmd(int cmd, int arg);
emilmont 1:7153ee70df01 65 int _cmdx(int cmd, int arg);
emilmont 1:7153ee70df01 66 int _cmd8();
emilmont 1:7153ee70df01 67 int _cmd58();
emilmont 1:7153ee70df01 68 int initialise_card();
emilmont 1:7153ee70df01 69 int initialise_card_v1();
emilmont 1:7153ee70df01 70 int initialise_card_v2();
emilmont 1:7153ee70df01 71
emilmont 1:7153ee70df01 72 int _read(uint8_t * buffer, uint32_t length);
emilmont 1:7153ee70df01 73 int _write(const uint8_t *buffer, uint32_t length);
emilmont 1:7153ee70df01 74 uint64_t _sd_sectors();
emilmont 1:7153ee70df01 75 uint64_t _sectors;
emilmont 1:7153ee70df01 76
emilmont 1:7153ee70df01 77 SPI _spi;
emilmont 1:7153ee70df01 78 DigitalOut _cs;
emilmont 1:7153ee70df01 79 int cdv;
emilmont 1:7153ee70df01 80 };
emilmont 1:7153ee70df01 81
emilmont 1:7153ee70df01 82 #endif