WINCE6.0下RIL中多路虚拟串口的实现解读

http://blog.csdn.net/ymzhou117/article/details/5401786

710MUX多路复用驱动程序Mux07_10.dll把一路实际的物理串口虚拟成两路串口。

1。一路虚拟串口是COM7-----用于一般的AT 命令发送
2。一路虚拟串口是COM9-----用于ppp connection over CSD / GPRS


看对应的注册表项就可以清楚,下面的内容来自C:/WINCE600/PLATFORM/DEVICEEMULATOR/FILES/platform.reg文件


 [HKEY_LOCAL_MACHINE/Drivers/BuiltIn/RIL]
            "Dll"="rilgsm.dll"
            ;DEVFLAGS_LOADLIBRARY    0x00000002      // Use LoadLibrary instead of LoadDriver
            "Flags"=dword:2
            "Index"=dword:1
            "Order"=dword:3
            "Prefix"="RIL"                
            "ComPort"="COM7:"
            "RebootOKEvName"="Mux0710_RebootOK"    ; name of the event used to signal reboot OK
            "RebootKOEvName"="Mux0710_RebootKO"    ; name of the event used to signal reboot failure
            
        [HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_1]
            "Prefix"="COM"
            "Dll"="Mux07_10.dll"
            "DeviceArrayIndex"=dword:1
            "Index"=dword:7
            "Order"=dword:2
            ; power manager enabled device driver
            "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"
            ; GSM 07.10 specific
            "GSM_0710_DLCI"=dword:1   ; Rem: Dlci also define priority (lowest is low prio)
            "GSM_0710_TYPE"=dword:1   ; boolean: 1 (true) is for AT cmd, 0 (false) is for Data

        ; COM9 for ppp connection over CSD / GPRS                    
        [HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_2]
            "Prefix"="COM"
            "Dll"="Mux07_10.dll"
            "DeviceArrayIndex"=dword:1
            "Index"=dword:9
            "Order"=dword:3
            ; power manager enabled device driver
            "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"
            ; GSM 07.10 specific
            "GSM_0710_DLCI"=dword:2    ; Rem: Dlci also define priority (lowest is low prio)
            "GSM_0710_TYPE"=dword:1    ; boolean: 1 (true) is for AT cmd, 0 (false) is for Data

        ; COM1 for underlying GSM 07.10
        [HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]
            "ComPort"="COM1:"
            "BaudRate"=dword:1C200    ; 115200
            "FrameOption"=dword:1     ; Advanced


再看Mux07_10.dll驱动程序对应的注册表项,下面的内容来自C:/WINCE600/PUBLIC/CELLCORE/710MUX/mux07_10.reg


; COM7 for RIL AT command
; ----------------------------------------
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/RIL]
    "ComPort"="COM7:"
 "RebootOKEvName"="Mux0710_RebootOK"  ; name of the event used to signal reboot OK
 "RebootKOEvName"="Mux0710_RebootKO"  ; name of the event used to signal reboot failure
 
 ;Init string: $VSELECT=1|%DATA=2,"UART",0,2,"SER","UART",0,1| => handset for voice,redirect PPP data from DLCI 1 to DLCI 2
 "ComInitString"=hex:/
 24,00,56,00,53,00,45,00,4c,00,45,00,43,00,54,00,3d,00,31,00,7c,00,/
 25,00,44,00,41,00,54,00,41,00,3d,00,32,00,2c,00,22,00,55,00,41,00,52,00,54,00,22,/
 00,2c,00,30,00,2c,00,32,00,2c,00,22,00,53,00,45,00,52,00,22,00,2c,00,22,00,55,00,/
    41,00,52,00,54,00,22,00,2c,00,30,00,2c,00,31,00,7c,00,00,00
  
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_1]
    "Prefix"="COM"
    "Dll"="Mux07_10.dll"
    "DeviceArrayIndex"=dword:1
    "Index"=dword:7
    "Order"=dword:2

 ; power manager enabled device driver
 ;-------------------------------------
 "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"

 ; GSM 07.10 specific
 ;---------------------
 "GSM_0710_DLCI"=dword:1  ; Rem: Dlci also define priority (lowest => low prio)
 "GSM_0710_TYPE"=dword:1  ; boolean: 1 (true) => AT cmd, 0 (false) => Data

 ; monitor channel activity
 ;---------------------------
 "GSM_0710_ACTIVITY_TIMEOUT"=dword:2710  ; time-out on channel activity in ms
            ;
            ; remark:
            ; the Mux driver will notify the device
            ; when this time-out expire 
            ; if there is no activity

