📄 sdiocontrollerbase.cpp
字号:
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;
if( !InitializeHardware() )
{
DEBUGMSG (1,(TEXT("InitializeHardware failed!\n\r")));
status = SD_API_STATUS_UNSUCCESSFUL;
goto INIT_ERROR;
}
INIT_ERROR:
if( hBusHandle )
{
CloseBusAccessHandle( hBusHandle );
}
if(!SD_API_SUCCESS(status))
{
Deinitialize();
}
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDInitialize ends")));
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()
{
PSD_BUS_REQUEST pRequest = NULL; // the request to complete
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDDeinitialize starts")));
//----- 1. Set the controller state to "shutdown" -----
m_bDriverShutdown = TRUE;
//----- 2. Disable and cleanup the ISTs/events ------
if(NULL != m_hResponseReceivedEvent)
{
SetEvent(m_hResponseReceivedEvent);
}
if(NULL != m_hDMAInterruptEvent)
{
SetEvent(m_hDMAInterruptEvent);
}
if(NULL != m_hSDIOInterruptEvent)
{
SetEvent(m_hSDIOInterruptEvent);
}
if(NULL != m_hCardInsertInterruptEvent)
{
SetEvent(m_hCardInsertInterruptEvent);
}
if(NULL != m_hSDIOInterruptThread)
{
WaitForSingleObject(m_hSDIOInterruptThread, INFINITE);
CloseHandle(m_hSDIOInterruptThread);
m_hSDIOInterruptThread = NULL;
}
if(NULL != m_hDMAInterruptThread)
{
WaitForSingleObject(m_hDMAInterruptThread, INFINITE);
CloseHandle(m_hDMAInterruptThread);
m_hDMAInterruptThread = NULL;
}
if(NULL != m_hCardInsertInterruptThread)
{
WaitForSingleObject(m_hCardInsertInterruptThread, INFINITE);
CloseHandle(m_hCardInsertInterruptThread);
m_hCardInsertInterruptThread = NULL;
}
if(NULL != m_hResponseReceivedEvent)
{
CloseHandle(m_hResponseReceivedEvent);
m_hResponseReceivedEvent = NULL;
}
if(NULL != m_hDMAInterruptEvent)
{
CloseHandle(m_hDMAInterruptEvent);
m_hDMAInterruptEvent = NULL;
}
if(NULL != m_hSDIOInterruptEvent)
{
CloseHandle(m_hSDIOInterruptEvent);
m_hSDIOInterruptEvent = NULL;
}
if(NULL != m_hCardInsertInterruptEvent)
{
CloseHandle(m_hCardInsertInterruptEvent);
m_hCardInsertInterruptEvent = NULL;
}
if( m_dwSDIOSysIntr != SYSINTR_UNDEFINED )
{
InterruptDisable (m_dwSDIOSysIntr);
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &m_dwSDIOSysIntr, sizeof(DWORD), NULL, 0, NULL);
m_dwSDIOSysIntr = SYSINTR_UNDEFINED;
}
if( m_dwDMASysIntr != SYSINTR_UNDEFINED )
{
InterruptDisable (m_dwDMASysIntr);
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &m_dwDMASysIntr, sizeof(DWORD), NULL, 0, NULL);
m_dwDMASysIntr = SYSINTR_UNDEFINED;
}
// if there is a pending request, cancel it
if( m_pHCContext && (pRequest = SDHCDGetAndLockCurrentRequest(m_pHCContext, 0)) != NULL)
{
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHCD:SDHControllerIstThread() - aborting current request!\r\n")));
SDHCDIndicateBusRequestComplete(m_pHCContext, pRequest, SD_API_STATUS_SHUT_DOWN);
}
// If a card is inserted, unload the driver...
if(m_pHCContext && m_bDevicePresent == TRUE)
{
m_fCardInTheSlot = FALSE;
// indicate the slot change
SDHCDIndicateSlotStateChange(m_pHCContext, 0, DeviceEjected);
m_bDevicePresent = FALSE;
}
//----- 3. Free the DMA memory -----
if( m_pDMABuffer != NULL )
{
HalFreeCommonBuffer( NULL, 0, m_pDMABufferPhys, m_pDMABuffer, FALSE );
m_pDMABuffer = NULL;
}
//----- 4. stop the hardware -----
if( vm_pSDIReg )
{
Stop_SDI_Clock();
}
if( vm_pCLKPWR )
{
MMC_Hardware_PowerDown();
}
//----- 5. release memory -----
if( vm_pSDIReg )
{
MmUnmapIoSpace( (PVOID)vm_pSDIReg, sizeof(S3C2410X_SDI_REG) );
vm_pSDIReg = NULL;
}
if( vm_pIOPreg )
{
MmUnmapIoSpace( (PVOID)vm_pIOPreg, sizeof(S3C2410X_IOPORT_REG) );
vm_pIOPreg = NULL;
}
if( vm_pCLKPWR )
{
MmUnmapIoSpace( (PVOID)vm_pCLKPWR, sizeof(S3C2410X_CLKPWR_REG) );
vm_pCLKPWR = NULL;
}
if( vm_pDMAreg )
{
MmUnmapIoSpace( (PVOID)vm_pDMAreg, sizeof(S3C2410X_DMA_REG) );
vm_pDMAreg = NULL;
}
if( m_fInitialized )
{
DeleteCriticalSection(&m_ControllerCriticalSection);
m_fInitialized = FALSE;
}
DEBUGMSG (SDCARD_ZONE_INIT,(TEXT("SDHCDDeinitialize ends")));
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")));
//--- 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")));
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")));
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")));
// Nothing to do because this system only operates at the reported 3.3V
break;
case SDHCDSetSlotInterface:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDSetSlotInterface")));
// 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")));
Enable_SDIO_Interrupts();
break;
case SDHCDDisableSDIOInterrupts:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDDisableSDIOInterrupts")));
Disable_SDIO_Interrupts();
break;
case SDHCDAckSDIOInterrupt:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDAckSDIOInterrupt")));
//----- 2. Clear the SDIO interrupt pending bit -----
Ack_SDIO_Interrupts();
InterruptDone(m_dwSDIOSysIntr);
break;
case SDHCDGetWriteProtectStatus:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDGetWriteProtectStatus")));
((PSD_CARD_INTERFACE)pData)->WriteProtected = IsCardWriteProtected();
break;
case SDHCDQueryBlockCapability:
DEBUGMSG (SDCARD_ZONE_INFO,(TEXT("SDHCDSlotOptionHandler option=SDHCDQueryBlockCapability")));
pBlockCaps = (PSD_HOST_BLOCK_CAPABILITY)pData;
DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SDHCD:SDHCDSlotOptionHandler() - Read Block Length: %d , Read Blocks: %d\n"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -