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.

Dependencies:   mbed

SDCard.h

Committer:
Blaze513
Date:
2010-07-18
Revision:
0:f3870f76a890
Child:
1:94c648931f84

File content as of revision 0:f3870f76a890:

#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