GPS Data Logger with SD File system. Logger can save RMC & GGA data from GPS and five channels of analog data. Based on http://mbed.org/users/prf/ "GPS_Logger_01" by Peter Forden
SDFileSystem.h@0:dc3be3264d2d, 2010-04-17 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Apr 17 13:27:34 2010 +0000
- Revision:
- 0:dc3be3264d2d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:dc3be3264d2d | 1 | /* mbed Microcontroller Library - SDFileSystem |
kenjiArai | 0:dc3be3264d2d | 2 | * Copyright (c) 2008-2009, sford |
kenjiArai | 0:dc3be3264d2d | 3 | */ |
kenjiArai | 0:dc3be3264d2d | 4 | |
kenjiArai | 0:dc3be3264d2d | 5 | // VERY DRAFT CODE!!! |
kenjiArai | 0:dc3be3264d2d | 6 | |
kenjiArai | 0:dc3be3264d2d | 7 | #ifndef SDFILESYSTEM_H |
kenjiArai | 0:dc3be3264d2d | 8 | #define SDFILESYSTEM_H |
kenjiArai | 0:dc3be3264d2d | 9 | |
kenjiArai | 0:dc3be3264d2d | 10 | #include "mbed.h" |
kenjiArai | 0:dc3be3264d2d | 11 | #include "FATFileSystem.h" |
kenjiArai | 0:dc3be3264d2d | 12 | |
kenjiArai | 0:dc3be3264d2d | 13 | /* Class: SDFileSystem |
kenjiArai | 0:dc3be3264d2d | 14 | * Access the filesystem on an SD Card using SPI |
kenjiArai | 0:dc3be3264d2d | 15 | * |
kenjiArai | 0:dc3be3264d2d | 16 | * Example: |
kenjiArai | 0:dc3be3264d2d | 17 | * > SDFileSystem sd(p5, p6, p7, p12, "sd"); |
kenjiArai | 0:dc3be3264d2d | 18 | * > |
kenjiArai | 0:dc3be3264d2d | 19 | * > int main() { |
kenjiArai | 0:dc3be3264d2d | 20 | * > FILE *fp = fopen("/sd/myfile.txt", "w"); |
kenjiArai | 0:dc3be3264d2d | 21 | * > fprintf(fp, "Hello World!\n"); |
kenjiArai | 0:dc3be3264d2d | 22 | * > fclose(fp); |
kenjiArai | 0:dc3be3264d2d | 23 | * > } |
kenjiArai | 0:dc3be3264d2d | 24 | */ |
kenjiArai | 0:dc3be3264d2d | 25 | class SDFileSystem : public FATFileSystem { |
kenjiArai | 0:dc3be3264d2d | 26 | public: |
kenjiArai | 0:dc3be3264d2d | 27 | |
kenjiArai | 0:dc3be3264d2d | 28 | /* Constructor: SDFileSystem |
kenjiArai | 0:dc3be3264d2d | 29 | * Create the File System for accessing an SD Card using SPI |
kenjiArai | 0:dc3be3264d2d | 30 | * |
kenjiArai | 0:dc3be3264d2d | 31 | * Variables: |
kenjiArai | 0:dc3be3264d2d | 32 | * mosi - SPI mosi pin connected to SD Card |
kenjiArai | 0:dc3be3264d2d | 33 | * miso - SPI miso pin conencted to SD Card |
kenjiArai | 0:dc3be3264d2d | 34 | * sclk - SPI sclk pin connected to SD Card |
kenjiArai | 0:dc3be3264d2d | 35 | * cs - DigitalOut pin used as SD Card chip select |
kenjiArai | 0:dc3be3264d2d | 36 | * name - The name used to access the filesystem |
kenjiArai | 0:dc3be3264d2d | 37 | */ |
kenjiArai | 0:dc3be3264d2d | 38 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
kenjiArai | 0:dc3be3264d2d | 39 | virtual int disk_initialize(); |
kenjiArai | 0:dc3be3264d2d | 40 | virtual int disk_write(const char *buffer, int block_number); |
kenjiArai | 0:dc3be3264d2d | 41 | virtual int disk_read(char *buffer, int block_number); |
kenjiArai | 0:dc3be3264d2d | 42 | virtual int disk_status(); |
kenjiArai | 0:dc3be3264d2d | 43 | virtual int disk_sync(); |
kenjiArai | 0:dc3be3264d2d | 44 | virtual int disk_sectors(); |
kenjiArai | 0:dc3be3264d2d | 45 | |
kenjiArai | 0:dc3be3264d2d | 46 | protected: |
kenjiArai | 0:dc3be3264d2d | 47 | |
kenjiArai | 0:dc3be3264d2d | 48 | int _cmd(int cmd, int arg); |
kenjiArai | 0:dc3be3264d2d | 49 | int _cmdx(int cmd, int arg); |
kenjiArai | 0:dc3be3264d2d | 50 | int _cmd8(); |
kenjiArai | 0:dc3be3264d2d | 51 | int _cmd58(); |
kenjiArai | 0:dc3be3264d2d | 52 | int initialise_card(); |
kenjiArai | 0:dc3be3264d2d | 53 | int initialise_card_v1(); |
kenjiArai | 0:dc3be3264d2d | 54 | int initialise_card_v2(); |
kenjiArai | 0:dc3be3264d2d | 55 | |
kenjiArai | 0:dc3be3264d2d | 56 | |
kenjiArai | 0:dc3be3264d2d | 57 | int _read(char *buffer, int length); |
kenjiArai | 0:dc3be3264d2d | 58 | int _write(const char *buffer, int length); |
kenjiArai | 0:dc3be3264d2d | 59 | int _sd_sectors(); |
kenjiArai | 0:dc3be3264d2d | 60 | int _sectors; |
kenjiArai | 0:dc3be3264d2d | 61 | |
kenjiArai | 0:dc3be3264d2d | 62 | SPI _spi; |
kenjiArai | 0:dc3be3264d2d | 63 | DigitalOut _cs; |
kenjiArai | 0:dc3be3264d2d | 64 | }; |
kenjiArai | 0:dc3be3264d2d | 65 | |
kenjiArai | 0:dc3be3264d2d | 66 | #endif |