Demonstration of a very simple unix-like shell. Based on integrating both Klaus Bu\'s SDHCFileSystem and the FATFileSystem library out of Thomas Hamilton\'s SDCard program. Result: you get high capacity + a plethora of filesystem functions.

Dependencies:   mbed

Committer:
shimniok
Date:
Tue Oct 11 15:13:42 2011 +0000
Revision:
0:792bddcf799d
Initial

Who changed what in which revision?

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