wince的调试串口作为普通串口使用

目前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的易用性差不多了。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/pk666666/archive/2010/12/17/6082654.aspx

posted @ 2011-04-25 14:00  继海  阅读(560)  评论(0编辑  收藏  举报