; COM9 for ppp connection over CSD / GPRS
; ----------------------------------------
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_2]
    "Prefix"="COM"
    "Dll"="Mux07_10.dll"
    "DeviceArrayIndex"=dword:1
    "Index"=dword:9
    "Order"=dword:3

 ; power manager enabled device driver
 ;-------------------------------------
 "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"

 ; GSM 07.10 specific
 ;---------------------
 "GSM_0710_DLCI"=dword:2  ; Rem: Dlci also define priority (lowest => low prio)
 "GSM_0710_TYPE"=dword:1  ; boolean: 1 (true) => AT cmd, 0 (false) => Data

 ; monitor channel activity
 ;---------------------------
 "GSM_0710_ACTIVITY_TIMEOUT"=dword:4E20  ; time-out on channel activity in ms
            ;
            ; remark:
            ; the Mux driver will notify the device
            ; when this time-out expire 
            ; if there is no activity

; COM2 for underlying GSM 07.10 
[HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]
    "ComPort"="COM2:"
    "BaudRate"=dword:1C200    ; 115200
    "FrameOption"=dword:1               ; 1 - Advanced; 0 -Basic
    "FrameSize"=dword:00000040          ; max data size

//##########################################################################################################

从上面的内容可以看出Mux07_10.dll被加载2次,虚拟出两个虚拟串口,COM7+COM9,COM7用于一般的AT命令,COM9用于ppp connection over CSD / GPRS。

但上面的两个文件的对应用到的物理串口不一样,这个是要特别注意的地方。

 ; COM1 for underlying GSM 07.10
        [HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]------platform.reg文件
            "ComPort"="COM1:"
            "BaudRate"=dword:1C200    ; 115200
            "FrameOption"=dword:1     ; Advanced

//----------------------------------------------------------------------------

; COM2 for underlying GSM 07.10 
[HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]-------------mux07_10.reg
    "ComPort"="COM2:"
    "BaudRate"=dword:1C200    ; 115200
    "FrameOption"=dword:1               ; 1 - Advanced; 0 -Basic
    "FrameSize"=dword:00000040          ; max data size


注册表的统一,估计要用到编译的时候,相同的注册表项会覆盖的功能!!!-----注意底层实际的物理串口只能有一个。

看到物理串口要虚拟出两个物理串口,所以Mux07_10.dll驱动必须先于rilgsm.dll被加载,因为rilgsm.dll要用虚拟出的COM7来进行AT命令发送。
看系统编译后的reginit.ini文件就应该可以清楚最后的注册表情况,对于[HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]注册表项是谁覆盖了谁。


rilgsm.dll驱动程序的形成

1。先看C:/WINCE600/PLATFORM/DEVICEEMULATOR/FILES/platform.bib文件


; @CESYSGEN IF CELLCORE_MODULES_RIL
IF IMGNOTPCLOW !
IF IMGNORILTSP !
IF IMGFAKERIL
    fakeril.dll                 $(_FLATRELEASEDIR)/fakeril.dll              NK SHK
IF IMGFAKERILNETWORK
    fakeril_intermediate.dll    $(_FLATRELEASEDIR)/fakeril_intermediate.dll               NK  SHK
ENDIF ; IMGFAKERILNETWORK
ELSE
IF IMGTTPCOM
    rilgsm.dll          $(_FLATRELEASEDIR)/rilttpcom.dll        NK SHK
    ttpmux.dll          $(_FLATRELEASEDIR)/ttpmux.dll           NK SHK
IF IMGTTPCOM_TTPGENIE
    ttpgenie.dll        $(_FLATRELEASEDIR)/ttpgenie.dll         NK SHK
ENDIF ; IMGTTPCOM_TTPGENIE
ELSE

IF IMGENFORA
    rilgsm.dll          $(_FLATRELEASEDIR)/rilenfora.dll          NK  SHK
ENDIF IMGENFORA

ENDIF ; IMGTTPCOM
ENDIF ; IMGFAKERIL
ENDIF ; IMGNORILTSP !
ENDIF ; IMGNOTPCLOW !
; @CESYSGEN ENDIF CELLCORE_MODULES_RIL

其中有两个地方----针对不同的环境变量,对应把那个厂家的MODEMN驱动包成rilgsm.dll进NK

 rilgsm.dll          $(_FLATRELEASEDIR)/rilttpcom.dll        NK SHK

 rilgsm.dll          $(_FLATRELEASEDIR)/rilenfora.dll          NK  SHK


2。再看rilenfora.dll的形成过程

    AAAA-----下面的内容来自C:/WINCE600/PLATFORM/DEVICEEMULATOR/SRC/DRIVERS/RILPDD/ENFORA/下的SOURCES文件


