5

Dependencies:   FATFileSystem

Committer:
Marknaja
Date:
Sun Dec 16 02:05:32 2018 +0000
Revision:
0:7cd1533897a3
88

Who changed what in which revision?

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