Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1085463
  • 博文数量: 169
  • 博客积分: 12306
  • 博客等级: 上将
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-29 14:55
文章分类

全部博文(169)

文章存档

2012年(18)

2011年(78)

2010年(15)

2009年(1)

2008年(11)

2007年(39)

2006年(7)

我的朋友

分类: C/C++

2007-09-27 02:20:49

    EVC串口通信编写完成后,发现通过开发板com1与pc通信时,除了我所以发送的信息之外,我的每一个动作(点击按钮,打开窗口…………)都主动发送的pc的串口调试助手上;而通过开发板com2与pc通信时,我所以发送的信息和每一动作又都没又发送的pc的串口调试助手上,真是奇怪!!!
    于是上网找答案,终于发现原因:原来三星的2410板子的BSP只添加了一个串口(这里对应com1)和一个红外口(这里对应com3)的支持,其中所支持的串口还是作为调试端口提供的。为什么说这里对应comX呢?原因是串口和与之对应的comX是可以修改的,以下有该说明。
    这样,周淳和我的目标就是修改BSP源码,使之支持正常的串口通信,一般对应于com2。
    在网上搜索到了不少相关的文章,但是都有这点、那点的小bug。以下是周淳和我所使用的一个版本,经过我们的研究已经更正了一些错误,现在已经能够成功的使2410开发板的wince4.2系统支持com2口通信!
    修改的源码如下:

需要更改的内容:

\FILES\platform.reg
\INC\oalintr.h
\DRIVERS\SERIAL\ser2410_hw.c
\DRIVERS\SERIAL\ser2410_ser.c
\KERNEL\HAL\cfw.c
\KERNEL\HAL\ARM\armint.c 

修改步骤如下:

1、中断源修改
#define SYSINTR_SERIAL1  (SYSINTR_FIRMWARE+19)
修改以下中断范围使之能包含这个新添加的中断。
MapIrq2SysIntr(DWORD _Irq)
{
   if( _Irq<=19 )
       return ( SYSINTR_FIRMWARE + _Irq );
   else
       return (0xffffffff);
}

 // 19 这个数字根据您的系统而定,并且需要和注册表相匹配。
这里,我们可以看到SYSINTR_SERIAL1定义到19=0x13,与注册表中一致。
2、打开串口源文件中ser2410_hw.c文件。这个文件修改了数据结构根据注册表中的配置情况进行端口匹配。
搜索:
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)
 {
 #if USEVIRTUAL
   EnterCriticalSection(&(pHWHead->RegCritSec));
   v_pIOPregs->rGPHCON &= ~(0x3<<8 | 0x3<<10 /*| 0x3<<12 | 0x3<<14*/); // clear
uart 1 - rx, tx
   v_pIOPregs->rGPHCON |= (0x2<<8 | 0x2<<10 /*| 0x1<<12 | 0x0<<14*/);
   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
   volatile IOPreg *s2410IOP;
   s2410IOP   = (volatile IOPreg *)IOP_BASE;
 
   EnterCriticalSection(&(pHWHead->RegCritSec));
   s2410IOP->rGPHCON &= ~(0x3<<8 | 0x3<<10/* | 0x3<<12 | 0x3<<14*/); // clear
uart 1 - rx, tx
   s2410IOP->rGPHCON |= (0x2<<8 | 0x2<<10 /*| 0x1<<12 | 0x0<<14*/);
   s2410IOP->rGPHCON |= (0x2<<0 | 0x2<<2 );
   s2410IOP->rGPHUP  |= 0x03;
   pHWHead->rDTRport = (volatile unsigned int *)(IOP_BASE+0x74);
//s2410IOP->rGPHDAT
   pHWHead->rDSRport = (volatile unsigned int *)(IOP_BASE+0x74);
   pHWHead->DtrPortNum = 0;
   pHWHead->DsrPortNum = 1;
 #endif
 }
 else if(pHWHead1->dwIOBase == 0x50008000)
 {
 #if USEVIRTUAL
   EnterCriticalSection(&(pHWHead->RegCritSec));
   v_pIOPregs->rGPHCON &= ~( 0x3<<12 | 0x3<<14); // clear uart 2 - rx, tx
   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
   volatile IOPreg *s2410IOP;
   s2410IOP   = (volatile IOPreg *)IOP_BASE;
 
   EnterCriticalSection(&(pHWHead->RegCritSec));
   s2410IOP->rGPHCON &= ~(0x3<<12 | 0x3<<14); // clear uart 2 - rx, tx
   s2410IOP->rGPHCON |= ( 0x02<<12 | 0x02<<14);
   s2410IOP->rGPHCON |= (0x2<<0 | 0x2<<2 );
   s2410IOP->rGPHUP  &= ~0xc0;
   pHWHead->rDTRport = (volatile unsigned int *)(IOP_BASE+0x74);
//s2410IOP->rGPHDAT
   pHWHead->rDSRport = (volatile unsigned int *)(IOP_BASE+0x74);
   pHWHead->DtrPortNum = 0;
   pHWHead->DsrPortNum = 1;
 #endif   
 }
 else
 {
 #if USEVIRTUAL
   EnterCriticalSection(&(pHWHead->RegCritSec));
   v_pIOPregs->rGPHCON &= ~(0x3<<0 | 0x3<<2 | 0x3<<4 | 0x3<<6/* | 0x3<<12 |
0x3<<14*/); // clear uart 0 - rx, tx
   v_pIOPregs->rGPHCON |= (0x2<<4 | 0x2<<6/* | 0x1<<12 | 0x0<<14*/);
   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
   volatile IOPreg *s2410IOP;
   s2410IOP   = (volatile IOPreg *)IOP_BASE;
 
   EnterCriticalSection(&(pHWHead->RegCritSec));
   s2410IOP->rGPHCON &= ~(0x3<<0 | 0x3<<2 | 0x3<<4 | 0x3<<6 /*| 0x3<<12 |
0x3<<14*/); // clear uart 0 - rx, tx
   s2410IOP->rGPHCON |= (0x2<<4 | 0x2<<6 /*| 0x1<<12 | 0x0<<14*/);
   s2410IOP->rGPHCON |= (0x2<<0 | 0x2<<2 );
   s2410IOP->rGPHUP  |= 0x03;
   pHWHead->rDTRport = (volatile unsigned int *)(IOP_BASE+0x74);
//s2410IOP->rGPHDAT
   pHWHead->rDSRport = (volatile unsigned int *)(IOP_BASE+0x74);
   pHWHead->DtrPortNum = 0;
   pHWHead->DsrPortNum =1;
 #endif
 }
 LeaveCriticalSection(&(pHWHead->RegCritSec));
}

接着搜索:
SL_Init(
      PVOID   pHead, // @parm points to device head
      PUCHAR  pRegBase, // Pointer to 16550 register base
      UINT8   RegStride, // Stride amongst the 16550 registers
      EVENT_FUNC EventCallback, // This callback exists in MDD
      PVOID   pMddHead,   // This is the first parm to callback
      PLOOKUP_TBL   pBaudTable  // BaudRate Table
      )
在PS2410_UART_INFO   pHWHead   = (PS2410_UART_INFO)pHead;这一句后面添加:

PSER_INFO     pHWHead1  = (PSER_INFO)pHead;

再搜索:
 if ( pHWHead->UseIrDA )
 {
   pHWHead->bINT = BIT_UART2;
   pHWHead->bTxINT = INTSUB_TXD2;
   pHWHead->bRxINT = INTSUB_RXD2;
   pHWHead->bErrINT = INTSUB_ERR2;
#if USEVIRTUAL
   pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART2regs;
   pRegBase = (PUCHAR)pHWHead->s2410SerReg;
#else   
   pRegBase = (PUCHAR)UART2_BASE;
   pHWHead->s2410SerReg = (S2410_UART_REG *)pRegBase;
#endif
 }
 else
 {
 把这其中的代码修改为以下代码
 }

   if(pHWHead1->dwIOBase == 0x50004000)
   {
     pHWHead->bINT = BIT_UART1;
     pHWHead->bTxINT = INTSUB_TXD1;
     pHWHead->bRxINT = INTSUB_RXD1;
     pHWHead->bErrINT = INTSUB_ERR1;
   #if USEVIRTUAL
     pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART1regs;
     pRegBase = (PUCHAR)pHWHead->s2410SerReg;
   #else   
     pRegBase = (PUCHAR)UART1_BASE;
     pHWHead->s2410SerReg = (S2410_UART_REG *)pRegBase;
   #endif
    
   }
   else if(pHWHead1->dwIOBase == 0x50008000)
   {
     pHWHead->bINT = BIT_UART2;
     pHWHead->bTxINT = INTSUB_TXD2;
     pHWHead->bRxINT = INTSUB_RXD2;
     pHWHead->bErrINT = INTSUB_ERR2;
   #if USEVIRTUAL
     pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART2regs;
     pRegBase = (PUCHAR)pHWHead->s2410SerReg;
   #else   
     pRegBase = (PUCHAR)UART2_BASE;
     pHWHead->s2410SerReg = (S2410_UART_REG *)pRegBase;
   #endif
   }
   else
   {
    
     pHWHead->bINT = BIT_UART0;
     pHWHead->bTxINT = INTSUB_TXD0;
     pHWHead->bRxINT = INTSUB_RXD0;
     pHWHead->bErrINT = INTSUB_ERR0;
   #if USEVIRTUAL
     pHWHead->s2410SerReg = (S2410_UART_REG *)v_pUART0regs;
     pRegBase = (PUCHAR)pHWHead->s2410SerReg;
   #else   
     pRegBase = (PUCHAR)UART0_BASE;
     pHWHead->s2410SerReg = (S2410_UART_REG *)pRegBase;
   #endif
   }

