与串口调试功能有关的OEM函数

标题:与串口调试功能有关的OEM函数

摘要:实现串口打印信息

备注: Windows Embedded CE 6.0

日期:2010.4.18

姓名:朱铭雷

=============================================================

       在调试驱动和下载NK的时候,串口的打印信息至关重要,这需要如下几个函数的支持。

OEMInitDebugSerial:初始化调试串口。

OEMReadDebugByte:从调试串口读取一个字节。

OEMWriteDebugByte:向调试串口写入一个字节。

OemWriteDebugString:向调试串口写入一个字符串。

       安装了WinCE 6.0之后,在PLATFORM文件夹下有一个DEVICEEMULATOR,以这个BSP包为例。

       在OAL下有一个debug.c文件,其中实现了OEMInitDebugSerial,OEMReadDebugByte,OEMWriteDebugByte这三个函数。具体路径是:

/WINCE600/PLATFORM/DEVICEEMULATOR/SRC/OAL/OALLIB

在BOOTLOADER下也有一个debug.c文件,其中实现了OemWriteDebugString函数。具体路径是:/WINCE600/PLATFORM/DEVICEEMULATOR/SRC/BOOTLOADER/EBOOT。

OAL和BOOTLOADER都需要使用串口调试的功能,所以上面四个函数一般是两者共同使用,这样可以减少工作量,维护起来也更方便。

下面是这四个函数的源代码:

① OEMInitDebugSerial

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

//

//  Function: OEMInitDebugSerial

//

//  Initializes the debug serial port

//

VOID OEMInitDebugSerial()

{

    S3C2410X_IOPORT_REG *pIOPortReg;

 

#ifdef DEBUG

    UINT32 logMask;

 

    // At this moment we must suppress logging.

    //

    logMask = dpCurSettings.ulZoneMask;

    dpCurSettings.ulZoneMask = 0;

#endif

   

    // Configure port H for UART1.

    //

pIOPortReg =

(S3C2410X_IOPORT_REG*)OALPAtoVA(S3C2410X_BASE_REG_PA_IOPORT, FALSE);

 

    // GPH2 and GHP3 are UART1 Tx and Rx, respectively.

    //

    CLRREG32(&pIOPortReg->GPHCON, (3 << 8)|(3 << 10));

    SETREG32(&pIOPortReg->GPHCON, (2 << 8)|(2 << 10));

 

    // Disable pull-up on TXD1 and RXD1.

    //

    SETREG32(&pIOPortReg->GPHUP, (1 << 4)|(1 << 5));

 

    // UART1 (TXD1 & RXD1) used for debug serial.

    //

g_pUARTReg =

(S3C2410X_UART_REG *)OALPAtoVA(S3C2410X_BASE_REG_PA_UART1, FALSE);

 

    // Configure the UART.

    //

    OUTREG32(&g_pUARTReg->UFCON,  BSP_UART1_UFCON);

    OUTREG32(&g_pUARTReg->UMCON,  BSP_UART1_UMCON);

    OUTREG32(&g_pUARTReg->ULCON,  BSP_UART1_ULCON);

    OUTREG32(&g_pUARTReg->UCON,   BSP_UART1_UCON);

    OUTREG32(&g_pUARTReg->UBRDIV, BSP_UART1_UBRDIV);

 

#ifdef DEBUG

    // Restore the logging mask.

    //

    dpCurSettings.ulZoneMask = logMask;

#endif

}

       将复用的IO口选择为串口功能,并进行配置。

       ② OEMReadDebugByte

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

//

//  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;

 

    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;

}

       状态寄存器UTRSTAT的第0位为1时,表示调试串口接收到有效数据。

       ③ OEMWriteDebugByte

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

//

//  Function: OEMWriteDebugByte

//

//  Transmits a character out the debug serial port.

//

VOID OEMWriteDebugByte(UINT8 ch)

{

    // Wait for transmit buffer to be empty

    while ((INREG32(&g_pUARTReg->UTRSTAT) & 0x02) == 0);

 

    // Send character

    OUTREG32(&g_pUARTReg->UTXH, ch);

}

       状态寄存器UTRSTAT的第1位为1时,表示调试串口已经准备好,可以发送数据。

       ④ OemWriteDebugString

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

//

//  Function:  OEMWriteDebugString

//

//  Output unicode string to debug serial port

//

VOID OEMWriteDebugString(LPWSTR string)

{

    while (*string != L'/0') OEMWriteDebugByte((UINT8)*string++);

}

       OEMWriteDebugString函数调用OEMWriteDebugByte函数来实现向调试串口输出一个字符串。

       BOOTLOADER运行时,一般禁用外设中断。所以上面几个函数都是以查询方式实现的。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/joyzml/archive/2010/04/18/5499691.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值