Dependencies:   FatFileSystem mbed

Committer:
higedura
Date:
Sat Apr 21 14:07:27 2012 +0000
Revision:
2:307500c991dd
Parent:
0:813b917360ac

        

Who changed what in which revision?

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