Copy of "Simon Ford".

Committer:
ds074704261
Date:
Sun Nov 04 08:57:35 2012 +0000
Revision:
1:f060966d5bf9
Parent:
0:cb288fc30586
Copied on 09 Aug 2012.

Who changed what in which revision?

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