用的是广嵌的GEC2410,他们提供的串口驱动第二个串口居然不能用
如果要做第二个串口驱动需要怎么改啊?
WINCE5.0增加第二串口
――基于TE2410开发板平台(http://www.witech.com.cn)
需要修改的文件:
\INC\oalintr.h
\KERNEL\HAL\ARM\armint.c
\KERNEL\HAL\cfw.c
\DRIVERS\SERIAL\ser2410_hw.c
\DRIVERS\SERIAL\ser2410_ser.c
\FILES\platform.reg
1,中断源 \INC\oalintr.h
添加:#define SYSINTR_SERIAL1 (SYSINTR_FIRMWARE+23)
修改:
MapIrq2SysIntr(DWORD _Irq)
{
if( _Irq<=23 )
return ( SYSINTR_FIRMWARE + _Irq );
else
return (0xffffffff);
}
2,arminit.c
在else if(IntPendVal == INTSRC_UART0)后添加如下代码:
else if(IntPendVal == INTSRC_UART1)
{
SubIntPendVal = s2410INT->rSUBSRCPND;
if(SubIntPendVal & INTSUB_ERR1)
{
s2410INT->rINTSUBMSK |= INTSUB_ERR1;
}
else if(SubIntPendVal & INTSUB_RXD1)
{
s2410INT->rINTSUBMSK |= INTSUB_RXD1;
}
else if(SubIntPendVal & INTSUB_TXD1)
{
s2410INT->rINTSUBMSK |= INTSUB_TXD1;
}
else
{
return(SYSINTR_NOP);
}
s2410INT->rINTMSK |= BIT_UART1;
if (s2410INT->rINTPND & BIT_UART1) s2410INT->rINTPND = BIT_UART1;
return(SYSINTR_SERIAL1);
}
3,cfw.c
分别在OEMInterruptEnable,OEMInterruptDisable,OEMInterruptDone三个函数中模仿串口0添加串口1的中断处理代码。
4,ser2410_hw.c(修改数据结构以根据注册表中的配置情况进行端口匹配)
分别修改S2410_SetSerialIOP,SL_Init函数如下:
S2410_SetSerialIOP(PVOID pHead) // @parm points to device head
{
PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
PSER_INFO pHWHead1 = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE, (TEXT("S2410_SetSerialIOP \r\n")));
if(pHWHead1->dwIOBase == 0x50004000)
{
EnterCriticalSection(&(pHWHead->RegCritSec));
v_pIOPregs->rGPHCON &= ~(0x3<<8 | 0x3<<10 );
v_pIOPregs->rGPHCON |= (0x2<<8 | 0x2<<10 );
v_pIOPregs->rGPHCON |= (0x2<<0 | 0x2<<2 );
v_pIOPregs->rGPHUP |= 0x03;
pHWHead->rDTRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->rDSRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->DtrPortNum = 0;
pHWHead->DsrPortNum = 1;
}
else if(pHWHead1->dwIOBase == 0x50008000)
{
EnterCriticalSection(&(pHWHead->RegCritSec));
v_pIOPregs->rGPHCON &= ~( 0x3<<12 | 0x3<<14);
v_pIOPregs->rGPHCON |= ( 0x2<<12 | 0x2<<14);
v_pIOPregs->rGPHCON |= (0x2<<0 | 0x2<<2 );
v_pIOPregs->rGPHUP &= ~0xc0;
pHWHead->rDTRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->rDSRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->DtrPortNum = 0;
pHWHead->DsrPortNum = 1;
}
else
{
EnterCriticalSection(&(pHWHead->RegCritSec));
v_pIOPregs->rGPHCON &= ~(0x3<<0 | 0x3<<2 | 0x3<<4 | 0x3<<6);
v_pIOPregs->rGPHCON |= (0x2<<4 | 0x2<<6);
v_pIOPregs->rGPHCON |= (0x2<<0 | 0x2<<2 );
v_pIOPregs->rGPHUP |= 0x03;
pHWHead->rDTRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->rDSRport = (volatile unsigned int *)&(v_pIOPregs->rGPHDAT);
pHWHead->DtrPortNum = 0;
pHWHead->DsrPortNum = 1;
}
LeaveCriticalSection(&(pHWHead->RegCritSec));
}
SL_Init函数中:(修改两处)
if ( pHWHead->UseIrDA )
{
pHWHead->bINT = BIT_UART2;
pHWHead->bTxINT = INTSUB_TXD2;
pHWHead->bRxINT = INTSUB_RXD2;
pHWHead->bErrINT = INTSUB_ERR2;
pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART2regs;
pRegBase = (PUCHAR)pHWHead->s2410SerReg;
}
else
{
if(pHWHead1->dwIOBase == 0x50004000)
{
pHWHead->bINT = BIT_UART1;
pHWHead->bTxINT = INTSUB_TXD1;
pHWHead->bRxINT = INTSUB_RXD1;
pHWHead->bErrINT = INTSUB_ERR1;
pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART1regs;
pRegBase = (PUCHAR)pHWHead->s2410SerReg;
}
else if(pHWHead1->dwIOBase == 0x50008000)
{
pHWHead->bINT = BIT_UART2;
pHWHead->bTxINT = INTSUB_TXD2;
pHWHead->bRxINT = INTSUB_RXD2;
pHWHead->bErrINT = INTSUB_ERR2;
pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART2regs;
pRegBase = (PUCHAR)pHWHead->s2410SerReg;
}
else
{
pHWHead->bINT = BIT_UART0;
pHWHead->bTxINT = INTSUB_TXD0;
pHWHead->bRxINT = INTSUB_RXD0;
pHWHead->bErrINT = INTSUB_ERR0;
pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART0regs;
pRegBase = (PUCHAR)pHWHead->s2410SerReg;
}
}
if ( pHWHead->UseIrDA )
{
pHWHead->pUFTXH = (volatile unsigned char *)&(v_pUART2regs->rUTXH);
pHWHead->pUFRXH = (volatile unsigned char *)&(v_pUART2regs->rURXH);
}
else
{
if(pHWHead1->dwIOBase == 0x50004000)
{
pHWHead->pUFTXH = (volatile unsigned char *)&(v_pUART1regs->rUTXH);
pHWHead->pUFRXH = (volatile unsigned char *)&(v_pUART1regs->rURXH);
}
else if(pHWHead1->dwIOBase == 0x50008000)
{
pHWHead->pUFTXH = (volatile unsigned char *)&(v_pUART2regs->rUTXH);
pHWHead->pUFRXH = (volatile unsigned char *)&(v_pUART2regs->rURXH);
}
else
{
pHWHead->pUFTXH = (volatile unsigned char *)&(v_pUART0regs->rUTXH);
pHWHead->pUFRXH = (volatile unsigned char *)&(v_pUART0regs->rURXH);
}
}
5,ser2410_ser.c
在const HWOBJ IoObj{……}后面添加:
const HWOBJ IoObj1 = {
THREAD_AT_INIT,
SYSINTR_SERIAL1,
(PHW_VTBL) &IoVTbl
};
修改:
const PCHWOBJ HWObjects[] = {
&IoObj,
&IoObj1,
&IrObj
};
修改:
PHWOBJ GetSerialObject(DWORD DeviceArrayIndex)
{
PHWOBJ pSerObj;
RETAILMSG(DEBUGMODE,(TEXT("IRDA : GetSerialObject\r\n")));
IRDA = DeviceArrayIndex;
if ( DeviceArrayIndex == 0 )
pSerObj = (PHWOBJ)(&IoObj);
else if( DeviceArrayIndex == 1 )
pSerObj = (PHWOBJ)(&IoObj1);
else
pSerObj = (PHWOBJ)(&IrObj);
return (pSerObj);
}
6,注册表\FILES\platform.reg
在串口0后添加:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410_1]
"DeviceArrayIndex"=dword:1
"Irq"=dword:17
"IoBase"=dword:50004000
"IoLen"=dword:2C
"Prefix"="COM"
"Dll"="SER2410.Dll"
"Order"=dword:2
"Priority"=dword:0
"Port"="COM2:"
"DeviceType"=dword:0 ; null modem
"FriendlyName"="S2410 COM2"
; "Index"=dword:2
"IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410_1\Unimodem]
"Tsp"="Unimodem.dll"
"DeviceType"=dword:0
"FriendlyName"="SER2410 UNIMODEM"
"DevConfig"=hex: 10,00, 00,00, 05,00,00,00, 10,01,00,00, 00,4B,00,00, 00,00, 08, 00, 00, 00,00,00,00
7,注:
由于TE2410开发板上没有红外,所以代码中红外部分是没有用的。
启动后查看注册表[HKEY_LOCAL_MACHINE\Drivers\Active]可以看到刚添加的串口对应的设备名是COMX,可通过修改Order及Index的值来改变X的值(COM2被USB占用,最好设成COM3...)。