📄 sdhceventhandlers.cpp
字号:
status = SDSynchronousBusRequest__X(hDevice,
Command,
Argument,
TransferClass,
ResponseType,
pResponse,
NumberOfBlocks,
BlockSize,
pBlockBuffer,
#ifdef ENABLE_SDIO_V1_1_SUPPORT
SD_SLOTRESET_REQUEST);
#else
0);
#endif //ENABLE_SDIO_V1_1_SUPPORT
}
}
// restore client flags
pDevice->ClientFlags = clientFlags;
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// UpdateCachedRegisterFromResponse - update the device shadow registers from the
// information in the response buffer
// Input: pDevice - the device who's shadowed register should be updated
// Register - the information to update
// pResponse - the response containing the register data
// Output:
// Return
// Notes:
//
///////////////////////////////////////////////////////////////////////////////
VOID UpdateCachedRegisterFromResponse(PSDCARD_DEVICE_CONTEXT pDevice,
SD_INFO_TYPE Register,
PSD_COMMAND_RESPONSE pResponse)
{
switch (Register) {
case SD_INFO_REGISTER_CID:
memcpy(pDevice->CachedRegisters.CID, pResponse->ResponseBuffer, SD_CID_REGISTER_SIZE);
break;
case SD_INFO_REGISTER_RCA:
// RCA is in bytes 3,4
pDevice->RelativeAddress = (SD_CARD_RCA)pResponse->ResponseBuffer[3];
pDevice->RelativeAddress |= ((SD_CARD_RCA)pResponse->ResponseBuffer[4]) << 8;
break;
case SD_INFO_REGISTER_OCR:
pDevice->CachedRegisters.OCR[3] = pResponse->ResponseBuffer[4];
pDevice->CachedRegisters.OCR[2] = pResponse->ResponseBuffer[3];
pDevice->CachedRegisters.OCR[1] = pResponse->ResponseBuffer[2];
pDevice->CachedRegisters.OCR[0] = pResponse->ResponseBuffer[1];
break;
case SD_INFO_REGISTER_CSD:
memcpy(pDevice->CachedRegisters.CSD, pResponse->ResponseBuffer, SD_CSD_REGISTER_SIZE);
break;
case SD_INFO_REGISTER_IO_OCR:
pDevice->CachedRegisters.IO_OCR[2] = pResponse->ResponseBuffer[3];
pDevice->CachedRegisters.IO_OCR[1] = pResponse->ResponseBuffer[2];
pDevice->CachedRegisters.IO_OCR[0] = pResponse->ResponseBuffer[1];
break;
default:
DEBUGCHK(FALSE);
}
}
///////////////////////////////////////////////////////////////////////////////
// DelayForPowerUp - Delay for powerup
// Input: pSlot - slot to delay on
//
// Output:
// Notes:
//
///////////////////////////////////////////////////////////////////////////////
VOID DelayForPowerUp(PSDBUS_HC_SLOT_CONTEXT pSlot)
{
// delay for power up
if (pSlot->PowerUpDelay != 0) {
Sleep(pSlot->PowerUpDelay);
} else {
// powerup delay should be set
DEBUG_CHECK(FALSE, (TEXT("SDBusDriver: Slot Delay is 0!!!\n")));
Sleep(500);
}
}
///////////////////////////////////////////////////////////////////////////////
// SetCardPower - Set the card power
// Input: DeviceType - the device type
// OperatingVoltageMask - operating voltage mask
// pSlot - the slot
// SetHCPower - flag to indicate whether the power should be set in the HC
// (combo cards do not need to reset power if the I/O portion
// was already powered).
//
// Output:
// Return: SD_API_STATUS code
// Notes:
// This function sets the card power and polls the card until it is
// not busy
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SetCardPower(SDCARD_DEVICE_TYPE DeviceType,
DWORD OperatingVoltageMask,
PSDBUS_HC_SLOT_CONTEXT pSlot,
BOOL SetHCPower,
CReg *pregDevice)
{
SD_API_STATUS status = SD_API_STATUS_SUCCESS; // intermediate status
SD_COMMAND_RESPONSE response; // response
UCHAR command; // command
SD_RESPONSE_TYPE responseType; // response type
ULONG powerUpRetries; // power up retries
BOOL appcmd = FALSE; // command is an app cmd
ULONG powerUpInterval; // powerup interval
ULONG totalPowerUpTime; // total powerup time
ULONG powerUpIntervalByDevice; // powerup interval by device
g_bIsSupportSDHC = FALSE;
switch (DeviceType) {
case Device_MMC:
command = SD_CMD_MMC_SEND_OPCOND;
responseType = ResponseR3;
powerUpIntervalByDevice = DEFAULT_POWER_UP_MMC_POLL_INTERVAL;
break;
case Device_SD_IO:
command = SD_CMD_IO_OP_COND;
responseType = ResponseR4;
powerUpIntervalByDevice = DEFAULT_POWER_UP_SDIO_POLL_INTERVAL;
break;
case Device_SD_Memory:
command = SD_ACMD_SD_SEND_OP_COND;
responseType = ResponseR3;
appcmd = TRUE;
powerUpIntervalByDevice = DEFAULT_POWER_UP_SD_POLL_INTERVAL;
break;
default:
DEBUGCHK(FALSE);
return SD_API_STATUS_INVALID_PARAMETER;
}
// check to see if we need to apply power
if (SetHCPower) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Setting slot %d power to 0x%08X \n"),
pSlot->SlotIndex, OperatingVoltageMask));
// set slot power
status = SDSetSlotPower(pSlot, OperatingVoltageMask);
if (!SD_API_SUCCESS(status)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Host failed to set slot power 0x%08X on slot:%d \n"),
status, pSlot->SlotIndex));
return status;
}
DelayForPowerUp(pSlot);
}
if (Device_SD_IO != DeviceType) {
// put the card into idle again
// CMD0
status = SendSDCommand(pSlot->hDevice,
SD_CMD_GO_IDLE_STATE,
0x00000000,
NoResponse,
NULL);
if (!SD_API_SUCCESS(status)){
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Go Idle Failed during powerup: Status: 0x%08X on slot:%d \n"),status,
pSlot->SlotIndex));
return status;
}
}
#ifdef SD_SPEC_20
/*************************************************************************/
/****** Date : 07.05.04 ******/
/****** Developer : HS.JANG ******/
/****** Description : SD card of Spec2.0 recognizes CMD 8 ******/
/*************************************************************************/
// CMD8
if (Device_SD_Memory == DeviceType) {
status = SendSDCommand(pSlot->hDevice,
SD_CMD_SEND_INTERFACE_CONDITION,
0x000001cc, // It means support 2.7 ~ 3.6 vol and Pattern 0xcc
ResponseR1,
&response);
if (!SD_API_SUCCESS(status)){
RETAILMSG(0,(TEXT("[SDBUS] This SD Card is NOT supporting High Capacity!! (CMD8 not regconized)\r\n")));
// ((PSDCARD_DEVICE_CONTEXT)(pSlot->hDevice))->dwWhatIsCardType = 1;
}
else
{
if ( (response.ResponseBuffer[1]& 0xff) == 0xcc )
{
g_bIsSupportSPEC20 = TRUE;
RETAILMSG(0,(TEXT("This SD Card is supporting High Capacity on %x voltage!! 0x%x 0x%x\r\n"),response.ResponseBuffer[1],pSlot->hDevice,(((PSDCARD_DEVICE_CONTEXT)(pSlot->hDevice))->dwWhatIsCardType)));
}
else
{
RETAILMSG(0,(TEXT("This SD Card is not supporting High Capacity!! 0x%x %x 0x%x\r\n"),(UINT32)response.ResponseBuffer[2],(UINT32)response.ResponseBuffer[1],pSlot->hDevice));
// ((PSDCARD_DEVICE_CONTEXT)(pSlot->hDevice))->dwWhatIsCardType = 1;
}
}
}
/*************************************************************************/
#endif
totalPowerUpTime = pregDevice->ValueDW(POWER_UP_POLL_TIME_KEY,
DEFAULT_POWER_UP_TOTAL_WAIT_TIME);
powerUpInterval = pregDevice->ValueDW(POWER_UP_POLL_TIME_INTERVAL_KEY,
powerUpIntervalByDevice);
powerUpRetries = totalPowerUpTime/powerUpInterval;
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Power Set, checking card in slot %d, MaxRetries: %d, Time: %d MS, Interval: %d MS \n"),
pSlot->SlotIndex, powerUpRetries, totalPowerUpTime , powerUpInterval));
while (powerUpRetries != 0) {
#ifdef SD_SPEC_20
/*************************************************************************/
/****** Date : 07.05.04 ******/
/****** Developer : HS.JANG ******/
/****** Description : Set OCR to support SD high capacity ******/
/*************************************************************************/
if(g_bIsSupportSPEC20)
{
if (appcmd) {
// send it as an APP cmd
status = SendSDAppCommand(pSlot->hDevice,
command,
(1<<30|OperatingVoltageMask), // set enable HC.
responseType,
&response);
} else {
// send the command to get the ready bit
status = SendSDCommand(pSlot->hDevice,
command,
OperatingVoltageMask,
responseType,
&response);
}
}
/*************************************************************************/
#endif
else
{
if (appcmd) {
// send it as an APP cmd
status = SendSDAppCommand(pSlot->hDevice,
command,
OperatingVoltageMask,
responseType,
&response);
} else {
#ifdef __MMC_SPEC_4_2_SUPPORT__
if(Device_MMC == DeviceType)
OperatingVoltageMask |= (1<<30);
#endif
// send the command to get the ready bit
status = SendSDCommand(pSlot->hDevice,
command,
OperatingVoltageMask,
responseType,
&response);
}
}
if (!SD_API_SUCCESS(status)){
break;
}
if (Device_SD_IO == DeviceType) {
// check to see if the I/O is ready
if (SD_IS_IO_READY(&response)) {
// we're done
break;
}
} else {
// check to see if the MMC or Memory card is ready
if (SD_IS_MEM_READY(&response)) {
// card is ready
break;
}
}
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Card in slot %d not ready, countdown: %d \n"),
pSlot->SlotIndex, powerUpRetries));
powerUpRetries--;
// sleep the powerup interval
Sleep(powerUpInterval);
}
if (0 == powerUpRetries) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Device failed to powerup after voltage setting \n")));
status = SD_API_STATUS_DEVICE_NOT_RESPONDING;
}
if (SD_API_SUCCESS(status)) {
DEBUGMSG(SDBUS_ZONE_DEVICE, (TEXT("SDBusDriver: Card in slot %d ready \n"),
pSlot->SlotIndex));
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// GetCardRegisters - Get card registers
// Input: pBaseDevice - the base device
// BaseDeviceType - base device type
// pSlot - the slot
// Output:
// Return: SD_API_STATUS code
// Notes: This function retreives important card registers for the device type
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS GetCardRegisters(PSDCARD_DEVICE_CONTEXT pBaseDevice,
SDCARD_DEVICE_TYPE BaseDeviceType,
PSDBUS_HC_SLOT_CONTEXT pSlot)
{
SD_API_STATUS status; // status
SD_COMMAND_RESPONSE response; // response
UCHAR scrReg[SD_SCR_REGISTER_SIZE]; // temporary buffer
USHORT oidValue; // oid value
SD_CARD_STATUS cardStatus; // card status
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -