For BU9480F D-A Conv.

Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Sat Sep 11 11:23:26 2010 +0000
Revision:
3:64c3ed0fc4b4
Parent:
0:805cffac956b

        

Who changed what in which revision?

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