Solar Cell Powered - Periodic logging of sensor data into SD card

Dependencies:   mbed

Committer:
gsundaresan3
Date:
Mon Feb 28 20:05:48 2011 +0000
Revision:
0:248aa51eeb12

        

Who changed what in which revision?

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