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

📄 cfc_pap.c

📁 ARM9基于WINDOWSCE的BSP源代码
💻 C
字号:
/***************************************************************************
*   File:    cfc_pap.c  -   Plug and Play
* 
*   The content of this file or document is CONFIDENTIAL and PROPRIETARY
*   to Jade Technologies Co., Ltd.  It is subject to the terms of a
*   License Agreement between Licensee and Jade Technologies Co., Ltd.
*   restricting among other things, the use, reproduction, distribution
*   and transfer.  Each of the embodiments, including this information 
*   and any derivative work shall retain this copyright notice.
* 
*   Copyright (c) 2005 Jade Technologies Co., Ltd. 
*   All rights reserved.
****************************************************************************/
#include "cfcard.h"

//------------------------------------------------------------------------------
// Global Variables in CF_PAP.C
//------------------------------------------------------------------------------
extern HANDLE cfIntrEvent;
extern HANDLE cfDataEvent;
extern HANDLE cfIdleEvent;

//------------------------------------------------------------------------------
//
// When insert detected, inform OS that the current device is a block device. 
//
//------------------------------------------------------------------------------
void CFC_DetectInsert(void)
{
	GUID uid = { 0xA4E7EDDA, 0xE575, 0x4252, 
		{0x9D, 0x6B, 0x41, 0x95,0xD4,0x8B,0xB8,0x65 } };
	RETAILMSG(MSG_PAP, (_T("CFCARD: +DetectInsert\r\n")));
	AdvertiseInterface( &uid, L"CFC1:", TRUE);
	RETAILMSG(MSG_PAP, (_T("CFCARD: -DetectInsert\r\n")));
}

//------------------------------------------------------------------------------
//
// When remove detected, inform OS that the current device is not 
//		a block device. That's the way to close the opened distance. 
//
//------------------------------------------------------------------------------
void CFC_DetectRemove(void)
{
	GUID uid = { 0xA4E7EDDA, 0xE575, 0x4252, 
		{0x9D, 0x6B, 0x41, 0x95,0xD4,0x8B,0xB8,0x65 } };
	RETAILMSG(MSG_PAP, (_T("CFCARD: +DetectRemove\r\n")));
	AdvertiseInterface( &uid, L"CFC1:", FALSE);
	RETAILMSG(MSG_PAP, (_T("CFCARD: -DetectRemove\r\n")));
}

//------------------------------------------------------------------------------
//
// This is a IST. In the thread, we wait the CF Card's sys-interrupt.
//		If the interrupt is triggered by TxPopOver, RxPopOver, TxfifoHfReq, 
//		RxfifoHfReq, we set an event to inform the main thread so that in 
//		main thread, it can do the followed work. See also CFC_DATA.C
//		If the interrupt is triggered by CfInsert or CfRemove, call corresponded
//		function above. 
//
// Arguments:
//		pDk - the opened instance
//
//------------------------------------------------------------------------------
unsigned long WINAPI CFC_WaitIntr(void * pDk)
{
	PDISK pDisk = (PDISK)pDk;
	int value, temp;
	OEM_IOCTL_GPIO gpio;
	int ifin = 0;
	int dither = 0;
	SetProcPermissions(0xFFFFFFFF);		// set permission to access other parts
	RETAILMSG(MSG_PAP, (_T("CFCARD: +IST\r\n")));

	// both edges triggered interrupt
	gpio.num = 2;	gpio.pin = 1;	gpio.code = GPIO_IntType;
	value = 0x06;	gpio.value = &value;
	KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
	gpio.num = 2;	gpio.pin = 2;	gpio.code = GPIO_IntType;
	value = 0x06;	gpio.value = &value;
	KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );

	// enable the interrupt at the beginning
	gpio.num = 2;	gpio.pin = 1;	gpio.code = GPIO_IntEnable;
	value = 1;		gpio.value = &value;
	KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
	gpio.num = 2;	gpio.pin = 2;	gpio.code = GPIO_IntEnable;
	value = 1;		gpio.value = &value;
	KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );


	while(1)
	{
		if (pDisk->d_pCFCardRegs->CF_ADDR_CFINTR & CF_DATA_INTR_MASK)
		{
			SetEvent(cfDataEvent);		// data transfer occured interrupt
//			RETAILMSG(1, (_T("CFCARD: IST - data interrupt: 0x%x\r\n"), pDisk->d_pCFCardRegs->CF_ADDR_CFINTR));
			goto CWI_IDLE;
		}

		Sleep(1);
		if (ifin)
		{
			gpio.num = 2;	gpio.pin = 1;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp = value>>1;
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin1:%d when in\r\n"), value));
			gpio.num = 2;	gpio.pin = 2;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp &= value>>2;	// only two pins all 1, it can be 1
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin2:%d when in\r\n"), value));
			if (temp)	//temp ==0 mean card in. else mean out.
			{
				RETAILMSG(1, (_T("CFCARD: IST - card remove detected\r\n")));
				CFC_DetectRemove();
				ifin = 0;
				dither = 0;
				WaitForSingleObject(cfIdleEvent, 10000);	// wait for card uninstall from FAT
			}
			else
			{
				RETAILMSG(1, (_T("CFCARD: IST - card still in socket\r\n")));
				dither++;
				if (dither > 5)
					goto CWI_DEAD;
			}
		}
		else
		{
			gpio.num = 2;	gpio.pin = 1;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp = value>>1;
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin1:%d when out\r\n"), value));
			gpio.num = 2;	gpio.pin = 2;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp |= value>>2;	// only two pins all 0, it can be 0
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin2:%d when out\r\n"), value));

			if (!temp)
			{
				RETAILMSG(1, (_T("CFCARD: IST - card insert detected\r\n")));
				CFC_DetectInsert();
				ifin = 1;
				dither = 0;
				WaitForSingleObject(cfIdleEvent, 10000);	// wait for card install in FAT
			}
			else
			{
				RETAILMSG(1, (_T("CFCARD: IST - card still out of socket\r\n")));
				dither++;
				if (dither > 5)
					goto CWI_DEAD;
			}
		}
		

		gpio.num = 2;	gpio.pin = 1;	gpio.code = GPIO_IntEnable;
		value = 1;		gpio.value = &value;
		KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
		gpio.num = 2;	gpio.pin = 2;	gpio.code = GPIO_IntEnable;
		value = 1;		gpio.value = &value;
		KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );

		InterruptDone(SYSINTR_CF);

		RETAILMSG(MSG_PAP, (_T("CFCARD: IST - wait for next intr\r\n")));
CWI_IDLE:
		WaitForSingleObject(cfIntrEvent, INFINITE);
		RETAILMSG(MSG_PAP, (_T("CFCARD: IST - wait an intr\r\n")));
//		WaitForSingleObject(cfIntrEvent, 1000);
	}
CWI_DEAD:
	CFC_DetectRemove();
	RETAILMSG(1, (_T("CFCARD: IST - card dead\r\n")));
	InterruptDone(SYSINTR_CF);

	RETAILMSG(MSG_PAP, (_T("CFCARD: -IST\r\n")));
	return 1;
}

⌨️ 快捷键说明

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