a

Dependencies:   FATFileSystem

Fork of SDFileSystem by Chaiyaporn Boonyasathian

Committer:
583405000008
Date:
Tue Dec 06 07:24:23 2016 +0000
Revision:
3:97dac58b99ec
Parent:
0:389b4c94c83b
d;

Who changed what in which revision?

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