Local copy of the SDHCFileSystem. But changed the I/O frequency to 20MHz.

Dependents:   SimpleWaveRecorderPlayer Application-SimpleWaveRecorderPlayerGenerator

Committer:
shintamainjp
Date:
Sat Apr 14 02:22:19 2012 +0000
Revision:
0:5afeb866dfef
Initial version.

Who changed what in which revision?

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