Skytraq S1315F-RAW-EVK Logger

Dependencies:   TextLCD mbed

Committer:
tosihisa
Date:
Sat Dec 18 11:17:21 2010 +0000
Revision:
0:e0ec137da369
1st release

Who changed what in which revision?

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