Copy of SDFileSystem library

Dependents:   IoTGateway_Basic y_CameraC1098_ES_01 y_XBeeTest_5_read MOVIE_MUSIC_TRIVIA_GAME ... more

Committer:
SomeRandomBloke
Date:
Sat Mar 31 06:58:28 2012 +0000
Revision:
0:9c5f0c655284
Copy of SDFileSystem library

Who changed what in which revision?

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