The Big Mouth Billy Bass program

Dependencies:   mbed

Committer:
sravet
Date:
Mon Jan 17 16:53:37 2011 +0000
Revision:
0:ef6fc1737022
Initial checkin

Who changed what in which revision?

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