?? impl.c.svn-base
字號(hào):
//
// 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.
//
//
// Copyright (c) 2002 BSQUARE Corporation. All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
//
// Module Name:
//
// Impl.c
//
// Abstract:
//
// Driver entry points for Mainstone SDIO driver
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <bulverde.h>
#include <mainstoneii.h>
#include <bsp_cfg.h>
#include <args.h>
#define SDH_CARD_DETECT_PRIORITY 101
volatile BULVERDE_GPIO_REG *g_pGPIORegs=NULL; // GPIO registers
HANDLE hCardInsertInterruptEvent; // card insert/remove interrupt event
HANDLE hCardInsertInterruptThread; // card insert/remove interrupt event
DWORD dwSDCDIrq; // SD/MMC card detect interrupt IRQ value
DWORD dwSysintrCD=SYSINTR_MMCCD; // SD/MMC card detect interrupt SYSINTR value
DWORD dwCardDetectIstThreadPriority; // Card detect IST thread priority
void ProcessCardInsertion(void *pContext);
void ProcessCardRemoval(void *pContext);
BOOL DriverShutdown(void *pContext);
DWORD SDCardDetectIstThread(void *pContext);
BOOL InitializeHardware()
{
PHYSICAL_ADDRESS Bulverde_GPIO_Base = {BULVERDE_BASE_REG_PA_GPIO};
NKDbgPrintfW(TEXT("++ SDHC Init...\r\n"));
g_pGPIORegs = (BULVERDE_GPIO_REG*)MmMapIoSpace( Bulverde_GPIO_Base, sizeof(BULVERDE_GPIO_REG), FALSE );
if ( !g_pGPIORegs )
{
return FALSE;
}
MMC_PWRON_CLEAR;
//MMC_PWRON_SET;
MMC_PWRON_FUNCTION_0_SET;
MMC_PWRON_DIRECTION_OUT_SET;
return TRUE;
}
void UnInitializeHardware()
{
if ( g_pGPIORegs ) {
MmUnmapIoSpace((PVOID)g_pGPIORegs, sizeof(BULVERDE_GPIO_REG));
g_pGPIORegs = NULL;
}
}
BOOL IsCardWriteProtected()
{
return FALSE;
}
BOOL IsCardPresent()
{
if((g_pGPIORegs->GPLR2&(1<<16))==0)
return TRUE;
else
return FALSE;
}
void MMCPowerControl( BOOL fPowerOn )
{
if(fPowerOn){
MMC_PWRON_SET;
}else{
MMC_PWRON_CLEAR;
}
Sleep(300);
}
///////////////////////////////////////////////////////////////////////////////
// SDCardDetectIstThread - IST thread for card detect interrupts
// Input: pContext - pointer to the device context
// Output:
// Return: thread exit code
///////////////////////////////////////////////////////////////////////////////
DWORD SDCardDetectIstThread(void *pContext)
{
DWORD waitStatus;
DWORD dwTimeout = INFINITE;
dwTimeout = INFINITE;
SetEvent( hCardInsertInterruptEvent ); // set it to check for cards already inserted at boot time
if (!CeSetThreadPriority(GetCurrentThread(),
dwCardDetectIstThreadPriority)) {
//DbgPrintZo(SDCARD_ZONE_WARN,
// (TEXT("SDCardDetectIstThread: warning, failed to set CEThreadPriority \n")));
}
while(TRUE)
{
waitStatus = WaitForSingleObject( hCardInsertInterruptEvent, dwTimeout );
if (WAIT_OBJECT_0 != waitStatus) {
return 0;
}
if( DriverShutdown(pContext) ) {
//DbgPrintZo(1, (TEXT("SDCardDetectIstThread: Thread Exiting\n")));
return 0;
}
Sleep( 100 ); // delay to handle bouncing effect on the interrupt line
if( IsCardPresent() )
{
ProcessCardInsertion(pContext);
}
else
{
ProcessCardRemoval(pContext);
}
InterruptDone( dwSysintrCD );
} // while
}
BOOL SetupCardDetectIST( void *pHardwareContext )
{
DWORD threadID; // thread ID
// convert the hardware SD/MMC card detect interrupt IRQ into a logical SYSINTR value
//if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwSDCDIrq, sizeof(DWORD), &(dwSysintrCD), sizeof(DWORD), NULL))
//{
// // invalid SDIO SYSINTR value!
// //DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("Error obtaining SDIO SYSINTR value!\n")));
// dwSysintrCD = SYSINTR_UNDEFINED;
// return FALSE;
//}
// allocate the interrupt event for card insertion
hCardInsertInterruptEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
if (NULL == hCardInsertInterruptEvent) {
return FALSE;
}
// initialize the card insertion interrupt event
if (!InterruptInitialize (dwSysintrCD,
hCardInsertInterruptEvent,
NULL,
0)) {
return FALSE;
}
// create the interrupt thread to handle card insertion events
hCardInsertInterruptThread =
CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)SDCardDetectIstThread,
pHardwareContext,
0,
&threadID);
if (NULL == hCardInsertInterruptThread) {
return FALSE;
}
return TRUE;
}
void CleanupCardDetectIST()
{
InterruptDisable (dwSysintrCD);
// clean up card insertion IST
if (NULL != hCardInsertInterruptThread) {
// wake up the IST
SetEvent(hCardInsertInterruptEvent);
// wait for the thread to exit
WaitForSingleObject(hCardInsertInterruptThread, INFINITE);
CloseHandle(hCardInsertInterruptThread);
hCardInsertInterruptThread = NULL;
}
// free card insertion interrupt
if (NULL != hCardInsertInterruptEvent) {
CloseHandle(hCardInsertInterruptEvent);
hCardInsertInterruptEvent = NULL;
}
}
#define CARDDETECT_IRQ_TEXT _T("CardDetectIRQ")
#define CARDDETECT_IST_PRI_TEXT _T("CardDetectISTPriority")
#define DEFAULT_CARD_DETECT_IST_PRIORITY 101
BOOL LoadPlatformRegistrySettings( HKEY hKeyDevice )
{
DWORD dwRegVal;
DWORD dwDataSize;
DWORD dwType;
dwDataSize = sizeof(DWORD);
if( ERROR_SUCCESS == RegQueryValueEx( hKeyDevice, CARDDETECT_IRQ_TEXT,
NULL, &dwType, (LPBYTE)&dwRegVal, &dwDataSize ) &&
REG_DWORD == dwType )
{
dwSDCDIrq = dwRegVal;
}
else
{
return FALSE;
}
dwDataSize = sizeof(DWORD);
if( ERROR_SUCCESS == RegQueryValueEx( hKeyDevice, CARDDETECT_IST_PRI_TEXT,
NULL, &dwType, (LPBYTE)&dwRegVal, &dwDataSize ) &&
REG_DWORD == dwType )
{
dwCardDetectIstThreadPriority = dwRegVal;
}
else
{
dwCardDetectIstThreadPriority = DEFAULT_CARD_DETECT_IST_PRIORITY;
}
return TRUE;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -