mbed Revision 38 SDHC 4GB

Dependencies:   ChaNFS

Dependents:   WebCamera_SD

Fork of ChaNFSSD by Stefan Mueller

Committer:
Dromar
Date:
Sun Feb 10 15:25:02 2013 +0000
Revision:
1:311fcc5058b3
ChanNFSSD?SDHCFileSystem??????????; mbed?Revision38???????????

Who changed what in which revision?

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