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

📄 cfc_pap.c

📁 此压缩包为杰得开发得z228的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_INFO.C
//------------------------------------------------------------------------------
extern HANDLE cfIntrEvent;
extern HANDLE cfDataEvent;
//{{{{{{{{{{{caipeng318@126.com
extern	HANDLE			IdleEvent ;
extern	int					g_ExcCnt ;			// count times open/close error ocurred
extern	int					g_CardStatus;		// indicate the card's state
//}}}}}}}}}}}}caipeng318@126.com

//------------------------------------------------------------------------------
//
// 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")));
}

//{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{caipeng318@126.com
//------------------------------------------------------------------------------
//
// Plug & Play Thread - created when the driver is loaded, and check the status
//		of the card. When the status changed, the routine called the two functions
//		above, to force OS open or close an instance. 
//
// Arguments:
//		controller - handle of the instance passed from the main thread. 
//
//------------------------------------------------------------------------------
unsigned long WINAPI CFC_DetectStatus(void * pDk)
{
	int ifin=0;
	OEM_IOCTL_GPIO gpio;
	unsigned long temp;
	unsigned long value;
	volatile unsigned long sys_addr = 0;
	PHYSICAL_ADDRESS regs;

	//yz_add_for_use_GP0_x
		regs.HighPart = 0;
		regs.LowPart = 0x2002010C;
		sys_addr = ( unsigned long )MmMapIoSpace(regs, 4, FALSE);
		if(!sys_addr)
			RETAILMSG(1, (_T("CFCARD: MmMapIoSpace:sys_addr FAILed!\r\n")));
		
		*(unsigned long *)sys_addr = 0x2000;
	
	while(1)
	{

		if (ifin)
		{

			gpio.num = 0;	gpio.pin = 7;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp = value>>7;
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin7:%d when in\r\n"), value));
			if (temp)	//temp ==0 mean card in. else mean out.
			{
				RETAILMSG(1, (_T("CFCARD: IST - crad remove detected\r\n")));
				CFC_DetectRemove();
				ifin = 0;
			}
			else
			{
				//RETAILMSG(1, (_T("CFCARD: IST - crad still in socket\r\n")));
			}

		}
		else
		{

			gpio.num = 0;	gpio.pin = 7;	gpio.code = GPIO_Read;
			value = 0;		gpio.value = &value;
			KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
			temp = value>>7;
				RETAILMSG(MSG_PAP, (_T("CFCARD: IST - pin7:%d when out\r\n"), value));
			if (!temp)
			{
				RETAILMSG(1, (_T("CFCARD: IST - crad insert detected\r\n")));
				CFC_DetectInsert();
				ifin = 1;
			}
			else
			{
				//RETAILMSG(1, (_T("CFCARD: IST - crad still out of socket\r\n")));
			}

		}
		Sleep(5000);
	}
}


//------------------------------------------------------------------------------
//
// 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;
	SetProcPermissions(0xFFFFFFFF);		// set permission to access other parts


//	RETAILMSG(MSG_PAP, (_T("CFCARD: +CFC_WaitIntr\r\n")));

	while(1)
	{
//		RETAILMSG(1, (_T("CFCARD:  IST - CFC_WaitIntr loop :%d\r\n"),i++));//caipeng318@126.com
		if (pDisk->d_pCFCardRegs->CF_ADDR_CFINTR &
			((1 << CfRawIntr_TxPopOver)
			|(1 << CfRawIntr_RxPopOver)
			|(1 << CfRawIntr_TxfifoHfReq)
			|(1 << CfRawIntr_RxfifoHfReq)))
		{
			SetEvent(cfDataEvent);		// data transfer occured interrupt
 			RETAILMSG(1, (_T("CFCARD: CFC_WaitIntr - data interrupt\r\n")));
			goto CWI_IDLE;
		}


	//clear the system interrupt
		InterruptDone(SYSINTR_CF);
			

CWI_IDLE:
		WaitForSingleObject(cfIntrEvent,INFINITE);
//		WaitForSingleObject(cfIntrEvent,1000);
	}
	RETAILMSG(MSG_PAP, (_T("CFCARD: -IST\r\n")));
	return 1;
}
//}}}}}}}}}}}}}}}}}}}}}caipeng318@126.com

⌨️ 快捷键说明

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