📄 sdiocontrollerbase.cpp
字号:
this, 0, &threadID);
if(NULL == m_hSDIOInterruptThread)
{
status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
goto INIT_ERROR;
}
//----- 11. Setup the interrupt event for handling SDIO DMA data transfers -----
m_hDMAInterruptEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
if(NULL == m_hDMAInterruptEvent)
{
status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
goto INIT_ERROR;
}
// initialize the dma transfer interrupt event
if(!InterruptInitialize (m_dwDMASysIntr, m_hDMAInterruptEvent,
NULL, 0))
{
status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
goto INIT_ERROR;
}
m_hDMAInterruptThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)SD_TransferIstThread,
this, 0, &threadID);
if(NULL == m_hDMAInterruptThread)
{
status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
goto INIT_ERROR;
}
m_dwLastTypeOfTransfer = SD_READ;
m_bUseDMAForTransfer = FALSE;
m_bUseDMABurst = FALSE;
m_DATATransferSize = 1;
if( !InitializeHardware() )
{
DEBUGMSG (1,(TEXT("InitializeHardware failed!\n\r")));
status = SD_API_STATUS_UNSUCCESSFUL;
goto INIT_ERROR;
}
INIT_ERROR:
if(!SD_API_SUCCESS(status))
{
Deinitialize();
}
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDInitialize ends\r\n")));
return status;
}
///////////////////////////////////////////////////////////////////////////////
// CSDIOControllerBase::DeInitialize - Deinitialize the the SDIO Controller
// Input: pHCContext - Host controller context
//
// Output:
// Return: SD_API_STATUS code
// Notes:
//
//
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDIOControllerBase::Deinitialize()
{
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDDeinitialize starts\r\n")));
//----- 1. Set the controller state to "shutdown" -----
m_bDriverShutdown = TRUE;
//----- 2. Disable and cleanup the ISTs/events ------
InterruptDisable (m_dwSDIOSysIntr);
SetEvent(m_hResponseReceivedEvent);
InterruptDisable (m_dwDMASysIntr);
if(NULL != m_hResponseReceivedEvent)
{
CloseHandle(m_hResponseReceivedEvent);
m_hResponseReceivedEvent = NULL;
}
if(NULL != m_hSDIOInterruptThread)
{
WaitForSingleObject(m_hSDIOInterruptThread, INFINITE);
CloseHandle(m_hSDIOInterruptThread);
m_hSDIOInterruptThread = NULL;
}
if(NULL != m_hSDIOInterruptEvent)
{
CloseHandle(m_hSDIOInterruptEvent);
m_hSDIOInterruptEvent = NULL;
}
if(NULL != m_hDMAInterruptThread)
{
WaitForSingleObject(m_hDMAInterruptThread, INFINITE);
CloseHandle(m_hDMAInterruptThread);
m_hDMAInterruptThread = NULL;
}
if(NULL != m_hDMAInterruptEvent)
{
CloseHandle(m_hDMAInterruptEvent);
m_hDMAInterruptEvent = NULL;
}
if(NULL != m_hCardInsertInterruptThread)
{
WaitForSingleObject(m_hCardInsertInterruptThread, INFINITE);
CloseHandle(m_hCardInsertInterruptThread);
m_hCardInsertInterruptThread = NULL;
}
if(NULL != m_hCardInsertInterruptEvent)
{
CloseHandle(m_hCardInsertInterruptEvent);
m_hCardInsertInterruptEvent = NULL;
}
if( m_dwDMAChannel != 0xffffffff )
{
//----- 3. Free the DMA memory -----
HalFreeCommonBuffer( NULL, 0, m_pDMABufferPhys, m_pDMABuffer, FALSE );
}
//----- 4. Close the handle to the utility driver (used for fast driver-->driver calling -----
MMC_Hardware_PowerDown();
DeleteCriticalSection(&m_ControllerCriticalSection);
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDDeinitialize ends\r\n")));
return SD_API_STATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
// CSDIOControllerBase::CancelIoHandler - io cancel handler
// Input: pHostContext - host controller context
// Slot - slot the request is going on
// pRequest - the request to be cancelled
//
// Output:
// Return: TRUE if the request was cancelled
// Notes:
//
//
///////////////////////////////////////////////////////////////////////////////
BOOLEAN CSDIOControllerBase::CancelIoHandler(DWORD dwSlot, PSD_BUS_REQUEST pRequest)
{
DEBUGMSG (SDCARD_ZONE_FUNC,(TEXT("SDHCDCancelIoHandler starts\r\n")));
//--- Stop hardware, cancel the request!
Stop_SDI_Hardware();
// release the lock before we complete the request
SDHCDReleaseHCLock(m_pHCContext);
// complete the request with a cancelled status
SDHCDIndicateBusRequestComplete(m_pHCContext, pRequest,SD_API_STATUS_CANCELED);
DEBUGMSG (SDCARD_ZONE_FUNC,(TEXT("SDHCDCancelIoHandler ends\r\n")));
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// CSDIOControllerBase::SlotOptionHandler - handler for slot option changes
// Input: SlotNumber - the slot the change is being applied to
// Option - the option code
// pData - data associated with the option
// OptionSize - size of option data
// Output:
// Return: SD_API_STATUS code
// Notes:
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDIOControllerBase::SlotOptionHandler(DWORD dwSlot, SD_SLOT_OPTION_CODE Option,
PVOID pData, ULONG OptionSize)
{
DEBUGMSG (SDCARD_ZONE_FUNC,(TEXT("SDHCDSlotOptionHandler starts\r\n")));
SD_API_STATUS status = SD_API_STATUS_SUCCESS; // status
PSD_HOST_BLOCK_CAPABILITY pBlockCaps; // block capabilities
switch(Option)
{
case SDHCDSetSlotPower:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDSetSlotPower\r\n")));
// Nothing to do because this system only operates at the reported 3.3V
break;
case SDHCDSetSlotInterface:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDSetSlotInterface\r\n")));
// First set the bus width
if(((PSD_CARD_INTERFACE)pData)->InterfaceMode == SD_INTERFACE_SD_4BIT)
{
Set_SDI_Bus_Width_4Bit();
}else
{
// Standard (i.e. 1bit) bus width
Set_SDI_Bus_Width_1Bit();
}
// Next, set the clock rate
((PSD_CARD_INTERFACE)pData)->ClockRate = SetClockRate(((PSD_CARD_INTERFACE)pData)->ClockRate);
break;
case SDHCDEnableSDIOInterrupts:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDEnableSDIOInterrupts\r\n")));
Enable_SDIO_Interrupts();
break;
case SDHCDDisableSDIOInterrupts:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDDisableSDIOInterrupts\r\n")));
Disable_SDIO_Interrupts();
break;
case SDHCDAckSDIOInterrupt:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDAckSDIOInterrupt\r\n")));
//----- 2. Clear the SDIO interrupt pending bit -----
Ack_SDIO_Interrupts();
InterruptDone(m_dwSDIOSysIntr);
break;
case SDHCDGetWriteProtectStatus:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDGetWriteProtectStatus\r\n")));
((PSD_CARD_INTERFACE)pData)->WriteProtected = IsCardWriteProtected();
break;
case SDHCDQueryBlockCapability:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDQueryBlockCapability\r\n")));
pBlockCaps = (PSD_HOST_BLOCK_CAPABILITY)pData;
DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SDHCD:SDHCDSlotOptionHandler() - Read Block Length: %d , Read Blocks: %d\r\n"),
pBlockCaps->ReadBlockSize, pBlockCaps->ReadBlocks));
DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SDHCD:SDHCDSlotOptionHandler() - Write Block Length: %d , Write Blocks: %d\r\n"),
pBlockCaps->WriteBlockSize, pBlockCaps->WriteBlocks));
pBlockCaps = (PSD_HOST_BLOCK_CAPABILITY)pData;
//----- Validate block transfer properties -----
if (pBlockCaps->ReadBlockSize < MINIMUM_BLOCK_TRANSFER_SIZE )
{
pBlockCaps->ReadBlockSize = MINIMUM_BLOCK_TRANSFER_SIZE;
}
if (pBlockCaps->WriteBlockSize < MINIMUM_BLOCK_TRANSFER_SIZE )
{
pBlockCaps->WriteBlockSize = MINIMUM_BLOCK_TRANSFER_SIZE;
}
if (pBlockCaps->ReadBlockSize > MAXIMUM_BLOCK_TRANSFER_SIZE )
{
pBlockCaps->ReadBlockSize = MAXIMUM_BLOCK_TRANSFER_SIZE;
}
if (pBlockCaps->WriteBlockSize > MAXIMUM_BLOCK_TRANSFER_SIZE )
{
pBlockCaps->WriteBlockSize = MAXIMUM_BLOCK_TRANSFER_SIZE;
}
break;
case SDHCDGetSlotInfo:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDGetSlotInfo\r\n")));
if( OptionSize != sizeof(SDCARD_HC_SLOT_INFO) || pData == NULL )
{
status = SD_API_STATUS_INVALID_PARAMETER;
}
else
{
PSDCARD_HC_SLOT_INFO pSlotInfo = (PSDCARD_HC_SLOT_INFO)pData;
// set the slot capabilities
SDHCDSetSlotCapabilities(pSlotInfo, SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK);
SDHCDSetVoltageWindowMask(pSlotInfo, (SD_VDD_WINDOW_3_2_TO_3_3 | SD_VDD_WINDOW_3_3_TO_3_4));
// Set optimal voltage
SDHCDSetDesiredSlotVoltage(pSlotInfo, SD_VDD_WINDOW_3_2_TO_3_3);
SDHCDSetMaxClockRate(pSlotInfo, MAX_SDI_BUS_TRANSFER_SPEED);
// Set power up delay. We handle this in SetVoltage().
SDHCDSetPowerUpDelay(pSlotInfo, 300);
}
break;
default:
DEBUGMSG (SDCARD_ZONE_WARN,(TEXT("SDHCDSlotOptionHandler option=SD_API_STATUS_INVALID_PARAMETER\r\n")));
status = SD_API_STATUS_INVALID_PARAMETER;
}
DEBUGMSG (SDCARD_ZONE_FUNC,(TEXT("SDHCDSlotOptionHandler ends\r\n")));
return status;
}
///////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -