Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Fri Jan 21 08:39:48 2011 +0000
Revision:
0:63ed631d8c3a

        

Who changed what in which revision?

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