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:
- 0:f3870f76a890
- Child:
- 1:94c648931f84
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDCard.h Sun Jul 18 21:26:24 2010 +0000 @@ -0,0 +1,47 @@ +#ifndef SDCardLibrary +#define SDCardLibrary + +#include "stdint.h" +#include "mbed.h" + +class SDCard +{ + private: + SPI DataLines; + DigitalOut ChipSelect; + unsigned char CommandCRCTable[256]; + //CRC7 lookup table + unsigned char DataCRCTable[512]; + //CRC CCITT lookup table + unsigned char OCR[4]; + //operating condition register + unsigned char CSD[16]; + //card-specific data register + bool Version; + //card version, low for 1, high for 2 + bool Capacity; + //low for low-capacity, high for high-capacity + bool CRCMode; + //low to disable CRCs, high to enable CRCs + unsigned char Workspace[5]; + //generic information holder + + bool Initialize(); + //complete all initialization operations, returns 1 if operation successful + 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 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 + + 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 +}; + +#endif \ No newline at end of file