Dependencies:   mbed

Committer:
joosttromp
Date:
Fri Jun 17 11:30:43 2011 +0000
Revision:
0:aa9931e79e3f

        

Who changed what in which revision?

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