TARGETNAME=rilenfora

!include $(_PUBLICROOT)/cellcore/ril/driver/mdd/sources_common.inc----------用到的WINCE里面的文件
!include $(_PUBLICROOT)/cellcore/ril/driver/mdd/sources_dll.inc----------用到的WINCE里面的文件

CDEFINES=$(CDEFINES) -DALPHA_IN_CPI

SOURCES=enfora.cpp


   BBBB------(_PUBLICROOT)/cellcore/ril/driver/mdd/sources_common.inc文件内容--------无实际作用,不引用

   CCCC-----(_PUBLICROOT)/cellcore/ril/driver/mdd/sources_dll.inc文件内容

!IF "$(IMGNOOSSVCSRIL)" == "1"
SKIPBUILD=1
!ENDIF

!IF "$(BSP_RILGSM_MSFT)" == "1"
SKIPBUILD=1
!ENDIF

!IF "$(BSP_NORILGSM)" == "1"
SKIPBUILD=1
!ENDIF

RELEASETYPE=PLATFORM
TARGETTYPE=DYNLINK
DEFFILE=$(_PUBLICROOT)/cellcore/ril/driver/mdd/rilgsm.def
DLLENTRY=_DllMainCRTStartup

SOURCELIBS=$(_PUBLICROOT)/cellcore/oak/lib/$(_CPUINDPATH)/rilmdd.lib

TARGETLIBS= $(TARGETLIBS) /
    $(_PROJECTROOT)/cesysgen/sdk/lib/$(_CPUINDPATH)/coredll.lib /
    $(_PUBLICROOT)/cellcore/oak/lib/$(_CPUINDPATH)/cellcore.lib /
    $(_PUBLICROOT)/cellcore/oak/lib/$(_CPUINDPATH)/ccoreutl.lib /
    $(_PUBLICROOT)/cellcore/oak/lib/$(_CPUINDPATH)/toolbox.lib


//-----------
通过上面的文件内容可见,PDD+MDD层合成一个合法的产生一个DLL的SOURCES文件----PDD层指定DLL的名称,MDD层指定DLL要用的rilgsm.def文件和要连接到的LIB库文件
这里的LIB文件就是MDD层的代码对应编译出来的,所以rilgsm.dll是一个MDD+PDD层代码合到一块的产物。

存在的几个疑问


1。Mux07_10.dll++++rilgsm.dll这两个驱动程序加载的先后次序

    rilgsm.dll要用到Mux07_10.dll虚拟出来的两路串口中的一个,那么Mux07_10.dll应该在rilgsm.dll之前被加载,但看注册表项没看出这个先后次序。


2。RIL Proxy是RIL的一个代理,所有高层的API都是跟这个打交道的。那TAPI/SMS/SIM这些高层的API是怎么跟RIL Proxy这个代理层打交道的?

    TAPI.DLL++++SMSDRV.DLL++++SIMDRV.DLL这些驱动的流程是怎么样的,还没细看。

3。RIL Proxy把来自高层的API命令一个个转换成RIL---XXX( )命令,每个RIL---XXX( )命令对应RIL_IOControl函数里面的一个分支

举例如下----RIL_Dial()命令对应RILDrv_Dial, RILDrv----XXX( )系列命令是真正的最底层实现功能的函数。

      // RIL_Dial()
            case IOCTL_RIL_DIAL:
                if ( BufInDuplicate.ptr() && sizeof(DIAL_PARAMS) == BufInDuplicate.size())
                {
                    LPDIAL_PARAMS pDP = (LPDIAL_PARAMS)BufInDuplicate.ptr();
                    pDP->szAddress[ARRAY_LENGTH(pDP->szAddress)-1] = 0;
                }
                CALLDRVAPI_PARAMS(DIAL_PARAMS, RILDrv_Dial(dwOpenData, pParams->szAddress, pParams->dwType, /
                                                                        pParams->dwOptions));
                break;


RIL---XXX( )命令是RIL Proxy代理层对底层RIL的一个简单封装,不建议直接所有RIL Proxy代理层命令去调RIL的底层命令。一般使用TAPI/SMS/SIM这些高层的API。
当然简单的对RIL进行测试也是可以直接去调RIL---XXX( )命令的。RIL Proxy代理层被引用的次数是没有限制的,但要用到一个ril.lib文件,但WINCE60下的ril.lib文件不能直接使用。
直接在APP里面去调RIL---XXX( )命令相当于自己的APP空间里面有了一个RIL Proxy代理层的实体存在。
RIL层只有一个,因为底层的串口只有一路,RIL Proxy代理层应该有无数个,TAPI/SMS/SIM这些高层的API的驱动程序里面都应该有一个RIL Proxy代理层的实体存在,但还没看出这个玄机所在。

