debug.c

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

C
227
字号
/* -*-C-*-
 *
 * $Revision: 1.1 $
 *   $Author: kwelton $
 *     $Date: 1999/11/02 17:09:31 $
 *
 * debug.c - debug utility routines for eboot program
 *
 * 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, 1996, 1997  Microsoft Corporation
 * Copyright (c) 1999, ARM Limited
 * All Rights Reserved
 */

/*
 * This file is derived very closely from the Microsoft's original
 * version in .../kernel/hal. Unfortunately, the HAL version is built
 * to run in a virtual address space, whereas the version for eboot
 * runs in a physical address space and therefore finds the peripherals
 * used for debug I/O elsewhere in the address space. Although duplicating
 * code is nasty, we do it here because the code involved is quite simple,
 * and life ends up cleaner than it otherwise would if we had to dick
 * around building two versions of the same source file
 */

#include <windows.h>
#include "platform.h"
#include "nkintr.h"

#if 0
#include "drv_glob.h"
#include "halether.h"
#include "ethdbg.h"
#include "win_plat.h"
#endif

/**********************************************************************/

static void setupserial(DWORD port)
{
    DWORD       value;

    /* first, disable everything */
    IO_WRITE(port + AMBA_UARTCR, 0x0);

    /* Set baud rate */
    value = (DEFAULT_OS_BAUD & 0xf00) >> 8;
    IO_WRITE(port + AMBA_UARTLCR_M, value);
    IO_WRITE(port + AMBA_UARTLCR_L, (DEFAULT_OS_BAUD & 0xff));

    /*
     * ----------v----------v-----------v----------v-----------
     * NOTE: MUST BE WRITTEN LAST (AFTER UARTLCR_M & UARTLCR_L)
     * ----------^----------^-----------^----------^-----------
     *
     * set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled
     */
    value = AMBA_UARTLCR_H_WLEN_8 | AMBA_UARTLCR_H_FEN;
    IO_WRITE(port + AMBA_UARTLCR_H, value);

    /* finally, enable the uart */
    IO_WRITE(port + AMBA_UARTCR, AMBA_UARTCR_UARTEN);
}

static void outb(BYTE value, void *address)
{
    IO_WRITE(address, value);
}

static DWORD inb(void *address)
{
    return (IO_READ(address));
}

/**********************************************************************/

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

/*
 *   @func   void OEMWriteDebugByte - Output byte to the monitor port.
 *
 *   @parm   unsigned char ch
 *           character to send
 */
void OEMWriteDebugByte(UCHAR ch) 
{
    int status;
        
    do
    {
        status = GET_STATUS(OS_COMPORT);
    } while(!TX_READY(status));

    PUT_CHAR(OS_COMPORT, ch);
}

/*
 *   @func   void OEMWriteDebugString - Display string to the monitor
 *                                      port.
 *
 *   @parm   unsigned short *str
 *           Points to the output buffer.
 */
void OEMWriteDebugString(unsigned short *str)
{
    while (*str)
        OEMWriteDebugByte((unsigned char)*str++);
}

/*
 *   @func   int OEMReadDebugByte - Get a byte from the monitor port.
 *
 *   @rdesc  Returns: 
 *           OEM_DEBUG_READ_NODATA      No data is available at the port.
 *           ch                         If data is available.
 *
 */
int OEMReadDebugByte(void) 
{
    DWORD status;

    status = GET_STATUS(OS_COMPORT);
    if (!RX_DATA(status))
        /* No data is available at the port */
        return OEM_DEBUG_READ_NODATA;

    return (int)GET_CHAR(OS_COMPORT);
}

/**********************************************************************/

void ARMInitSerial(void)
{
    setupserial(OS_COMPORT);
}

void ARMWriteByte(unsigned char ch) 
{
    OEMWriteDebugByte(ch);
}

void ARMWriteString(unsigned char *str)
{
    while (*str)
        ARMWriteByte(*str++);
}

void ARMPutHex(long value)
{
    unsigned char c;
    int i;

    ARMWriteByte('0');
    ARMWriteByte('x');

    for (i = 7; i >= 0; i--)
    {
        /* Strip next nibble */
        c = (value >> (i * 4)) & 0xf;

        if ((c >= 0) && (c <= 9))
            c = c + '0';
        else
            c = (c - 10) + 'a';

        ARMWriteByte(c);
    }
}

/**********************************************************************/

/*
 * Codes for hexadecimal characters
 */
static const unsigned int alpha_codes[] =
{
    0x007E, 0x080C, 0x01B6, 0x011E, 0x01CC, 0x01DA, 0x01FA, 0x2802,
    0x01FE, 0x01CE, 0x01EE, 0x01F8, 0x0072, 0x01BC, 0x00F2, 0x00E2
};

void ARMSetAlpha(DWORD value)
{
    volatile DWORD *AlphaBank = (DWORD *)INTEGRATOR_DBG_ALPHA;

    /*
     * Poll the scan in progress bit
     *
     * If the H/W is in the process of writing to the LED's then writing
     * to the control register will screw things up
     */
    while ((*(volatile DWORD *)AlphaBank & 1) != 0)
        /* do nothing */
        ;

    *AlphaBank = value;
}

int ARMSetLEDs(DWORD value)
{
    volatile DWORD *LedBank = (DWORD *)LED_BANK;

    /*
     * Poll the scan in progress bit
     */
    while ((*(volatile DWORD *)INTEGRATOR_DBG_ALPHA & 1) != 0)
        ;

    *LedBank = value;

    /* Return the number of LEDs in the system */
    return (uHAL_NUM_OF_LEDS);
}

/* EOF debug.c */

⌨️ 快捷键说明

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