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

Revision:
3:210eb67b260c
Parent:
1:94c648931f84
Child:
4:9a5878d316d5
--- a/SDCard.h	Mon Aug 23 01:31:50 2010 +0000
+++ b/SDCard.h	Mon Aug 23 07:12:13 2010 +0000
@@ -1,3 +1,8 @@
+//mbed Microcontroller Library
+//SDCard Interface
+//Copyright 2010
+//Thomas Hamilton
+
 #ifndef SDCardLibrary
 #define SDCardLibrary
 
@@ -30,23 +35,28 @@
         unsigned char Workspace[5];
             //all-purpose work area
         unsigned int Timeout;
+            //timeout limit
         unsigned int t;
-            //timeout limit and counter
+            //timeout counter
 
         unsigned char Initialize();
             //complete all initialization operations
         void Command(unsigned char Index, unsigned int Argument, unsigned char* Response);
             //sends command to the SD card
         void CommandCRC(unsigned char* IndexPtr, unsigned int* ArgumentPtr, unsigned char* Result);
+            //calculates the command CRC7 result with a lookup table
         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);
+            //calculates the CRC16 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_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();
@@ -56,14 +66,16 @@
     public:
         SDCard(PinName mosi, PinName miso, PinName sck, PinName cs, const char* DiskName);
             //constructor requires SPI and DigitalOut pins, and a directory name
+        virtual ~SDCard();
+            //destructor deallocates tables and workspace
         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
+            //  1       successively write input 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
+            //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
@@ -72,6 +84,9 @@
             //read data sectors from the card
         unsigned char SelectCRCMode(bool Mode);
             //turn CRC mode on or off, default is off
+        void SetTimeout(unsigned int Retries);
+            //change the number of retries for interface functions; increase if lines are
+            //unreliable; default is 1024
 };
 
 #endif
\ No newline at end of file