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