Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

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