Chinaunix首页 | 论坛 | 博客
  • 博客访问: 921021
  • 博文数量: 96
  • 博客积分: 10071
  • 博客等级: 上将
  • 技术积分: 1118
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-20 17:54
文章分类

全部博文(96)

文章存档

2011年(3)

2010年(3)

2009年(29)

2008年(54)

2007年(7)

分类:

2009-05-18 16:22:05

wince的调试串口作为普通串口使用
creator
sz111@126.com

目前wince的串口0是作为调试串口用的,但是因为我的案子需要3个串口,所以要把它改为普通串口,但是开机时候还是需要打印debug信息,鉴于此,我修改如下:
debug.c中加入一行:
int DebugConsoleEnabled=1;
发送时候做判断:
//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugByte
//
//  Transmits a character out the debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch) 
{
    if(DebugConsoleEnabled == 0)
return;
    // Wait for transmit buffer to be empty
    while ((INREG32(&g_pUARTReg->UTRSTAT) & 0x02) == 0);

    // Send character
    OUTREG32(&g_pUARTReg->UTXH, ch);
}

//------------------------------------------------------------------------------
//
//  Function: OEMReadDebugByte
//
//  Reads a byte from the debug serial port. Does not wait for a character. 
//  If a character is not available function returns "OEM_DEBUG_READ_NODATA".
//

int OEMReadDebugByte() 
{
    UINT32 status, ch;

    if(DebugConsoleEnabled == 0)
return 0;
    status = INREG32(&g_pUARTReg->UTRSTAT);
    if ((status & 0x01) != 0) {
       ch = INREG32(&g_pUARTReg->URXH);
       // if ((status & UART_LINESTAT_RF) != 0) ch = OEM_DEBUG_COM_ERROR;
    } else {
       ch = OEM_DEBUG_READ_NODATA;
    }
    return (int)ch;
}

然后在OemInit函数结束后把DebugConsoleEnabled = 0;就可以了。
不知道为何,我4.2的bsp生成的wince,用以前的串口测试程序来测试,就可以,但是我的5.0的wince,串口测试程序打开不了,无奈只能自己写了一个简单的c#的串口测试,串口0是ok的。后续就是串口1,串口2了。
ps:C#真是方便啊,一个从来没有摸过c#的人就可以直接写界面看起来并不简单的程序。感觉和delphi的易用性差不多了。
阅读(2409) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~