📄 sdhcslot.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#if (BSP_TYPE == BSP_SMDK2443)
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#elif (BSP_TYPE == BSP_SMDK2450)
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
#endif
// Copyright (c) 2002 BSQUARE Corporation. All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
#if (BSP_TYPE == BSP_SMDK2443)
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <s3c2450.h>
#elif (BSP_TYPE == BSP_SMDK2450)
#endif
#include "SDHC.h"
#include "SDHCSlot.h"
#include <bsp.h>
// 08.04.03 by KYS
// Below variable and macro lines are needed for working as a mass storage device
static volatile BSP_ARGS *v_gBspArgs;
#define CARD_INSERTED 1
#define CARD_REMOVED 2
#if (BSP_TYPE == BSP_SMDK2443)
//extern S3C2450_IOPORT_REG *pIOPreg;
#elif (BSP_TYPE == BSP_SMDK2450)
#endif
// Macros
#define DX_D1_OR_D2(cps) ((cps) == D1 || (cps) == D2)
#define SETFNAME() LPCTSTR pszFname = _T(__FUNCTION__) _T(":")
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
//#define _FB_ON_ // for Feedback clock on
#endif
#ifdef DEBUG
// dump the current request info to the debugger
static
VOID
DumpRequest(
PSD_BUS_REQUEST pRequest,
DWORD dwZone
)
{
PREFAST_DEBUGCHK(pRequest);
if (dwZone) {
DEBUGMSG(1, (TEXT("DumpCurrentRequest: 0x%08X\n"), pRequest));
DEBUGMSG(1, (TEXT("\t Command: %d\n"), pRequest->CommandCode));
DEBUGMSG(1, (TEXT("\t Argument: 0x%08x\n"), pRequest->CommandArgument));
DEBUGMSG(1, (TEXT("\t ResponseType: %d\n"), pRequest->CommandResponse.ResponseType));
DEBUGMSG(1, (TEXT("\t NumBlocks: %d\n"), pRequest->NumBlocks));
DEBUGMSG(1, (TEXT("\t BlockSize: %d\n"), pRequest->BlockSize));
DEBUGMSG(1, (TEXT("\t HCParam: %d\n"), pRequest->HCParam));
}
}
#else
#define DumpRequest(ptr, dw)
#endif
CSDHCSlotBase::CSDHCSlotBase(
)
{
m_pregDevice = NULL;
m_dwSlot = 0;
m_pbRegisters = NULL;
m_pHCDContext = NULL;
m_dwSysIntr = 0;
m_hBusAccess = NULL;
m_interfaceType = InterfaceTypeUndefined;
m_dwBusNumber = 0;
m_dwVddWindows = 0;
m_dwMaxClockRate = 0;
m_dwTimeoutControl = 0;
m_dwMaxBlockLen = 0;
m_pbDmaBuffer = NULL;
m_paDmaBuffer = 0;
m_wRegClockControl = 0;
m_wIntSignals = 0;
m_cpsCurrent = D0;
m_cpsAtPowerDown = D0;
m_dwDefaultWakeupControl = 0;
m_bWakeupControl = 0;
#ifdef DEBUG
m_dwReadyInts = 0;
#endif
m_fCommandCompleteOccurred = FALSE;
m_fSleepsWithPower = FALSE;
m_fPowerUpDisabledInts = FALSE;
m_fIsPowerManaged = FALSE;
m_fSDIOInterruptsEnabled = FALSE;
m_fCardPresent = FALSE;
m_fAutoCMD12Success = FALSE;
m_fCheckSlot = TRUE;
m_fCanWakeOnSDIOInterrupts = FALSE;
m_f4BitMode = FALSE;
m_fFakeCardRemoval = FALSE;
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
m_pCurrentRequest = NULL;
m_fCurrentRequestFastPath = FALSE;
m_dwPollingModeSize = NUM_BYTE_FOR_POLLING_MODE ;
#endif
}
CSDHCSlotBase::~CSDHCSlotBase(
)
{
DEBUGCHK(m_pbDmaBuffer == NULL);
}
BOOL
CSDHCSlotBase::Init(
DWORD dwSlot,
volatile BYTE *pbRegisters,
PSDCARD_HC_CONTEXT pHCDContext,
DWORD dwSysIntr,
HANDLE hBusAccess,
INTERFACE_TYPE interfaceType,
DWORD dwBusNumber,
CReg *pregDevice
)
{
BOOL fRet = TRUE;
DEBUGCHK(dwSlot < SDHC_MAX_SLOTS);
DEBUGCHK(pbRegisters);
DEBUGCHK(pHCDContext);
DEBUGCHK(hBusAccess);
PREFAST_DEBUGCHK(pregDevice && pregDevice->IsOK());
m_dwSlot = dwSlot;
m_pbRegisters = pbRegisters;
m_pHCDContext = pHCDContext;
m_dwSysIntr = dwSysIntr;
m_hBusAccess = hBusAccess;
m_interfaceType = interfaceType;
m_dwBusNumber = dwBusNumber;
m_pregDevice = pregDevice;
fRet = SoftwareReset(SOFT_RESET_ALL);
if (fRet) {
Sleep(10); // Allow time for card to power down after a device reset
SSDHC_CAPABILITIES caps = GetCapabilities();
DEBUGMSG(SDCARD_ZONE_INIT && caps.bits.DMA,
(_T("SDHC Will use DMA for slot %u\n"), m_dwSlot));
m_dwVddWindows = DetermineVddWindows();
m_dwMaxClockRate = DetermineMaxClockRate();
m_dwMaxBlockLen = DetermineMaxBlockLen();
m_dwTimeoutControl = DetermineTimeoutControl();
m_dwDefaultWakeupControl = DetermineWakeupSources();
m_fCanWakeOnSDIOInterrupts = m_pregDevice->ValueDW(SDHC_CAN_WAKE_ON_INT_KEY);
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
m_dwPollingModeSize = m_pregDevice->ValueDW(SDHC_POLLINGMODE_SIZE, NUM_BYTE_FOR_POLLING_MODE);
#endif
Validate();
DumpRegisters();
}
// 08.04.03 by KYS
// Below code lines are needed for working as a mass storage device
v_gBspArgs = (volatile BSP_ARGS *)VirtualAlloc(0, sizeof(BSP_ARGS), MEM_RESERVE, PAGE_NOACCESS);
if (!v_gBspArgs) {
RETAILMSG(1, (TEXT("[HSMMC0] Common Argument Area VirtualAlloc failed!\r\n")));
return FALSE;
}
if (!VirtualCopy((PVOID)v_gBspArgs, (PVOID)(IMAGE_SHARE_ARGS_UA_START), sizeof(BSP_ARGS), PAGE_READWRITE | PAGE_NOCACHE )) {
RETAILMSG(1, (TEXT("[HSMMC0] BSP Common Argument Are VirtualCopy failed!\r\n")));
return FALSE;
}
v_gBspArgs->g_SDCardState = CARD_REMOVED;//initialize
v_gBspArgs->g_SDCardDetectEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
return fRet;
}
SD_API_STATUS
CSDHCSlotBase::Start(
)
{
Validate();
SD_API_STATUS status;
if (SoftwareReset(SOFT_RESET_ALL)) {
// timeout control
#if (BSP_TYPE == BSP_SMDK2443)
WriteByte(SDHC_TIMEOUT_CONTROL, (BYTE) m_dwTimeoutControl);
#elif (BSP_TYPE == BSP_SMDK2450)
WriteByte(SDHC_TIMEOUT_CONTROL, (BYTE)0xE);
#endif
// Enable error interrupt status and signals for all but the vendor
// errors. This allows any normal error to generate an interrupt.
WriteWord(SDHC_ERROR_INT_STATUS_ENABLE, ~0 & ~ERR_INT_STATUS_VENDOR);
WriteWord(SDHC_ERROR_INT_SIGNAL_ENABLE, ~0 & ~ERR_INT_STATUS_VENDOR);
// Enable all interrupt signals. During execution, we will enable
// and disable interrupt statuses as desired.
#if (BSP_TYPE == BSP_SMDK2443)
WriteWord(SDHC_NORMAL_INT_SIGNAL_ENABLE, 0xFFFF);
WriteWord(SDHC_NORMAL_INT_STATUS_ENABLE,
NORMAL_INT_ENABLE_CARD_INSERTION | NORMAL_INT_ENABLE_CARD_REMOVAL);
#elif (BSP_TYPE == BSP_SMDK2450)
WriteWord(SDHC_NORMAL_INT_SIGNAL_ENABLE, 0x1F7);
//WriteWord(SDHC_NORMAL_INT_STATUS_ENABLE,
// NORMAL_INT_ENABLE_CARD_INSERTION | NORMAL_INT_ENABLE_CARD_REMOVAL);
WriteWord(SDHC_NORMAL_INT_STATUS_ENABLE, 0x1F7);
#endif
status = SD_API_STATUS_SUCCESS;
}
else {
status = SD_API_STATUS_DEVICE_NOT_RESPONDING;
}
return status;
}
SD_API_STATUS
CSDHCSlotBase::Stop(
)
{
if (m_fCardPresent) {
// Remove device
HandleRemoval(FALSE);
}
SoftwareReset(SOFT_RESET_ALL);
// 08.04.03 by KYS
// Below code lines are needed for working as a mass storage device
if(NULL != v_gBspArgs->g_SDCardDetectEvent)
{
CloseHandle(v_gBspArgs->g_SDCardDetectEvent);
v_gBspArgs->g_SDCardDetectEvent = NULL;
}
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS
CSDHCSlotBase::GetSlotInfo(
PSDCARD_HC_SLOT_INFO pSlotInfo
)
{
PREFAST_DEBUGCHK(pSlotInfo);
DEBUGCHK(m_pregDevice->IsOK());
// set the slot capabilities
#if (BSP_TYPE == BSP_SMDK2443)
#ifdef _MMC_SPEC_42_
/*************************************************************************/
/****** Date : 07.05.14 ******/
/****** Developer : HS.JANG ******/
/****** Description : to support SD SPEC20 card. Response7 is added ******/
/****** for supporting SD SPEC20 card ******/
/*************************************************************************/
SDHCDSetSlotCapabilities(pSlotInfo, SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK |
SD_SLOT_HIGH_SPEED_CAPABLE );
/*************************************************************************/
#else
SDHCDSetSlotCapabilities(pSlotInfo, SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK );
#endif
#elif (BSP_TYPE == BSP_SMDK2450)
DWORD dwCap = SD_SLOT_SD_4BIT_CAPABLE |
SD_SLOT_SD_1BIT_CAPABLE |
//SD_SLOT_SD_8BIT_CAPABLE | // CH0 does not support DAT 8 Bit.
SD_SLOT_SDIO_CAPABLE |
SD_SLOT_SDIO_INT_DETECT_4BIT_MULTI_BLOCK;
if (GetCapabilities().bits.HighSpeed)
dwCap |= SD_SLOT_HIGH_SPEED_CAPABLE;
SDHCDSetSlotCapabilities(pSlotInfo,dwCap );
#endif
SDHCDSetVoltageWindowMask(pSlotInfo, m_dwVddWindows);
// Set optimal voltage
SDHCDSetDesiredSlotVoltage(pSlotInfo, GetDesiredVddWindow());
// Controller may be able to clock at higher than the max SD rate,
// but we should only report the highest rate in the range.
DWORD dwMaxClockRateInSDRange = SD_FULL_SPEED_RATE;
SetClockRate(&dwMaxClockRateInSDRange);
SDHCDSetMaxClockRate(pSlotInfo, dwMaxClockRateInSDRange);
// Set power up delay. We handle this in SetVoltage().
SDHCDSetPowerUpDelay(pSlotInfo, 1);
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS
CSDHCSlotBase::SlotOptionHandler(
SD_SLOT_OPTION_CODE sdOption,
PVOID pData,
DWORD cbData
)
{
SD_API_STATUS status = SD_API_STATUS_SUCCESS;
RETAILMSG(0,(TEXT("CSDHCSlotBase::SlotOptionHandle\nr")));
switch (sdOption) {
case SDHCDSetSlotPower: {
DEBUGCHK(cbData == sizeof(DWORD));
PDWORD pdwVddSetting = (PDWORD) pData;
SetVoltage(*pdwVddSetting);
break;
}
case SDHCDSetSlotInterface: {
DEBUGCHK(cbData == sizeof(SD_CARD_INTERFACE));
PSD_CARD_INTERFACE pInterface = (PSD_CARD_INTERFACE) pData;
DEBUGMSG(SDCARD_ZONE_INFO,
(TEXT("CSDHCSlotBase::SlotOptionHandler: Clock Setting: %d\n"),
pInterface->ClockRate));
#if (BSP_TYPE == BSP_SMDK2443)
SetInterface(pInterface);
#elif (BSP_TYPE == BSP_SMDK2450)
SD_CARD_INTERFACE_EX sdCardInterfaceEx;
memset(&sdCardInterfaceEx,0, sizeof(sdCardInterfaceEx));
sdCardInterfaceEx.InterfaceModeEx.bit.sd4Bit = (pInterface->InterfaceMode == SD_INTERFACE_SD_4BIT? 1: 0);
/* 07.11.20 by KYS for HSMMC8BIT*/
sdCardInterfaceEx.InterfaceModeEx.bit.hsmmc8Bit = (((pInterface->InterfaceMode) == SD_INTERFACE_MMC_8BIT)? 1:0);
sdCardInterfaceEx.ClockRate = pInterface->ClockRate;
sdCardInterfaceEx.InterfaceModeEx.bit.sdWriteProtected = (pInterface->WriteProtected?1:0);
SetInterface(&sdCardInterfaceEx);
// Update the argument back.
if (sdCardInterfaceEx.InterfaceModeEx.bit.hsmmc8Bit != 0) {
pInterface->InterfaceMode = SD_INTERFACE_MMC_8BIT;
} else {
pInterface->InterfaceMode = (sdCardInterfaceEx.InterfaceModeEx.bit.sd4Bit!=0?SD_INTERFACE_SD_4BIT:SD_INTERFACE_SD_MMC_1BIT);
}
pInterface->ClockRate = sdCardInterfaceEx.ClockRate;
pInterface->WriteProtected = (sdCardInterfaceEx.InterfaceModeEx.bit.sdWriteProtected!=0?TRUE:FALSE);
#endif
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -