SD Card test

Dependencies:   mbed

Committer:
dgwilson
Date:
Fri Apr 23 08:29:01 2010 +0000
Revision:
0:cca5efd78157

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgwilson 0:cca5efd78157 1 /* mbed Microcontroller Library - SDFileSystem
dgwilson 0:cca5efd78157 2 * Copyright (c) 2008-2009, sford
dgwilson 0:cca5efd78157 3 */
dgwilson 0:cca5efd78157 4
dgwilson 0:cca5efd78157 5 // VERY DRAFT CODE!!!
dgwilson 0:cca5efd78157 6
dgwilson 0:cca5efd78157 7 #ifndef SDFILESYSTEM_H
dgwilson 0:cca5efd78157 8 #define SDFILESYSTEM_H
dgwilson 0:cca5efd78157 9
dgwilson 0:cca5efd78157 10 #include "mbed.h"
dgwilson 0:cca5efd78157 11 #include "FATFileSystem.h"
dgwilson 0:cca5efd78157 12
dgwilson 0:cca5efd78157 13 /* Class: SDFileSystem
dgwilson 0:cca5efd78157 14 * Access the filesystem on an SD Card using SPI
dgwilson 0:cca5efd78157 15 *
dgwilson 0:cca5efd78157 16 * Example:
dgwilson 0:cca5efd78157 17 * > SDFileSystem sd(p5, p6, p7, p12, "sd");
dgwilson 0:cca5efd78157 18 * >
dgwilson 0:cca5efd78157 19 * > int main() {
dgwilson 0:cca5efd78157 20 * > FILE *fp = fopen("/sd/myfile.txt", "w");
dgwilson 0:cca5efd78157 21 * > fprintf(fp, "Hello World!\n");
dgwilson 0:cca5efd78157 22 * > fclose(fp);
dgwilson 0:cca5efd78157 23 * > }
dgwilson 0:cca5efd78157 24 */
dgwilson 0:cca5efd78157 25 class SDFileSystem : public FATFileSystem {
dgwilson 0:cca5efd78157 26 public:
dgwilson 0:cca5efd78157 27
dgwilson 0:cca5efd78157 28 /* Constructor: SDFileSystem
dgwilson 0:cca5efd78157 29 * Create the File System for accessing an SD Card using SPI
dgwilson 0:cca5efd78157 30 *
dgwilson 0:cca5efd78157 31 * Variables:
dgwilson 0:cca5efd78157 32 * mosi - SPI mosi pin connected to SD Card
dgwilson 0:cca5efd78157 33 * miso - SPI miso pin conencted to SD Card
dgwilson 0:cca5efd78157 34 * sclk - SPI sclk pin connected to SD Card
dgwilson 0:cca5efd78157 35 * cs - DigitalOut pin used as SD Card chip select
dgwilson 0:cca5efd78157 36 * name - The name used to access the filesystem
dgwilson 0:cca5efd78157 37 */
dgwilson 0:cca5efd78157 38 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
dgwilson 0:cca5efd78157 39 virtual int disk_initialize();
dgwilson 0:cca5efd78157 40 virtual int disk_write(const char *buffer, int block_number);
dgwilson 0:cca5efd78157 41 virtual int disk_read(char *buffer, int block_number);
dgwilson 0:cca5efd78157 42 virtual int disk_status();
dgwilson 0:cca5efd78157 43 virtual int disk_sync();
dgwilson 0:cca5efd78157 44 virtual int disk_sectors();
dgwilson 0:cca5efd78157 45
dgwilson 0:cca5efd78157 46 protected:
dgwilson 0:cca5efd78157 47
dgwilson 0:cca5efd78157 48 int _cmd(int cmd, int arg);
dgwilson 0:cca5efd78157 49 int _cmdx(int cmd, int arg);
dgwilson 0:cca5efd78157 50 int _cmd41();
dgwilson 0:cca5efd78157 51 int _cmd8();
dgwilson 0:cca5efd78157 52 int _cmd58();
dgwilson 0:cca5efd78157 53 int initialise_card();
dgwilson 0:cca5efd78157 54 int initialise_card_v1();
dgwilson 0:cca5efd78157 55 int initialise_card_v2();
dgwilson 0:cca5efd78157 56
dgwilson 0:cca5efd78157 57
dgwilson 0:cca5efd78157 58 int _read(char *buffer, int length);
dgwilson 0:cca5efd78157 59 int _write(const char *buffer, int length);
dgwilson 0:cca5efd78157 60 int _sd_sectors();
dgwilson 0:cca5efd78157 61 int _sectors;
dgwilson 0:cca5efd78157 62
dgwilson 0:cca5efd78157 63 SPI _spi;
dgwilson 0:cca5efd78157 64 DigitalOut _cs;
dgwilson 0:cca5efd78157 65
dgwilson 0:cca5efd78157 66 struct CSD_REGISTER {
dgwilson 0:cca5efd78157 67 unsigned reserved1:4;
dgwilson 0:cca5efd78157 68 unsigned reserved2:3;
dgwilson 0:cca5efd78157 69 unsigned low_voltage:1;
dgwilson 0:cca5efd78157 70 unsigned reserved3:7;
dgwilson 0:cca5efd78157 71 unsigned volt_27_28:1;
dgwilson 0:cca5efd78157 72 unsigned volt_28_29:1;
dgwilson 0:cca5efd78157 73 unsigned volt_29_30:1;
dgwilson 0:cca5efd78157 74 unsigned volt_30_31:1;
dgwilson 0:cca5efd78157 75 unsigned volt_31_32:1;
dgwilson 0:cca5efd78157 76 unsigned volt_32_33:1;
dgwilson 0:cca5efd78157 77 unsigned volt_33_34:1;
dgwilson 0:cca5efd78157 78 unsigned volt_34_35:1;
dgwilson 0:cca5efd78157 79 unsigned volt_35_36:1;
dgwilson 0:cca5efd78157 80 unsigned reserved:6;
dgwilson 0:cca5efd78157 81 unsigned card_capacity_status:1;
dgwilson 0:cca5efd78157 82 unsigned card_power_up_status:1;
dgwilson 0:cca5efd78157 83 };
dgwilson 0:cca5efd78157 84 };
dgwilson 0:cca5efd78157 85
dgwilson 0:cca5efd78157 86 #endif