typedef struct
{
uint8 CSDStruct; // CSD结构
uint8 SysSpecVersion; // 体系标准版别
uint8 Reserved1; // 保存
uint8 TAAC; // 读取时刻1
uint8 NSAC; // 数据在CLK周期内读取时刻2
uint8 MaxBusClkFrec; // 最大总线速度
uint16 CardComdClasses; // 卡指令调集
uint8 RdBlockLen; // 最大读取数据块长
uint8 PartBlockRead; // 答应读的部分块
uint8 WrBlockMisalign; // 非线写块
uint8 RdBlockMisalign; // 非线读块
uint8 DSRImpl; // DSR条件
uint8 Reserved2; // 保存
uint32 DeviceSize; // 设备容量
uint8 MaxRdCurrentVDDMin; // 最小读取电流 @ VDD min
uint8 MaxRdCurrentVDDMax; // 最大读取电流 @ VDD max
uint8 MaxWrCurrentVDDMin; // 最小写入电流 @ VDD min
uint8 MaxWrCurrentVDDMax; // 最大写入电流 @ VDD max
uint8 DeviceSizeMul; // 设备容量乘积因子
uint8 EraseGrSize; // 擦出块巨细
uint8 EraseGrMul; // 擦出扇区巨细
uint8 WrProtectGrSize; // 写保护群巨细
uint8 WrProtectGrEnable; // 写保护群使能
uint8 ManDeflECC; // Manufacturer default ECC
uint8 WrSpeedFact; // 写速度因子
uint8 MaxWrBlockLen; // 最大写数据块长度
uint8 WriteBlockPaPartial; // 答应写的部分
uint8 Reserved3; // 保存
uint8 ContentProtectAppli; // Content protection application
uint8 FileFormatGrouop; // 文件体系群
uint8 CopyFlag; // 复制标志
uint8 PermWrProtect; // 永久写保护
uint8 TempWrProtect; // 暂时写保护
uint8 FileFormat; // 文件体系
uint8 ECC; // ECC code
uint8 CSD_CRC; // CSD CRC
uint8 Reserved4; // 一直为 1
} SD_CSD;
/**************************************************************************************
* FunctionName : SD_GetCSDRegister()
* Description : CSD-寄存器。寄存器长度为128,16字节
* EntryParameter : csd 寄存器
* ReturnValue : 回来操作状况:成功-0
**************************************************************************************/
uint8 SD_GetCSDRegister(SD_CSD *csd)
{
uint8 i;
uint8 csdTable[16];
uint8 count = 0xFF;
uint8 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;
}