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