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