SD Card Interface class. Log raw data bytes to memory addresses of your choice, or format the card and use the FAT file system to write files.
Diff: SDCard.h
- Revision:
- 1:94c648931f84
- Parent:
- 0:f3870f76a890
- Child:
- 3:210eb67b260c
--- a/SDCard.h Sun Jul 18 21:26:24 2010 +0000 +++ b/SDCard.h Sat Aug 07 18:32:30 2010 +0000 @@ -3,12 +3,14 @@ #include "stdint.h" #include "mbed.h" +#include "FATFileSystem.h" -class SDCard +class SDCard : private FATFileSystem { private: SPI DataLines; DigitalOut ChipSelect; + //physical chip interface unsigned char CommandCRCTable[256]; //CRC7 lookup table unsigned char DataCRCTable[512]; @@ -17,6 +19,8 @@ //operating condition register unsigned char CSD[16]; //card-specific data register + unsigned char FSR[64]; + //function status register bool Version; //card version, low for 1, high for 2 bool Capacity; @@ -24,24 +28,50 @@ bool CRCMode; //low to disable CRCs, high to enable CRCs unsigned char Workspace[5]; - //generic information holder + //all-purpose work area + unsigned int Timeout; + unsigned int t; + //timeout limit and counter - bool Initialize(); - //complete all initialization operations, returns 1 if operation successful + unsigned char Initialize(); + //complete all initialization operations void Command(unsigned char Index, unsigned int Argument, unsigned char* Response); //sends command to the SD card - char CommandCRC(unsigned char* IndexPtr, unsigned int* ArgumentPtr); + void CommandCRC(unsigned char* IndexPtr, unsigned int* ArgumentPtr, unsigned char* Result); void DataCRC(unsigned short Length, unsigned char* Data, unsigned char* Result); //calculates the CRC result of the input with a lookup table void GenerateCRCTable(unsigned char Size, unsigned long long Generator, unsigned char* Table); //pre-calculates CRC results for efficient checking + virtual unsigned char disk_initialize(); + virtual unsigned char disk_status(); + virtual unsigned char disk_read(unsigned char* buff, unsigned long sector, unsigned char count); + virtual unsigned char disk_write(const unsigned char* buff, unsigned long sector, unsigned char count); + virtual unsigned char disk_sync(); + virtual unsigned long disk_sector_count(); + virtual unsigned short disk_sector_size(); + virtual unsigned long disk_block_size(); + //FAT system virtual function definitions, called by FAT module + public: - SDCard(PinName mosi, PinName miso, PinName sck, PinName cs); - bool Write(unsigned int Address, unsigned char* Data); - //write data to the card - bool Read(unsigned int Address, unsigned char* Data); - //read data from the card + SDCard(PinName mosi, PinName miso, PinName sck, PinName cs, const char* DiskName); + //constructor requires SPI and DigitalOut pins, and a directory name + unsigned char Log(unsigned char Control, unsigned char Data); + //multipurpose raw data-logging method with three modes of operation + //Control description + // 0 synchronizes card and resets internal counter to finalize I/O operations + // 1 successive write input Data to a raw data byte in order starting at address 0 + // 2 successively read and return a raw data byte in order starting at address 0 + //return data from sync or write operations, and input data of sync or read operations are + //"don't care" bits + unsigned char Write(unsigned int Address, unsigned char* Data); + unsigned char Write(unsigned int Address, unsigned char SectorCount, unsigned char* Data); + //write data sectors to the card + unsigned char Read(unsigned int Address, unsigned char* Data); + unsigned char Read(unsigned int Address, unsigned char SectorCount, unsigned char* Data); + //read data sectors from the card + unsigned char SelectCRCMode(bool Mode); + //turn CRC mode on or off, default is off }; #endif \ No newline at end of file