SDFileSystem

Dependencies:   FATFileSystem

Dependents:   EMIRv2

Fork of SDFileSystem by mbed official

Committer:
screamer
Date:
Mon Mar 17 14:34:01 2014 +0000
Revision:
3:7b35d1709458
Parent:
1:7153ee70df01
Added library documentation and updated FATFileSystem sub-library to the latest revision

Who changed what in which revision?

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