谢谢了。
switch (ctrl) {
case GET_SECTORS : /* Get number of sectors on the disk (unsigned long) */
if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16/2)) {
/* Calculate disk size */
csm = 1 << (((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2);
csize = ((uint16)(csd[8] & 3) >> 6) + (uint16)(csd[7] << 2) + ((uint16)(csd[6] & 3) << 10) + 1;
*(uint32*)buff = (uint32)csize * csm;
res = RES_OK;
}
break;
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
if ((send_cmd(CMD9, 0) == 0) /* READ_CSD */
&& rcvr_datablock(buff, 16/2))
res = RES_OK;
break;
case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
if ((send_cmd(CMD10, 0) == 0) /* READ_CID */
&& rcvr_datablock(buff, 16/2))
res = RES_OK;
break;
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
for (n = 0, p = buff; n < 4; n++)
*p++ = rcvr_spi();
res = RES_OK;
}
break;