SDHC Library SDCard

Dependents:   CameraC1098_picture CameraC1098_GPS_different_Lib

Committer:
atommota
Date:
Fri Jul 01 21:18:58 2011 +0000
Revision:
2:5e21e22ef223
Parent:
0:aefb7d370128

        

Who changed what in which revision?

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