zoukankan      html  css  js  c++  java
  • 【原创】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);
    
  • 相关阅读:
    Linux下Socket编程之地址结构
    矫正Fedora 8中livna源Nvidia驱动托付关连
    Firefox3 RC1颁布各种新特征发扬阐发更平定
    Fedora 8中完全开启compizfusion特效
    编译安置gsopcast SVN版
    Sopcast for linux更新至3.01!
    措置惩罚Fedora 8中的装备权限标题成绩
    vsftp假造用户设置(Ubuntu8.04)
    QQ2008贺岁版 on FedoraBy wine 0.9.58
    vFU NET
  • 原文地址:https://www.cnblogs.com/hao507/p/2440935.html
Copyright © 2011-2022 走看看