|
我的那个程序只是专门为SD Memory做的,也就是加载SDMemory_Class
原程序定义是这样的WCHAR *szRegKey_SDMMC = L"Drivers\\SDCARD\\ClientDrivers\\Class\\SDMemory_Class";
而加载SDIO的驱动是我一相情愿的
我只是不知道这个是否能行得通
那么是不是如果原本驱动的意图并不是兼容SD Memory 和SDIO Card就可以不判断了
而我想用SDIO只需修改WCHAR *szRegKey_SDMMC = L"Drivers\\SDCARD\\ClientDrivers\\Class\\SDMemory_Class";
为WCHAR *szRegKey_SDMMC = L"Drivers\\SDCARD\\ClientDrivers\\Class\\SDSC";
完整的SD驱动源程序如下:
// 全局变量
HANDLE hSDEvent;
void InitializeHardware(void);
HANDLE gSDMMCDetectThread; /* 检测线程句柄 */
HANDLE gSDMMCIntrEvent; /* 中断事件 */
HANDLE hDevice = NULL;
static BOOL SDMMC_DETECT = 0; /* 卡原来是否已经插入,*/
UINT32 g_CardInsertIrq = IRQ_EINT18; /* 使用EINT18作为卡插入与否检测线 */
UINT32 g_CardInsertSysIntr = SYSINTR_UNDEFINED;
static volatile S3C2410X_IOPORT_REG * v_pIOPregs;
/*******************************************************************************************
函数名称: SDMMCLoader_InitializeAddresses
描 述: 获取 GPIO 寄存器的虚拟空间
static BOOL SDMMCLoader_InitializeAddresses(VOID)
{
BOOL RetValue = TRUE;
RETAILMSG(1, (TEXT("::: SDMMCLoader Initialize address..set..\r\n")));
/* IO Register Allocation */
v_pIOPregs = (volatile S3C2410X_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2410X_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPregs == NULL)
{
ERRORMSG(1,(TEXT("For IOPregs : VirtualAlloc failed!\r\n")));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(S3C2410X_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2410X_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
ERRORMSG(1,(TEXT("For IOPregs: VirtualCopy failed!\r\n")));
RetValue = FALSE;
}
}
if (!RetValue)
{
RETAILMSG (1, (TEXT("::: PBT_InitializeAddresses - Fail!!\r\n") ));
if (v_pIOPregs)
{
VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE);
}
v_pIOPregs = NULL;
}
else
RETAILMSG (1, (TEXT("::: SDMMCLoader_InitializeAddresses - Success\r\n") ));
return(RetValue);
}
/*******************************************************************************************
函数名称: InitializeHardware
描 述: 初始化硬件: 设置 GP10 为 EINT18, 并且中断为双边沿触发
void InitializeHardware(void)
{
v_pIOPregs->GPGCON &= ~(0x03 << 20);
v_pIOPregs->GPGCON |= (0x02 << 20); /* GPG10 is Interrupt Pin (EINT18) */
v_pIOPregs->GPGUP &= ~(1<<10); /* enable pull up */
v_pIOPregs->EXTINT2 &= ~(0x7 << 8); /* Configure EINT18 as Falling Edge Mode */
v_pIOPregs->EXTINT2 |= (0x6 << 8);
}
/*******************************************************************************************
函数名称: SDMMCDetectThread
描 述: 卡是否插入检测线程
输入参数: LPVOID pArgument: 线程输入参数
WCHAR *szRegKey_SDMMC = L"Drivers\\SDCARD\\ClientDrivers\\Class\\SDMemory_Class";
static DWORD WINAPI SDMMCDetectThread(LPVOID pArgument)
{
RETAILMSG(1, (TEXT("Entering SDMMCDetectThread done.\r\n")));
Sleep (1000); // Same as CF driver, wait for 1 sencond to avoid data abort.
while(1)
{
Sleep(20);
if (((v_pIOPregs->GPGDAT & (0x01 << 10)) != 0) && (SDMMC_DETECT == 1))
{
RETAILMSG(1, (TEXT("INFO: SD/MMC Card is removed.\r\n")));
SDMMC_DETECT = 0;
DeactivateDevice(hDevice); /* 卸载SD/MMC卡驱动 */
InterruptDone(g_CardInsertSysIntr); /* 中断结束 */
}
if ((SDMMC_DETECT == 0) && ((v_pIOPregs->GPGDAT & (0x01 << 10)) == 0))
{
RETAILMSG(1, (TEXT("INFO: SD/MMC Card is detected.\r\n")));
SDMMC_DETECT = 1;
hDevice = ActivateDeviceEx(szRegKey_SDMMC, NULL, 0, NULL); /* 加载SD/MMC卡驱动 */
InterruptDone(g_CardInsertSysIntr);
}
else
{
InterruptDone(g_CardInsertSysIntr);
}
WaitForSingleObject(hSDEvent, INFINITE); /* 等待卡的下一次插入/拨出事件 */
}
return 1;
}
/*******************************************************************************************
函数名称: DllEntry
描 述: 驱动程序动态库入口
BOOL WINAPI DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
switch ( dwReason )
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1, (TEXT("SDMMCLoader: DLL_PROCESS_ATTACH\r\n")));
DisableThreadLibraryCalls((HMODULE) hInstDll);
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1, (TEXT("SDMMCLoader: DLL_PROCESS_DETACH\r\n")));
break;
}
return (TRUE);
}
/*******************************************************************************************
函数名称: IIC_Init
描 述: 驱动程序初始化函数
输入参数: DWORD dwContext: 设备管理器传递给本驱动的参数, 通常为流接口驱动在注册表内的位置
DWORD SML_Init(DWORD dwContext)
{
// 申请硬件寄存器虚拟空间
SDMMCLoader_InitializeAddresses();
// 初始化硬件
InitializeHardware();
// 创建卡插入事件
hSDEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(!hSDEvent)
{
RETAILMSG( 1, (TEXT("SML_Init: CreateEvent hSDEvent failed, error = %x\r\n"), GetLastError()));
return FALSE;
}
// 向 OAL 层申请硬件中断对应的逻辑中断
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_CardInsertIrq, sizeof(UINT32), &g_CardInsertSysIntr, sizeof(UINT32), NULL))
{
RETAILMSG(1, (TEXT("ERROR: SDMMCLoader: Failed to request sysintr value for SDMMC Card Detect interrupt.\r\n")));
return(0);
}
RETAILMSG(1,(TEXT("INFO: SDMMCLoader: Mapped Irq 0x%x to SysIntr 0x%x.\r\n"), g_CardInsertIrq, g_CardInsertSysIntr));
// 绑定卡插入逻辑中断到对应的事件
InterruptDone(g_CardInsertSysIntr);
InterruptDisable(g_CardInsertSysIntr);
if (!(InterruptInitialize(g_CardInsertSysIntr, hSDEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: SDMMCLoader: Interrupt initialize failed.\r\n")));
return FALSE;
}
// 创建卡插入检测线程
gSDMMCDetectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SDMMCDetectThread, NULL, 0, NULL);
if (gSDMMCDetectThread == NULL )
{
RETAILMSG(1, (TEXT("Fatal Error! Failed to create MMC card detect thread.\r\n")));
return (FALSE);
}
RETAILMSG(1, (TEXT(":::SML_Init Sucessfully.\r\n")));
return TRUE;
}
DWORD SML_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
return 1;
}
BOOL SML_Close(DWORD Handle)
{
return (TRUE);
}
DWORD SML_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
return (0);
}
DWORD SML_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
return (0);
}
DWORD SML_Seek(DWORD Handle, long lDistance, DWORD dwMoveMethod)
{
return (DWORD)-1;
}
VOID SML_PowerUp(VOID)
{
return;
}
BOOL SML_PowerDown(VOID)
{
RETAILMSG (1, (TEXT("SMLoader Power down end...\r\n")));
return (TRUE);
}
BOOL SML_Deinit(DWORD dwData)
{
return (TRUE);
}
BOOL
SML_IOControl(
DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned
)
{
return (FALSE);
}
|
|