This is a simple benchmark of the SDFileSystem module. This will attempt to write bytes to the SD card, and will time the operation and display the bits/sec.

Dependencies:   mbed

Committer:
theterg
Date:
Mon Feb 14 22:12:09 2011 +0000
Revision:
0:5e7c5b7321c9
1/14/10

Who changed what in which revision?

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