Dependencies:   mbed FatFileSystem

Committer:
higedura
Date:
Mon Sep 17 09:39:54 2012 +0000
Revision:
1:0c42db451cb9
Parent:
0:75227c386257
dotHR_phothe

Who changed what in which revision?

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