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.cpp
- Revision:
- 4:9a5878d316d5
- Parent:
- 3:210eb67b260c
- Child:
- 5:d85e20b6b904
--- a/SDCard.cpp Mon Aug 23 07:12:13 2010 +0000 +++ b/SDCard.cpp Fri Aug 27 00:59:28 2010 +0000 @@ -13,10 +13,10 @@ ChipSelect.write(1); //chip select is active low GenerateCRCTable(1, 137, CommandCRCTable); - //generate the command crc lookup table + //generate the command crc lookup table; //(generator polynomial x^7 + x^3 + 1 converts to decimal 137) GenerateCRCTable(2, 69665, DataCRCTable); - //generate the command crc lookup table + //generate the command crc lookup table; //(generator polynomial x^16 + x^12 + x^5 + 1 converts to decimal 69665) Initialize(); //run card setup operations @@ -159,8 +159,8 @@ Command(25, 0, Workspace); Mode = 0x01; } - //if previous call was not a write operation, sync the card, start a new write - //block, and set function to write mode + //if previous call was not a write operation, sync the card, + //start a new write block, and set function to write mode if (Index == 0) { ChipSelect.write(0); @@ -193,8 +193,8 @@ ChipSelect.write(1); Index = 0; } - //if the index is at the last address, get through CRC, Data response token, and - //busy signal and reset the index + //if the index is at the last address, get through CRC, + //Data response token, and busy signal and reset the index return 0xFF; //return stuff bits; control code 1 writes a byte @@ -205,8 +205,8 @@ Command(18, 0, Workspace); Mode = 0x02; } - //if previous call was not a read operation, sync the card, start a new read block, - //and set function to read mode + //if previous call was not a read operation, sync the card, + //start a new read block, and set function to read mode if (Index == 0) { ChipSelect.write(0); @@ -240,8 +240,8 @@ Index = 0; return Workspace[0]; } - //if the index is at the last address, get through CRC and reset the index; - //control code 2 reads a byte + //if the index is at the last address, get through + //CRC and reset the index; control code 2 reads a byte default: return 0xFF; @@ -345,6 +345,7 @@ { ChipSelect.write(0); DataLines.write(0xFD); + DataLines.write(0xFF); while (!DataLines.write(0xFF)); ChipSelect.write(1); DataLines.write(0xFF); @@ -540,8 +541,7 @@ { Command(55, 0, Workspace); Command(41, 1073741824, Workspace); - //specify host supports high capacity - //cards, [40,00,00,00] = 1073741824 + //specify host supports high capacity cards, [40,00,00,00] = 1073741824 t++; } while (Workspace[0] && (t < Timeout)); //check if card is ready @@ -732,8 +732,8 @@ do { Response[0] = DataLines.write(0xFF); - //clock the card high to let it run operations, the first byte will be - //busy (all high), the response will be sent some time later + //clock the card high to let it run operations, the first byte will + //be busy (all high), the response will be sent some time later t++; } while ((Response[0] & 0x80) && (t < Timeout)); //check for a response by testing if the first bit is low @@ -851,8 +851,10 @@ for (unsigned char l = 0; l < Index[8]; l++) //increment through the encountered generator 1s { - Table[(Size * ((0x01 << i) + j)) + k] ^= (((unsigned char*)&Generator)[7-k] << (i + 1 - Index[l])); - Table[(Size * ((0x01 << i) + j)) + k] ^= (((unsigned char*)&Generator)[6-k] >> (7 - i + Index[l])); + Table[(Size * ((0x01 << i) + j)) + k] ^= + (((unsigned char*)&Generator)[7-k] << (i + 1 - Index[l])); + Table[(Size * ((0x01 << i) + j)) + k] ^= + (((unsigned char*)&Generator)[6-k] >> (7 - i + Index[l])); //xor the new bit and the new generator 1s } }