//------------------下面的OPEN代码应该可以说明这样的问题,每次都pHandle = new CRilInstanceHandle这样的对象,并把其加到列表中pDevice->AddToList(pHandle),函数返回pHandle对象


//
// Open a driver instance
//
#ifdef __cplusplus
extern "C" DWORD RIL_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
#else
DWORD RIL_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
#endif
{
    FUNCTION_TRACE(RIL_Open);
    DEBUGCHK(dwData != 0);

    CRilInstanceHandle* pHandle = NULL;
    CRilHandle* pDevice = RILHANDLE_FROM_DRIVERCOOKIE(dwData);
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (!g_pDeviceAllowDriverRemovalTesting)
    {
        return 0x4321;
    }
#endif
    DWORD dwRet = 0;

    // Wait until the COM port is initialized
    if (!pDevice /* || !pDevice->WaitForInit(MAX_DRIVERINIT_TIME) */ )
    {
        goto Error;
    }

    pHandle = new CRilInstanceHandle;
    if (!pHandle || !pHandle->Init(pDevice))
    {
        goto Error;
    }

    // Insert new handle into the handle list
    if (!pDevice->AddToList(pHandle))
    {
        goto Error;
    }

    dwRet = (DWORD)pHandle;

    Error:
    if (!dwRet)
    {
        delete pHandle;
    }
    return dwRet;
}


4。RIL Proxy Log用于调试的日志文件产生,但不知道怎么使用,关于RIL的调试手段还不清楚。

 5。Mux07_10.dll是怎么形成的,看其SOURCES文件只是形成一个LIB文件啊!

   Mux07_10.dll是一个虚拟串口的驱动能不能直接用到一般的场合-----也就是简单的把一个物理串口虚拟成2-3个虚拟串口,不去跟RIL挂接。
   还是必须用到GSM07.10这样的协议才能实现虚拟串口的功能.

  setup710.txt这个文件里面的说明主要是起什么作用的?还真没看太明白!!!


Mux07_10.dll的形成

1。C:/WINCE600/PUBLIC/CELLCORE/710MUX下的SOURCES文件内容


TARGETNAME=Mux07_10

DEFFILE=ser_intf.def
RELEASETYPE=OAK
TARGETTYPE=LIBRARY

TARGETDEFNAME=Mux07_10
WINCETARGETFILE0=$(_RELEASELIBDIR)/$(TARGETDEFNAME).def

WINCEOEM=1

!IFDEF GSM0710_LOG_MSG 
CDEFINES=$(CDEFINES) -DGSM0710_LOG_MSG -DGSM0710_ERR_MSG
!ENDIF

!IFDEF GSM0710_ERR_MSG
CDEFINES=$(CDEFINES) -DGSM0710_ERR_MSG
!ENDIF

SOURCES= /
 chanel.cpp  /
 dispatcher.cpp /
 ser_intf.cpp /
 hw_related.cpp

//--------这里是形成一个LIB文件,但同时提到了WINCETARGETFILE0=$(_RELEASELIBDIR)/$(TARGETDEFNAME).def


2。C:/WINCE600/PUBLIC/CELLCORE/OAK/LIB/ARMV4I/RETAIL目录下Mux07_10.def文件内容

LIBRARY MUX07_10.DLL

EXPORTS COM_Init
 COM_Deinit
 COM_Open
 COM_Close
 COM_Read
 COM_Write
 COM_Seek
 COM_PowerDown
 COM_PowerUp
 COM_IOControl


//----------这样应该就形成了Mux07_10.dll文件

3。CellCore的各个组件怎么加进NK的---------C:/WINCE600/PUBLIC/CELLCORE/OAK/FILES下的cellcore.bib文件说明了

举例mux07_10.dll怎么进NK的

; @CESYSGEN IF CELLCORE_MODULES_MUX07_10
IF IMGNORILTSP !
IF IMGENFORA
   mux07_10.dll      $(_FLATRELEASEDIR)/mux07_10.dll                   NK  SHK
ELSE
IF IMG710MUX
   mux07_10.dll      $(_FLATRELEASEDIR)/mux07_10.dll                   NK  SHK
ENDIF ; IMG710MUX
ENDIF ; IMGENFORA
ENDIF ; IMGNORILTSP !
; @CESYSGEN ENDIF

你可能感兴趣的:(WINCE6.0下RIL中多路虚拟串口的实现解读)