debug.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 198 行

C
198
字号
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1998  Microsoft Corporation

Module Name:

   debug.c

Abstract:

Notes:


--*/

#include <windows.h>
#include <nkintr.h>
#include <altoona.h>
#include <hal.h>
#include <oalio.h>
#include <alt_def.h>
#include "ethernet.h"
#include <eglobal.h>


#define IoPortBase            ((PUCHAR)(PCI_IO_BASE | 0xA0000000))

#define DEBUG_COM_BASE      COM2_BASE

#define COM1_BASE           0x03F8

#define COM2_BASE           0x02F8

#define comTxBuffer         0x00
#define comRxBuffer         0x00
#define comDivisorLow       0x00
#define comDivisorHigh      0x01
#define comIntEnable        0x01
#define comIntId            0x02
#define comFIFOControl      0x02
#define comLineControl      0x03
#define comModemControl     0x04
#define comLineStatus       0x05
#define comModemStatus      0x06

#define LS_TSR_EMPTY        0x40
#define LS_THR_EMPTY        0x20
#define LS_RX_BREAK         0x10
#define LS_RX_FRAMING_ERR   0x08
#define LS_RX_PARITY_ERR    0x04
#define LS_RX_OVERRUN       0x02
#define LS_RX_DATA_READY    0x01

#define LS_RX_ERRORS        ( LS_RX_FRAMING_ERR | LS_RX_PARITY_ERR | LS_RX_OVERRUN )

//   14400 = 8
//   16457 = 7 +/-
//   19200 = 6
//   23040 = 5
//   28800 = 4
//   38400 = 3
//   57600 = 2
//  115200 = 1





/*****************************************************************************
*
*
*   @func void | OEMInitDebugSerial | Initialize debug monitor port.
*
*   NOTE: This function MUST NOT use any global variables.
*/
void OEMInitDebugSerial(void)
{

    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comLineControl, 0x80);   // Access Baud Divisor
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comDivisorLow, 0x03);    // Default Baud Rate is changed to 38400
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comDivisorHigh, 0x00);
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comFIFOControl, 0x01);   // Enable FIFO if present
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comLineControl, 0x03);   // 8 bit, no parity
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comIntEnable, 0x00);     // No interrupts, polled
    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comModemControl, 0x03);  // Assert DTR, RTS

}



/*****************************************************************************
*
*
*   @func   void | OEMWriteDebugString | Display string to the monitor port.
*
*   @parm   unsigned short * | str |
*           Points to the receiving buffer.
*/
void OEMWriteDebugString(unsigned short *str)
{

     
    while (*str)
    {
        UCHAR   ucChar;
        UCHAR   ucStatus;

        do
        {
            ucStatus = READ_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comLineStatus);
        }
        while (!(ucStatus & LS_THR_EMPTY));

        ucChar = (UCHAR)*str;

        WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comTxBuffer, ucChar);
        str++;
    }


}

/*****************************************************************************
*
*
*   @func   void | OEMWriteDebugByte | Output byte to the monitor port.
*
*   @parm   UCHAR | ucChar |
*           The data byte to be transmitted.
*/
void OEMWriteDebugByte(BYTE ucChar)
{

    unsigned char   ucStatus;

    do
    {
        ucStatus = READ_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comLineStatus);
    }
    while (!(ucStatus & LS_THR_EMPTY));

    WRITE_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comTxBuffer, ucChar);

}


/*****************************************************************************
*
*
*   @func   int | OEMReadDebugByte | Get a byte from the monitor port.
*
*   @rdesc  Returns:
*           OEM_DEBUG_COM_ERROR        Error detected
*           OEM_DEBUG_READ_NODATA      No data is available at the port.
*           ch                         If data is available.
*
*/
int OEMReadDebugByte(void)
{
    unsigned char   ucStatus;
    unsigned char   ucChar;

    ucStatus = READ_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comLineStatus);

    if (ucStatus & LS_RX_DATA_READY)
    {
        ucChar = READ_PORT_UCHAR(IoPortBase+DEBUG_COM_BASE+comRxBuffer);

        if (ucStatus & LS_RX_ERRORS)
        {
            return OEM_DEBUG_COM_ERROR;
        }
        else
        {
            return ucChar;
        }

    }

    return OEM_DEBUG_READ_NODATA;

}


/*****************************************************************************
*
*
*   @func   void    |   OEMClearDebugComError | Clear a debug communications
*                       error
*
*/
void OEMClearDebugCommError(void)
{
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?