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