再搜索:
 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);   
   }
3、打开ser2410_ser.c文件。
搜索:
const HWOBJ IoObj = {
 THREAD_AT_INIT,
 SYSINTR_SERIAL,
 (PHW_VTBL) &IoVTbl
};
在其后面添加:

const HWOBJ Io1Obj = {
 THREAD_AT_INIT,
 SYSINTR_SERIAL1,
 (PHW_VTBL) &IoVTbl
};

const HWOBJ Io2Obj = {
 THREAD_AT_INIT,
 SYSINTR_IR,
 (PHW_VTBL) &IoVTbl
};

接着搜索:
const PCHWOBJ HWObjects[] = {
 &IoObj,
 &IrObj
};
将其修改为:

const PCHWOBJ HWObjects[] = {
 &IoObj,
 &Io1Obj,
 &Io2Obj
};

再搜索:
GetSerialObject(
              DWORD DeviceArrayIndex
              )
将其函数改为:

{
 PHWOBJ pSerObj;

 DEBUGMSG(DEBUGMODE,(TEXT("GetSerialObject : DeviceArrayIndex = %d\r\n"),
DeviceArrayIndex));

 // Now return this structure to the MDD.
 if ( DeviceArrayIndex == 2 )
 { 
   RETAILMSG(1,(TEXT("GetSerialObject Io2Obj\r\n")));
   pSerObj = (PHWOBJ)(&Io2Obj);
 }
 else if(DeviceArrayIndex == 1)
   pSerObj = (PHWOBJ)(&Io1Obj);
 else
   pSerObj = (PHWOBJ)(&IoObj);

 return (pSerObj);
}
4、打开cfw.c文件,这就是中断处理。
搜索:
BOOL
OEMInterruptEnable(DWORD  idInt,  // @parm Interrupt ID to be enabled. See Interrupt ID's.Interrupt ID's>  for a list of possble values.
          LPVOID pvData,  // @parm ptr to data passed in in the InterruptInitialize> call
              DWORD  cbData)  // @parm Size of data pointed to be


找到这一句:case SYSINTR_SERIAL:
在其后面添加:

 case SYSINTR_SERIAL1:  // Serial port1.
   s2410INT->rSUBSRCPND  = (INTSUB_RXD1 | INTSUB_TXD1 | INTSUB_ERR1);
   s2410INT->rINTSUBMSK &= ~INTSUB_RXD1;
   s2410INT->rINTSUBMSK &= ~INTSUB_TXD1;
   s2410INT->rINTSUBMSK &= ~INTSUB_ERR1;
   s2410INT->rSRCPND     = BIT_UART1;
   // S3C2410X Developer Notice (page 4) warns against writing a 1 to a 0 bit in
the INTPND register.
   if (s2410INT->rINTPND & BIT_UART1) s2410INT->rINTPND = BIT_UART1;
   s2410INT->rINTMSK    &= ~BIT_UART1;
   break;

