The software I used to run my Sparkfun AVC 2011 entry, a 1:10 scale RC truck called \"Data Bus\". This is the final revision of the code as-run on April 23, 2011, the date of the contest, on the 3rd heat.

Dependencies:   TinyCHR6dm PinDetect mbed IncrementalEncoder Servo Schedule DebounceIn SimpleFilter LSM303DLH Steering

Committer:
shimniok
Date:
Wed Apr 27 19:23:43 2011 +0000
Revision:
0:9b27ebe1ce17
Initial release

Who changed what in which revision?

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