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