Dependencies:   mbed

Committer:
simon
Date:
Mon Dec 14 22:32:28 2009 +0000
Revision:
2:849162a1207f
Parent:
0:666a082cf50f
Child:
3:68ef62208d4d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 2:849162a1207f 1 /* mbed Microcontroller Library - SDFileSystem
simon 2:849162a1207f 2 * Copyright (c) 2008-2009, sford
simon 2:849162a1207f 3 */
simon 2:849162a1207f 4
simon 2:849162a1207f 5 #ifndef SDFILESYSTEM_H
simon 2:849162a1207f 6 #define SDFILESYSTEM_H
simon 2:849162a1207f 7
simon 2:849162a1207f 8 #include "mbed.h"
simon 2:849162a1207f 9 #include "FATFileSystem.h"
simon 2:849162a1207f 10
simon 2:849162a1207f 11 /* Class: SDFileSystem
simon 2:849162a1207f 12 * Access the filesystem on an SD Card using SPI
simon 2:849162a1207f 13 *
simon 2:849162a1207f 14 * Example:
simon 2:849162a1207f 15 * > SDFileSystem sd(p5, p6, p7, p12, "sd");
simon 2:849162a1207f 16 * >
simon 2:849162a1207f 17 * > int main() {
simon 2:849162a1207f 18 * > FILE *fp = fopen("/sd/myfile.txt", "w");
simon 2:849162a1207f 19 * > fprintf(fp, "Hello World!\n");
simon 2:849162a1207f 20 * > fclose(fp);
simon 2:849162a1207f 21 * > }
simon 2:849162a1207f 22 */
simon 2:849162a1207f 23 class SDFileSystem : public FATFileSystem {
simon 2:849162a1207f 24 public:
simon 2:849162a1207f 25
simon 2:849162a1207f 26 /* Constructor: SDFileSystem
simon 2:849162a1207f 27 * Create the File System for accessing an SD Card using SPI
simon 2:849162a1207f 28 *
simon 2:849162a1207f 29 * Variables:
simon 2:849162a1207f 30 * mosi - SPI mosi pin connected to SD Card
simon 2:849162a1207f 31 * miso - SPI miso pin conencted to SD Card
simon 2:849162a1207f 32 * sclk - SPI sclk pin connected to SD Card
simon 2:849162a1207f 33 * cs - DigitalOut pin used as SD Card chip select
simon 2:849162a1207f 34 * name - The name used to access the filesystem
simon 2:849162a1207f 35 */
simon 2:849162a1207f 36 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
simon 2:849162a1207f 37 virtual int disk_initialize();
simon 2:849162a1207f 38 virtual int disk_write(const char *buffer, int block_number);
simon 2:849162a1207f 39 virtual int disk_read(char *buffer, int block_number);
simon 2:849162a1207f 40 virtual int disk_status();
simon 2:849162a1207f 41 virtual int disk_sync();
simon 2:849162a1207f 42 virtual int disk_sectors();
simon 2:849162a1207f 43
simon 2:849162a1207f 44 protected:
simon 2:849162a1207f 45
simon 2:849162a1207f 46 int _cmd(int cmd, int arg);
simon 2:849162a1207f 47 int _cmd8();
simon 2:849162a1207f 48
simon 2:849162a1207f 49 int _read(char *buffer, int length);
simon 2:849162a1207f 50 int _write(const char *buffer, int length);
simon 2:849162a1207f 51 int _sd_sectors();
simon 2:849162a1207f 52 int _sectors;
simon 2:849162a1207f 53
simon 2:849162a1207f 54 SPI _spi;
simon 2:849162a1207f 55 DigitalOut _cs;
simon 2:849162a1207f 56 };
simon 2:849162a1207f 57
simon 2:849162a1207f 58 #endif