搜索:
void
OEMInterruptDisable(DWORD idInt)  // @parm Interrupt ID to be disabled. See Interrupt ID's>
还是这一句:case SYSINTR_SERIAL:
在其后面添加:

 case SYSINTR_SERIAL1:
   s2410INT->rINTMSK    |= BIT_UART1;
   s2410INT->rINTSUBMSK |= INTSUB_RXD1;
   s2410INT->rINTSUBMSK |= INTSUB_TXD1;
   s2410INT->rINTSUBMSK |= INTSUB_ERR1;
   break;

搜索:
void
OEMInterruptDone(DWORD idInt)  // @parm Interrupt ID. See
依旧找到case SYSINTR_SERIAL:
在其后面添加:

 case SYSINTR_SERIAL1:
   s2410INT->rINTMSK    &= ~BIT_UART1;
   s2410INT->rINTSUBMSK &= ~INTSUB_RXD1;
   break;
5、打开armint.c文件。
搜索:else if(IntPendVal == INTSRC_UART0)
在其后面添加:

 else if(IntPendVal == INTSRC_UART1)
 {
   SubIntPendVal = s2410INT->rSUBSRCPND;

   // Note that we only mask the sub source interrupt - the serial driver will
clear the
   // sub source pending register.
   //
   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);
   }
 
   // NOTE: Don't clear INTSRC:UART1 here - serial driver does that.
   //
   s2410INT->rINTMSK |= BIT_UART1;
   if (s2410INT->rINTPND & BIT_UART1) s2410INT->rINTPND  = BIT_UART1;

   return(SYSINTR_SERIAL1);
  
 }

6、打开platform.reg文件,这个是WinCE注册表文件,在这里,我们要修改并添加串口。
搜索:[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410],这就是串口1。
将其下面的键值改为:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410]
  "DeviceArrayIndex"=dword:0
  "Irq"=dword:03
  "IoBase"=dword:50000000
  "IoLen"=dword:2C
  "Prefix"="COM"
  "Dll"="SER2410.Dll"
  "Order"=dword:0
  "Priority"=dword:0
  "Port"="COM1:"
  "DeviceType"=dword:0
  "FriendlyName"="Serial Cable on COM1:"
  "Tsp"="Unimodem.dll"
  "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

再在其后面添加串口2:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410_2]
  "DeviceArrayIndex"=dword:1
  "Irq"=dword:13
  "IoBase"=dword:50004000
  "IoLen"=dword:2C
  "Prefix"="COM"
  "Dll"="SER2410.Dll"
  "Order"=dword:0
  "Priority"=dword:0
  "Port"="COM2:"
  "DeviceType"=dword:0
  "FriendlyName"="Serial Cable on COM2:"
  "Tsp"="Unimodem.dll"
  "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

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SER2410_2\Unimodem]
  "Tsp"="Unimodem.dll"
  "DeviceType"=dword:0
  "FriendlyName"="SER2410_2 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

再搜索:[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\IRDA2410],这个是红外,也要修改下:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\IRDA2410]
  "DeviceArrayIndex"=dword:2
  "Irq"=dword:09
  "IoBase"=dword:50008000
  "IoLen"=dword:2C
  "Prefix"="COM"
  "Dll"="IRDA2410.Dll"
  "Order"=dword:0
  "Priority"=dword:0
  "Port"="COM3:"
  "DeviceType"=dword:0  ; IRDA modem, 0 -> null modem
  "FriendlyName"="S2410 IRDA2410"
; "Index"=dword:3
  "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"

好了,注册表就改到这里,以上要特别注意Irq的值,要和oalintr.h里面的中断定义对应,并且注意Order的顺序,DeviceArrayIndex的值以及IoBase,后面串口源代码中要用到该值作判断。


阅读(5093) | 评论(8) | 转发(0) |
给主人留下些什么吧!~~

gunnerlzx2008-03-15 15:34:28

不好意思,我公司上不了QQ,我记得按照这种方法,我是通过了的,你自己看看是不是哪里出了小问题?

gunnerlzx2008-03-15 15:34:28

不好意思,我公司上不了QQ,我记得按照这种方法,我是通过了的,你自己看看是不是哪里出了小问题?

chinaunix网友2008-03-15 10:57:33

编译不了 QQ:63314398

chinaunix网友2008-03-15 10:57:33

编译不了 QQ:63314398

gunnerlzx2008-01-23 17:23:34

这里的order其实并不是决定顺序的关键,关键是看DeviceArrayIndex,这个参数来决定顺序