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

📄 platspecific.c

📁 wince 5.0下SDIO驱动
💻 C
字号:
/*++
Copyright (c) 2005  BSQUARE Corporation.  All rights reserved.

Module Name:

    platspecific.c

Module Description:

    This file contains platform specific functions for the SD driver.

Author:

    Ian Rae 3-Feb-2005

Notes:

Revision History:

--*/

#include "sdcardddk.h"
#include "sdhcd.h"
#include "sdio.h"
#include <gpio.h>


// Db1200 has just the one slot
int SDIOPlatNumSlots()
{
	return 1;
}


// card insertion interrupts
// mapping BCSR etc
SD_API_STATUS SDIOPlatInit(PSDIO_HW_CONTEXT pController)
{
    SD_API_STATUS    status = SD_API_STATUS_SUCCESS;
    PHYSICAL_ADDRESS PhysAddr;
	HANDLE           hGPIO;

	PhysAddr.HighPart = 0;
	PhysAddr.LowPart = BCSR_PHYSADDR;

	pController->pPlatSpecificPtr = MmMapIoSpace(PhysAddr,
	                                             sizeof(BCSR),
												 FALSE);

	if (NULL==pController->pPlatSpecificPtr) {
		DbgPrintZo(SDCARD_ZONE_ERROR,(TEXT("SDIOPlatInit - failed to map BCSR\n")));
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
		goto ErrorReturn;
	}
	

	hGPIO = GPIO_Init();

    if(hGPIO==INVALID_HANDLE_VALUE) {
        DbgPrintZo(SDCARD_ZONE_ERROR,(L"SDIOPlatInit -  Can not open GPIO device\r\n"));
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
		goto ErrorReturn;
    }

       // connect slot 0 insertion interrupt
    pController->Slots[0].InsertionSysIntr = InterruptConnect(Internal,
                                                              0,
                                                              (HWINTR_EXT_SD0INSERT << 8) | HWINTR_EXT_SD0EJECT,
                                                              0);

    if (SYSINTR_NOP==pController->Slots[0].InsertionSysIntr) {
        DbgPrintZo(SDCARD_ZONE_ERROR,(TEXT("InterruptConnect returned SYSINTR_NOP\r\n")));
        status = SD_API_STATUS_INSUFFICIENT_RESOURCES;
		goto ErrorReturn;
    }

	// Set Pinfunc for SD0
	GPIO_SetPinFunction(hGPIO,SYS_PINFUNC_S0A|SYS_PINFUNC_S0B);
	GPIO_ClearPinFunction(hGPIO,SYS_PINFUNC_S0C);

ErrorReturn:
	if (hGPIO) {
		CloseHandle(hGPIO);
	}

	return status;
}

// un-mapping BCSR etc
SD_API_STATUS SDIOPlatDeinit(PSDIO_HW_CONTEXT pController)
{
    SD_API_STATUS status = SD_API_STATUS_SUCCESS;

	if (NULL!=pController->pPlatSpecificPtr) {
		MmUnmapIoSpace(pController->pPlatSpecificPtr,sizeof(BCSR));
		pController->pPlatSpecificPtr = NULL;
	}

	return status;
}

SD_API_STATUS SDIOPlatPower(PSDIO_HW_CONTEXT pController, BOOL PowerOn, ULONG Slot)
{
	USHORT tmp;
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr;

	tmp = READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->specific);

	if (PowerOn) {
		tmp |= BCSR_SPECIFIC_SD0PWR;
	} else {
		tmp &= ~BCSR_SPECIFIC_SD0PWR;
	}

	WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->specific,tmp);

	return SD_API_STATUS_SUCCESS;
}

BOOL SDIOPlatCardWriteProteced(PSDIO_HW_CONTEXT pController, ULONG Slot)
{
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr;

	if (BCSR_STATUS_SD0WP & READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->status)) {
		return TRUE;
	} else {
		return FALSE;
	}
}

BOOL SDIOPlatCardInserted(PSDIO_HW_CONTEXT pController, ULONG Slot)
{
	pBCSR pDb1200BCSR = pController->pPlatSpecificPtr;

	if (BCSR_BIC_SD0INSERT & READ_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->sigstatus)) {
		// Disable insertion interrupt, enable ejection interrupt
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intclrenable,BCSR_BIC_SD0INSERT);
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intsetenable,BCSR_BIC_SD0EJECT);
		return TRUE;
	} else {
		// Disable ejection interrupt, enable insertion interrupt
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intsetenable,BCSR_BIC_SD0INSERT);
		WRITE_REGISTER_USHORT((PUSHORT)&pDb1200BCSR->intclrenable,BCSR_BIC_SD0EJECT);
		return FALSE;
	}
}

⌨️ 快捷键说明

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