TXT

CSD

By Donald Franklin,2014-12-04 10:38
11 views 0
CSD

    SD???ÁCSD?Ä?æÆ? 2011-06-13 14:37:51| ?ÖÀà?º ?ª??Ó?Óà | ?êÇ??º |×ÖºÅ?ó

    ÖÐ

    Ð? ??ÔÄ

    typedef struct

    {

     unsigned char CSDStruct; // CSD?á??

     unsigned char SysSpecVersion; // ϵÍ??æ???æ??

     unsigned char Reserved1; // ??Áô

     unsigned char TAAC; // ?ÁÈ?Ê??ä1

     unsigned char NSAC; // Êý?ÝÔÚCLKÖÜÆÚÄÚ?ÁÈ?Ê??ä2

     unsigned char MaxBusClkFrec; // ×î?ó×ÜÏßËÙ?È

     unsigned short CardComdClasses; // ??ÃüÁî??ºÏ

     unsigned char RdBlockLen; // ×î?ó?ÁÈ?Êý?Ý?é??

     unsigned char PartBlockRead; // ÔÊÐí?ÁµÄ???Ö?é

     unsigned char WrBlockMisalign; // ?ÇÏßÐ??é

     unsigned char RdBlockMisalign; // ?ÇÏß?Á?é

     unsigned char DSRImpl; // DSRÌõ?þ

     unsigned char Reserved2; // ??Áô

     unsigned int DeviceSize; // Éè??ÈÝÁ?

     unsigned char MaxRdCurrentVDDMin; // ×îÐ??ÁÈ?µçÁ? @ VDD min

     unsigned char MaxRdCurrentVDDMax; // ×î?ó?ÁÈ?µçÁ? @ VDD max

     unsigned char MaxWrCurrentVDDMin; // ×îÐ?Ð?ÈëµçÁ? @ VDD min

     unsigned char MaxWrCurrentVDDMax; // ×î?óÐ?ÈëµçÁ? @ VDD max

     unsigned char DeviceSizeMul; // Éè??ÈÝÁ??Ë?ýÒò×Ó

     unsigned char EraseGrSize; // ?Á?ö?é?óÐ?

     unsigned char EraseGrMul; // ?Á?öÉÈÇø?óÐ?

     unsigned char WrProtectGrSize; // Ð?????Ⱥ?óÐ?

     unsigned char WrProtectGrEnable; // Ð?????ȺÊ?ÄÜ

     unsigned char ManDeflECC; // Manufacturer default ECC

     unsigned char WrSpeedFact; // Ð?ËÙ?ÈÒò×Ó

     unsigned char MaxWrBlockLen; // ×î?óÐ?Êý?Ý?é???È

     unsigned char WriteBlockPaPartial; // ÔÊÐíÐ?µÄ???Ö

     unsigned char Reserved3; // ??Áô

     unsigned char ContentProtectAppli; // Content protection application

     unsigned char FileFormatGrouop; // ÎÄ?þϵÍ?Ⱥ

     unsigned char CopyFlag; // ?????êÖ?

     unsigned char PermWrProtect; // ÓÀ?ÃÐ?????

     unsigned char TempWrProtect; // ÔÝÊ?Ð?????

     unsigned char FileFormat; // ÎÄ?þϵÍ?

     unsigned char ECC; // ECC code

     unsigned char CSD_CRC; // CSD CRC

     unsigned char Reserved4; // Ê?ÖÕΪ 1

} SD_CSD;

    /**************************************************************************************

    * FunctionName : SD_GetCSDRegister()

    * Description : CSD-?Ä?æÆ????Ä?æÆ????ÈΪ128??16×Ö?Ú * EntryParameter : csd ?Ä?æÆ?

    * ReturnValue : ?µ?Ø?Ù×?×?Ì??º?É??-0

    **************************************************************************************/

    unsigned char SD_GetCSDRegister(SD_CSD *csd)

    {

     unsigned char i;

     unsigned char csdTable[16];

     unsigned char count = 0xFF;

     unsigned char rvalue = SD_RESPONSE_FAILURE; // ?µ?ØÖµ

     SD_Enable(0); // SD??Ê?ÄÜ

     if (SD_SendCmd(CMD9,0x00,0xFF) == SD_RESPONSE_NO_ERROR)

     {

     while ((SD_ReadByte() != SD_START_SINGLE_BLOCK_READ) && count) // µÈ?ýÊý?Ý?ÓÊÕ?ªÊ???ÊÕµ?0xFE?íÊ??ªÊ?

     {

     count--; // µÈ?ý??Ê?

     }

     if (count != 0x00)

     {

     for (i=0; i<16; i++)

     {

     csdTable[i] = SD_ReadByte();

     }

     }

     SD_ReadByte(); // ?ÁCRC

     SD_ReadByte();

     rvalue = SD_RESPONSE_NO_ERROR; // ÉèÖÃ?É???êÖ?

     }

     SD_Enable(1); // Çå?ýSD??Æ?Ñ?

     SD_WriteByte(0xFF); //

8?öÊ?ÖÓÂö?åµÄÑÓ?Ù

     // ?Ñ?ñÈ?Öµ?ÅÈëCSD?á??ÌåÖÐ

     csd->CSDStruct = (csdTable[0] & 0xC0) >> 6; // Byte 0

     csd->SysSpecVersion = (csdTable[0] & 0x3C) >> 2;

     csd->Reserved1 = csdTable[0] & 0x03;

     csd->TAAC = csdTable[1]; // Byte 1

     csd->NSAC = csdTable[2]; // Byte 2

     csd->MaxBusClkFrec = csdTable[3]; // Byte 3

     csd->CardComdClasses = csdTable[4] << 4; // Byte 4

     csd->CardComdClasses |= (csdTable[5] & 0xF0) >> 4; // Byte 5

     csd->RdBlockLen = csdTable[5] & 0x0F;

     csd->PartBlockRead = (csdTable[6] & 0x80) >> 7; // Byte 6

     csd->WrBlockMisalign = (csdTable[6] & 0x40) >> 6;

     csd->RdBlockMisalign = (csdTable[6] & 0x20) >> 5;

     csd->DSRImpl = (csdTable[6] & 0x10) >> 4;

     csd->Reserved2 = 0;

     csd->DeviceSize = (csdTable[6] & 0x03) << 10;

     csd->DeviceSize |= (csdTable[7]) << 2; // Byte 7

     csd->DeviceSize |= (csdTable[8] & 0xC0) >> 6; // Byte 8

     csd->MaxRdCurrentVDDMin = (csdTable[8] & 0x38) >> 3;

     csd->MaxRdCurrentVDDMax = (csdTable[8] & 0x07);

     csd->MaxWrCurrentVDDMin = (csdTable[9] & 0xE0) >> 5; // Byte 9

     csd->MaxWrCurrentVDDMax = (csdTable[9] & 0x1C) >> 2;

     csd->DeviceSizeMul = (csdTable[9] & 0x03) << 1;

     csd->DeviceSizeMul |= (csdTable[10] & 0x80) >> 7; // Byte 10

     csd->EraseGrSize = (csdTable[10] & 0x40) >> 6;

     csd->EraseGrMul = (csdTable[10] & 0x3F) << 1;

     csd->EraseGrMul |= (csdTable[11] & 0x80) >> 7; // Byte 11

     csd->WrProtectGrSize = (csdTable[11] & 0x7F);

     csd->WrProtectGrEnable = (csdTable[12] & 0x80) >> 7; // Byte 12

     csd->ManDeflECC = (csdTable[12] & 0x60) >> 5;

     csd->WrSpeedFact = (csdTable[12] & 0x1C) >> 2;

     csd->MaxWrBlockLen = (csdTable[12] & 0x03) << 2;

     csd->MaxWrBlockLen |= (csdTable[13] & 0xC0) >> 6; // Byte 13

     csd->WriteBlockPaPartial = (csdTable[13] & 0x20) >> 5;

     csd->Reserved3 = 0;

     csd->ContentProtectAppli = (csdTable[13] & 0x01);

     csd->FileFormatGrouop = (csdTable[14] & 0x80) >> 7; // Byte 14

     csd->CopyFlag = (csdTable[14] & 0x40) >> 6;

     csd->PermWrProtect = (csdTable[14] & 0x20) >> 5;

     csd->TempWrProtect = (csdTable[14] & 0x10) >> 4;

     csd->FileFormat = (csdTable[14] & 0x0C) >> 2;

     csd->ECC = (csdTable[14] & 0x03);

     csd->CSD_CRC = (csdTable[15] & 0xFE) >> 1; // Byte 15

     csd->Reserved4 = 1;

     return rvalue;

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com