Final Report

Dependencies:   mbed

Fork of ecu_reader by Sukkin Pang

Committer:
pangsk
Date:
Mon Jul 12 10:03:53 2010 +0000
Revision:
2:e7b3b8da71ff

        

Who changed what in which revision?

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