📄 sdhcslot.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// 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.
//
#if (BSP_TYPE == BSP_SMDK2443)
#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.
//
#endif
// Copyright (c) 2002 BSQUARE Corporation. All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
#ifndef _SDHCSLOT_DEFINED
#define _SDHCSLOT_DEFINED
#if (BSP_TYPE == BSP_SMDK2443)
#include "SDCardDDK.h"
#include "SDHCD.h"
#elif (BSP_TYPE == BSP_SMDK2450)
#include <s3c2450.h>
#include "../../../SDDriver_INC/SDCardDDK.h"
#include "../../../SDDriver_INC/SDHCD.h"
#ifdef _SMDK2450_CH1_WP_
#include <bsp.h>
#endif
#endif
#include <ceddk.h>
#include "SDHCRegs.h"
#define SDHC_MAX_POWER_SUPPLY_RAMP_UP 250 // SD Phys Layer 6.6
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
#define NUM_BYTE_FOR_POLLING_MODE 0x800
#endif
#define SDHC_POWER_UP_DELAY_KEY _T("PowerUpDelay")
#define SDHC_WAKEUP_SOURCES_KEY _T("DefaultWakeupSources")
#define SDHC_CAN_WAKE_ON_INT_KEY _T("AllowWakeOnSDIOInterrupts")
#define SDHC_FREQUENCY_KEY _T("BaseClockFrequency")
#define SDHC_TIMEOUT_FREQUENCY_KEY _T("TimeoutClockFrequency")
#define SDHC_TIMEOUT_KEY _T("TimeoutInMS")
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
#define SDHC_POLLINGMODE_SIZE _T("PollingModeSize")
#endif
#ifdef _SMDK2450_CH1_EXTCD_
// The enumeration for factors is used in card detect interrupt handler of HSMMC ch0 on SMDK2450.
typedef enum _SDSLOT_INT_TYPE {
SDSLOT_INT_NULL = 0,
SDSLOT_INT_CARD_DETECTED = 1,
} SDSLOT_INT_TYPE, *PSDSLOT_INT_TYPE;
#endif
typedef class CSDHCSlotBase {
public:
// Constructor - only initializes the member data. True initialization
// occurs in Init().
CSDHCSlotBase();
virtual ~CSDHCSlotBase();
// Perform basic initialization including initializing the hardware
// so that the capabilities register can be read.
virtual BOOL Init(DWORD dwSlot, volatile BYTE *pbRegisters,
PSDCARD_HC_CONTEXT pHCDContext, DWORD dwSysIntr, HANDLE hBusAccess,
INTERFACE_TYPE interfaceType, DWORD dwBusNumber, CReg *pregDevice);
// Second stage of hardware initialization. Complete slot configuration
// and enable interrupts.
virtual SD_API_STATUS Start();
// Signals card removal disables the slot.
virtual SD_API_STATUS Stop();
// Process a slot option call.
virtual SD_API_STATUS SlotOptionHandler(SD_SLOT_OPTION_CODE sdOption,
PVOID pData, DWORD cbData);
// Get this slot's power state.
virtual CEDEVICE_POWER_STATE GetPowerState() { return m_cpsCurrent; }
// What power state is required upon power up?
virtual CEDEVICE_POWER_STATE GetPowerUpRequirement() { return m_cpsAtPowerDown; }
// Called when the device is suspending.
virtual VOID PowerDown();
// Called when the device is resuming.
virtual VOID PowerUp();
// Start this bus request.
virtual SD_API_STATUS BusRequestHandler(PSD_BUS_REQUEST pRequest);
// Returns TRUE if the interrupt routine needs servicing, say at
// initialization to see if a card is present.
virtual BOOL NeedsServicing() { return m_fCheckSlot; }
#ifndef _SMDK2450_CH1_EXTCD_
// Handle a slot interrupt. Also called when NeedsServicing() returns TRUE.
virtual VOID HandleInterrupt();
#else
// Prototype for the new Interrupt handler function can process factors on new card detect interrupt of HSMMC ch0 on SMDK2450.
virtual VOID HandleInterrupt(SDSLOT_INT_TYPE intType = SDSLOT_INT_NULL);
#endif
BOOL IsOnlySDIOInterrupt();
// Called by the controller to get the controller interrupt register.
inline WORD ReadControllerInterrupts() {
return ReadWord(SDHC_NORMAL_INT_STATUS);
}
protected:
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
virtual SD_API_STATUS SubmitBusRequestHandler(PSD_BUS_REQUEST pRequest );
virtual BOOL PollingForCommandComplete();
#endif
// What is this slot's maximum clock rate?
virtual DWORD DetermineMaxClockRate();
// What is this slot's maximum block length?
virtual DWORD DetermineMaxBlockLen();
// What should this slot use for timeout control?
virtual DWORD DetermineTimeoutControl();
// What are the default wakeup sources?
virtual DWORD DetermineWakeupSources();
// Set the slot voltage.
virtual VOID SetVoltage(DWORD dwVddSetting);
// Set the bus width and clock rate.
#if (BSP_TYPE == BSP_SMDK2443)
virtual VOID SetInterface(PSD_CARD_INTERFACE pInterface);
#elif (BSP_TYPE == BSP_SMDK2450)
virtual VOID SetInterface(PSD_CARD_INTERFACE_EX pInterface);
#endif
// Set this slot's power state.
virtual VOID SetPowerState(CEDEVICE_POWER_STATE cpsNew);
// Get the capabilities register.
virtual SSDHC_CAPABILITIES GetCapabilities() {
SSDHC_CAPABILITIES caps;
caps.dw = ReadDword(SDHC_CAPABILITIES);
return caps;
}
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
virtual SSDHC_VERSION GetSDHCVersion() {
SSDHC_VERSION version;
version.uw = ReadWord(SDHC_HOST_CONTROLLER_VER);
return version;
}
#endif
// Fill in the slot info structure.
virtual SD_API_STATUS GetSlotInfo(PSDCARD_HC_SLOT_INFO pSlotInfo);
// Get the desired Vdd window.
virtual DWORD GetDesiredVddWindow();
// Get the max Vdd window.
virtual DWORD GetMaxVddWindow();
// Is the card write-protected?
virtual BOOL IsWriteProtected() {
#if (BSP_TYPE == BSP_SMDK2443)
return ((ReadDword(SDHC_PRESENT_STATE) & STATE_WRITE_PROTECT) == STATE_WRITE_PROTECT);
#elif (BSP_TYPE == BSP_SMDK2450)
#ifdef _SMDK2450_CH1_WP_
// 08.06.04 by KYS
// This routine is used in case of using GPIO pin as WriteProtection.
BOOL bRet = FALSE; // The result on WriteProtection
DWORD dwCount = 5;
volatile S3C2450_IOPORT_REG *pIOPreg = NULL;
pIOPreg = (volatile S3C2450_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2450_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if (pIOPreg == NULL) {
RETAILMSG(1,(TEXT("[HSMMC1] GPIO registers is *NOT* allocated for WriteProtect.\n")));
return FALSE;
}
if (!VirtualCopy((PVOID)pIOPreg, (PVOID)(S3C2450_BASE_REG_PA_IOPORT >> 8),
sizeof(S3C2450_IOPORT_REG), PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE)) {
RETAILMSG(1,(TEXT("[HSMMC1] GPIO registers is *NOT* mapped for WriteProtect.\n")));
return FALSE;
}
while (dwCount) {
bRet = (((pIOPreg->GPJDAT) & (1 << 15)) != 0) ? 1: 0; // Used GPJ15 as Ch1 WriteProtection in case of SMDK2450.
Sleep(1);
dwCount--;
}
VirtualFree((PVOID)pIOPreg, 0, MEM_RELEASE);
if (bRet) RETAILMSG(1, (TEXT("[HSMMC1] Is Write Protected? TRUE\n")));
else RETAILMSG(1, (TEXT("[HSMMC1] Is Write Protected? FALSE\n")));
return bRet;
#else
// 08.02.04 by KYS
// Because the STATE_WRITE_PROTECT bit in SDHC_PRESENT_STATE register is not HIGH, modifying is needed.
//return ((ReadDword(SDHC_PRESENT_STATE) & STATE_WRITE_PROTECT) == 0); // -> Orginal !!
return (FALSE); // Always False.
#endif
#endif
}
// Enable/disable SDIO card interrupts.
virtual VOID EnableSDIOInterrupts(BOOL fEnable);
// How much extra time in ms for initial clocks is needed upon
// insertion of a card for the power supply ramp up?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -