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.
SDCard.h@0:f3870f76a890, 2010-07-18 (annotated)
- Committer:
- Blaze513
- Date:
- Sun Jul 18 21:26:24 2010 +0000
- Revision:
- 0:f3870f76a890
- Child:
- 1:94c648931f84
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Blaze513 | 0:f3870f76a890 | 1 | #ifndef SDCardLibrary |
Blaze513 | 0:f3870f76a890 | 2 | #define SDCardLibrary |
Blaze513 | 0:f3870f76a890 | 3 | |
Blaze513 | 0:f3870f76a890 | 4 | #include "stdint.h" |
Blaze513 | 0:f3870f76a890 | 5 | #include "mbed.h" |
Blaze513 | 0:f3870f76a890 | 6 | |
Blaze513 | 0:f3870f76a890 | 7 | class SDCard |
Blaze513 | 0:f3870f76a890 | 8 | { |
Blaze513 | 0:f3870f76a890 | 9 | private: |
Blaze513 | 0:f3870f76a890 | 10 | SPI DataLines; |
Blaze513 | 0:f3870f76a890 | 11 | DigitalOut ChipSelect; |
Blaze513 | 0:f3870f76a890 | 12 | unsigned char CommandCRCTable[256]; |
Blaze513 | 0:f3870f76a890 | 13 | //CRC7 lookup table |
Blaze513 | 0:f3870f76a890 | 14 | unsigned char DataCRCTable[512]; |
Blaze513 | 0:f3870f76a890 | 15 | //CRC CCITT lookup table |
Blaze513 | 0:f3870f76a890 | 16 | unsigned char OCR[4]; |
Blaze513 | 0:f3870f76a890 | 17 | //operating condition register |
Blaze513 | 0:f3870f76a890 | 18 | unsigned char CSD[16]; |
Blaze513 | 0:f3870f76a890 | 19 | //card-specific data register |
Blaze513 | 0:f3870f76a890 | 20 | bool Version; |
Blaze513 | 0:f3870f76a890 | 21 | //card version, low for 1, high for 2 |
Blaze513 | 0:f3870f76a890 | 22 | bool Capacity; |
Blaze513 | 0:f3870f76a890 | 23 | //low for low-capacity, high for high-capacity |
Blaze513 | 0:f3870f76a890 | 24 | bool CRCMode; |
Blaze513 | 0:f3870f76a890 | 25 | //low to disable CRCs, high to enable CRCs |
Blaze513 | 0:f3870f76a890 | 26 | unsigned char Workspace[5]; |
Blaze513 | 0:f3870f76a890 | 27 | //generic information holder |
Blaze513 | 0:f3870f76a890 | 28 | |
Blaze513 | 0:f3870f76a890 | 29 | bool Initialize(); |
Blaze513 | 0:f3870f76a890 | 30 | //complete all initialization operations, returns 1 if operation successful |
Blaze513 | 0:f3870f76a890 | 31 | void Command(unsigned char Index, unsigned int Argument, unsigned char* Response); |
Blaze513 | 0:f3870f76a890 | 32 | //sends command to the SD card |
Blaze513 | 0:f3870f76a890 | 33 | char CommandCRC(unsigned char* IndexPtr, unsigned int* ArgumentPtr); |
Blaze513 | 0:f3870f76a890 | 34 | void DataCRC(unsigned short Length, unsigned char* Data, unsigned char* Result); |
Blaze513 | 0:f3870f76a890 | 35 | //calculates the CRC result of the input with a lookup table |
Blaze513 | 0:f3870f76a890 | 36 | void GenerateCRCTable(unsigned char Size, unsigned long long Generator, unsigned char* Table); |
Blaze513 | 0:f3870f76a890 | 37 | //pre-calculates CRC results for efficient checking |
Blaze513 | 0:f3870f76a890 | 38 | |
Blaze513 | 0:f3870f76a890 | 39 | public: |
Blaze513 | 0:f3870f76a890 | 40 | SDCard(PinName mosi, PinName miso, PinName sck, PinName cs); |
Blaze513 | 0:f3870f76a890 | 41 | bool Write(unsigned int Address, unsigned char* Data); |
Blaze513 | 0:f3870f76a890 | 42 | //write data to the card |
Blaze513 | 0:f3870f76a890 | 43 | bool Read(unsigned int Address, unsigned char* Data); |
Blaze513 | 0:f3870f76a890 | 44 | //read data from the card |
Blaze513 | 0:f3870f76a890 | 45 | }; |
Blaze513 | 0:f3870f76a890 | 46 | |
Blaze513 | 0:f3870f76a890 | 47 | #endif |