mbed Dev board test program

Dependencies:   EthernetNetIf mbed HTTPServer SerialLCD

Committer:
pangsk
Date:
Mon Jul 11 15:02:04 2011 +0000
Revision:
0:0f36b9fac4c5

        

Who changed what in which revision?

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