【原创】WinCE下流驱动开发流程

硬件平台:S5PV210

软件平台:WinCE6.0

已IICBUS为例,实现流驱动框架,供以后参考使用

1、创建文件

  IICBUS.cpp

  IICBUS.DEF

  makefile

  sources

2、IICBUS.DEF文件导出函数接口

EXPORTS IBS_Init
    IBS_Deinit
    IBS_Open
    IBS_Close
    IBS_Read
    IBS_Write
    IBS_Seek
    IBS_IOControl
    IBS_PowerDown
    IBS_PowerUp

 3、source文件

TARGETNAME=IICBUS
TARGETTYPE=DYNLINK
RELEASETYPE=PLATFORM
DLLENTRY = DllEntry
DEFFILE = IICBUS.DEF


TARGETLIBS=$(_COMMONSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib

INCLUDES=$(INCLUDES); \
        
SOURCES= \
	iicbus.cpp	\

4、 IICBUS.cpp文件

BOOL WINAPI DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
	switch ( dwReason ) 
	{
	case DLL_PROCESS_ATTACH:
		RETAILMSG(TRUE,(TEXT("******************[+IICBUS DLL_PROCESS_ATTACH]**************\r\n"))); 
		break;
	case DLL_PROCESS_DETACH:
		RETAILMSG(TRUE,(TEXT("******************[-IICBUS DLL_PROCESS_DETACH]**************\r\n"))); 
		break;
	}
	return TRUE;
}

 DWORD IBS_Init(DWORD dwContext)
{
	RETAILMSG(TRUE,(TEXT("[+IICBUS_Init: %s]\r\n"), (LPCTSTR)dwContext)); 

	RETAILMSG(TRUE,(TEXT("[-IICBUS_Init]\r\n")));

	return TRUE;
}

BOOL IBS_Deinit(DWORD dwContext)
{
	RETAILMSG(TRUE, (TEXT("[+IICBUS_Deinit]\r\n"))); 	
	
		
	RETAILMSG(TRUE,(TEXT("[-VSP_Deinit]\r\n")));
	return TRUE;
}

BOOL IBS_Open( DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{	
	RETAILMSG(TRUE,(TEXT("[+IICBUS_Open]\r\n"))); 
	  
	RETAILMSG(TRUE,(TEXT("[-IICBUS_Open]\r\n")));
	
	return TRUE;
}


BOOL IBS_Close(DWORD dwHandle)
{
                RETAILMSG(TRUE,(TEXT("[+IICBUS_Close]\r\n")));

	
	RETAILMSG(TRUE,(TEXT("[-IICBUS_Close]\r\n")));

	return TRUE;
}


BOOL IBS_IOControl(
				   DWORD dwHandle,
				   DWORD dwIoControlCode,
				   PBYTE pBufIn,
				   DWORD dwBufInSize,
				   PBYTE pBufOut,
				   DWORD dwBufOutSize,
				   PDWORD pBytesReturned
				   )
{ 
	switch(dwIoControlCode)
	{
                 。。。。。
              。。。。。
	}

	return TRUE;
}


DWORD IBS_Read(DWORD dwHandle, LPVOID pBuffer, DWORD dwNumBytes)
{
	RETAILMSG(TRUE,(TEXT("[+IICBUS_Read]\r\n")));

	RETAILMSG(TRUE,(TEXT("[-IICBUS_Read]\r\n")));
	
	return 0;
}

DWORD IBS_Write(DWORD dwHandle, LPCVOID pBuffer, DWORD dwNumBytes)
{
	RETAILMSG(TRUE,(TEXT("[+IICBUS_Write]\r\n")));

	RETAILMSG(TRUE,(TEXT("[-IICBUS_Write]\r\n")));
	return 0;
}


DWORD IBS_Seek(DWORD dwHandle, long lDistance, DWORD dwMoveMethod)
{
	return FALSE;
}

void IBS_PowerUp(void)
{
	return;
}

void IBS_PowerDown(void)
{
	return;
}

 4、修改platform.bib文件

IF BSP_NOIICBUS !
IICBUS.dll			$(_FLATRELEASEDIR)\IICBUS.dll           NK SHK  
ENDIF BSP_NOIICBUS !

 5、修改platform.reg文件

IF BSP_NOIICBUS !
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\IICBUS]
	"DLL" = "IICBUS.DLL"
	"Prefix" = "IBS"
	"Index" = dword:1
	"Order" = dword:0
ENDIF BSP_NOIICBUS !

注意:Prefix不能超过3个字符!而且必须跟驱动文件里的前缀一致!

 以上完成流驱动的架构,具体的实现功能可以根据需求来做。

6、应用程序调用

	HANDLE hIICBUS;

	hIICBUS = CreateFile(_T("IBS1:"),
						GENERIC_READ|GENERIC_WRITE,
						FILE_SHARE_READ|FILE_SHARE_WRITE,
						NULL,
						OPEN_EXISTING,
						0,
						0);

	if (INVALID_HANDLE_VALUE == hIICBUS)
	{
		MessageBox(_T("打开IICBUS:失败!"));
		return;
	}

	if(!DeviceIoControl(hIICBUS,
					CHANGE_CH1, 
					NULL, 0, 
					NULL, 0,
					NULL, NULL))
	{
		MessageBox(_T("CH1切换失败!"));
		return;
	}

	CloseHandle(hIICBUS);

 

 

 

posted @ 2012-04-10 17:21  风雨雪夜  阅读(293)  评论(0编辑  收藏  举报