⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 impl.c

📁 老外的一个开源项目
💻 C
字号:
// Copyright (c) David Vescovi.  All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// 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 Gumstix SDIO/MMC driver 
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include "SDCardDDK.h"
#include "bsp.h"

#define CARDDETECT_IRQ_TEXT _T("CardDetectIRQ")
#define CARDDETECT_IST_PRI_TEXT _T("CardDetectISTPriority")
#define DEFAULT_CARD_DETECT_IST_PRIORITY 101

volatile GPIO_REG_T  *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;				// 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 GPIO_Base = {PXA255_BASE_REG_PA_GPIO};
    ASSERT( g_pGPIORegs == NULL );
	g_pGPIORegs = (GPIO_REG_T *)MmMapIoSpace( GPIO_Base, sizeof(GPIO_REG_T), FALSE );
	if ( !g_pGPIORegs )
	{
        return FALSE;
	}

    return TRUE;
}

void UnInitializeHardware()
{
	if ( g_pGPIORegs )
	{
		MmUnmapIoSpace((PVOID)g_pGPIORegs, sizeof(GPIO_REG_T));
		g_pGPIORegs = NULL;
	}
}

BOOL IsCardWriteProtected()
{
	return FALSE;
}

BOOL IsCardPresent()
{
	return TRUE;
}

void MMCPowerControl( BOOL fPowerOn )
{
}

///////////////////////////////////////////////////////////////////////////////
//  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("SDControllerIstThread: warning, failed to set CEThreadPriority \n")));
    }

    while(TRUE)
    {
        waitStatus = WaitForSingleObject( hCardInsertInterruptEvent, dwTimeout );

        if (WAIT_OBJECT_0 != waitStatus) {
            DbgPrintZo(SDCARD_ZONE_WARN, (TEXT("SDCardDetectIstThread: Wait Failed! 0x%08X \n"), waitStatus));
            // bail out
            return 0;
        }

        if( DriverShutdown(pContext) ) {
            DbgPrintZo(SDCARD_ZONE_WARN, (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 )
{
    if( IsCardPresent() )
    {
        ProcessCardInsertion(pHardwareContext);
    }
    else 
    {
        ProcessCardRemoval(pHardwareContext);
    }

    return TRUE;
}


void CleanupCardDetectIST()
{

}


/*
BOOL  SetupCardDetectIST( void *pHardwareContext )
{
    DWORD threadID;                         // thread ID

	if ( !KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwSDCDIrq, sizeof(UINT32), &dwSysintrCD, sizeof(UINT32), NULL)) {
		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;
    }
}
*/

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;
    }

    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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -