dd

Dependencies:   C12832 mbed

Committer:
pfe
Date:
Wed Apr 08 08:27:55 2015 +0000
Revision:
0:caecb0d1e7d3
ddd

Who changed what in which revision?

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