nesta
Fork of SDFileSystem by
SDFileSystem.h@7:d2502a37ebf9, 2017-09-09 (annotated)
- Committer:
- suads
- Date:
- Sat Sep 09 14:33:28 2017 +0000
- Revision:
- 7:d2502a37ebf9
- Parent:
- 4:3f40cbfe801c
jebeee
Who changed what in which revision?
User | Revision | Line number | New 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> |
suads | 7:d2502a37ebf9 | 28 | #include <string> |
suads | 7:d2502a37ebf9 | 29 | //#include "SDFileSystem.h" |
emilmont | 1:7153ee70df01 | 30 | /** Access the filesystem on an SD Card using SPI |
emilmont | 1:7153ee70df01 | 31 | * |
emilmont | 1:7153ee70df01 | 32 | * @code |
emilmont | 1:7153ee70df01 | 33 | * #include "mbed.h" |
emilmont | 1:7153ee70df01 | 34 | * #include "SDFileSystem.h" |
emilmont | 1:7153ee70df01 | 35 | * |
maclobdell | 4:3f40cbfe801c | 36 | * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs |
maclobdell | 4:3f40cbfe801c | 37 | * |
emilmont | 1:7153ee70df01 | 38 | * int main() { |
maclobdell | 4:3f40cbfe801c | 39 | * FILE *fp = fopen("/sd/myfile.txt", "w"); |
emilmont | 1:7153ee70df01 | 40 | * fprintf(fp, "Hello World!\n"); |
emilmont | 1:7153ee70df01 | 41 | * fclose(fp); |
emilmont | 1:7153ee70df01 | 42 | * } |
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); |
emilmont | 1:7153ee70df01 | 56 | virtual int disk_initialize(); |
emilmont | 1:7153ee70df01 | 57 | virtual int disk_status(); |
maclobdell | 4:3f40cbfe801c | 58 | virtual int disk_read(uint8_t* buffer, uint32_t block_number, uint32_t count); |
maclobdell | 4:3f40cbfe801c | 59 | virtual int disk_write(const uint8_t* buffer, uint32_t block_number, uint32_t count); |
emilmont | 1:7153ee70df01 | 60 | virtual int disk_sync(); |
maclobdell | 4:3f40cbfe801c | 61 | virtual uint32_t disk_sectors(); |
suads | 7:d2502a37ebf9 | 62 | bool writeSD(char *filename,char *payload); |
suads | 7:d2502a37ebf9 | 63 | bool readSD(char *filename,char *SDBuffer); |
emilmont | 1:7153ee70df01 | 64 | |
emilmont | 1:7153ee70df01 | 65 | protected: |
emilmont | 1:7153ee70df01 | 66 | |
emilmont | 1:7153ee70df01 | 67 | int _cmd(int cmd, int arg); |
emilmont | 1:7153ee70df01 | 68 | int _cmdx(int cmd, int arg); |
emilmont | 1:7153ee70df01 | 69 | int _cmd8(); |
emilmont | 1:7153ee70df01 | 70 | int _cmd58(); |
emilmont | 1:7153ee70df01 | 71 | int initialise_card(); |
emilmont | 1:7153ee70df01 | 72 | int initialise_card_v1(); |
emilmont | 1:7153ee70df01 | 73 | int initialise_card_v2(); |
maclobdell | 4:3f40cbfe801c | 74 | |
emilmont | 1:7153ee70df01 | 75 | int _read(uint8_t * buffer, uint32_t length); |
emilmont | 1:7153ee70df01 | 76 | int _write(const uint8_t *buffer, uint32_t length); |
maclobdell | 4:3f40cbfe801c | 77 | uint32_t _sd_sectors(); |
maclobdell | 4:3f40cbfe801c | 78 | uint32_t _sectors; |
maclobdell | 4:3f40cbfe801c | 79 | |
maclobdell | 4:3f40cbfe801c | 80 | void set_init_sck(uint32_t sck) { _init_sck = sck; } |
maclobdell | 4:3f40cbfe801c | 81 | // Note: The highest SPI clock rate is 20 MHz for MMC and 25 MHz for SD |
maclobdell | 4:3f40cbfe801c | 82 | void set_transfer_sck(uint32_t sck) { _transfer_sck = sck; } |
maclobdell | 4:3f40cbfe801c | 83 | uint32_t _init_sck; |
maclobdell | 4:3f40cbfe801c | 84 | uint32_t _transfer_sck; |
maclobdell | 4:3f40cbfe801c | 85 | |
emilmont | 1:7153ee70df01 | 86 | SPI _spi; |
emilmont | 1:7153ee70df01 | 87 | DigitalOut _cs; |
emilmont | 1:7153ee70df01 | 88 | int cdv; |
maclobdell | 4:3f40cbfe801c | 89 | int _is_initialized; |
emilmont | 1:7153ee70df01 | 90 | }; |
emilmont | 1:7153ee70df01 | 91 | |
maclobdell | 4:3f40cbfe801c | 92 | #endif |