⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 Wince4.2 BSP for SH4 engineering development board
💻 C
字号:

//
//      Copyright (c) Renesas Technology Corp. 1998-2003 All Rights Reserved.
//
//      OEM Adaptation Layer
//
//----------------------------------------------------------------------------
//
//  FILE      : Debug.c
//  CREATED   : 2001.09.27
//  MODIFIED  : 2003.08.06
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS HS7751RSTC01H (S1-E, ITS-DS5)
//  TARGET OS : Microsoft(R) Windows(R) CE .NET 4.2
//  NOTES     : 
//  FUNCTION  : ISR body of HD64404 timer module
//  HISTORY   :
//				1999.04.26  
//				- Released for PFM-DS6x.
//        		2001.07.05  
//        		- Modified for ITS-DS2A.
//        		(Detailed history for previous platforms are omitted.)
//        		2002.02.19  
//        		- Modified for HS7751RSTC01H (S1-E, ITS-DS5).
//        		2002.05.02  
//        		- Adapted for System FPGA and Peripheral FPGA specification
//               changes from supporting 64MB flash memory board.
//        		2002.07.26  
//        		- Temporary modified for CEPB4.1 environment.
//        		2002.08.29  
//        		- Commented network initialization part is removed.
//        		2002.09.27
//        		- Released


//------------------------------------------------------------------------------
//
//  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-1997 Microsoft Corporation.  All rights reserved.
//  
//------------------------------------------------------------------------------

#include <windows.h>
#include <nkintr.h>
#include <ethdbg.h>
#include <halether.h>

#include "shx.h"
#include "s1e.h"
#include "drv_glob.h"

#ifndef ENABLE_DEBUG_SERIAL
#define ENABLE_DEBUG_SERIAL 0
#endif

#define BAUD_RATE 38400

// For converting net byte order to host byte order
#define htons( value ) ((UINT16)((((UINT16)value) << 8) | (((UINT16)((UINT16)value)) >> 8)))
#define ntohs( value ) htons( value )      

static BOOL DebugEtherPresent;
#define SCSMR   *(UCHAR volatile *)(SCI_SCSMR1)     /* serial mode        */
#define SCBRR   *(UCHAR volatile *)(SCI_SCBRR1)     /* serial baud rate   */
#define SCSCR   *(UCHAR volatile *)(SCI_SCSCR1)     /* serial control     */
#define SCTDR   *(UCHAR volatile *)(SCI_SCTDR1)     /* transmit data      */
#define SCSSR   *(UCHAR volatile *)(SCI_SCSSR1)     /* serial status      */
#define SCRDR   *(UCHAR volatile *)(SCI_SCRDR1)     /* recieve data       */
#define SCSCMR  *(UCHAR volatile *)(SCI_SCSCMR1)    /* serial mode        */
#define SCSPTR  *(UCHAR volatile *)(SCI_SCSPTR1)    /* port I/O control   */

extern void InitTransport (void); 	//2001.10.09 P00001

/* Message LED support functions */
void PrintLED(char *p) // display character string
{
    volatile char *pAlphaLED;
    int i;

    pAlphaLED = (volatile char*)LED_ALPHA;
    i = 0;
    while (i < 8 && *p != '\0') {
        *pAlphaLED++ = *p++;
        *pAlphaLED++; // byte size registers allocated in word space
        i++;
    }
}

void WriteLED(DWORD val) // display hexadecimal value
{
    volatile char *pAlphaLED;
    int i;
    char c;

    pAlphaLED = (volatile char*)LED_ALPHA;

    for (i = 7; i >= 0; i--) {
        c = (char)((val >> i * 4) & 0x0f);
        if (c < 10) c += '0'; // '0' - '9'
        else c += 'A' - 10; // 'A' - 'F'
        *pAlphaLED++ = c;
        *pAlphaLED++; // byte size registers allocated in word space
    }
}


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

        volatile int i; /* not to be optimized out */
        int nClockFreq, nDiv;
        int nDiv1, nDiv2, nError1, nError2;


        /* Get clock frequency for SH-4 SCI. */
        nClockFreq = (int)
            ((PDRIVER_GLOBALS)DRIVER_GLOBALS_PHYSICAL_MEMORY_START)->
            clk.dwPeripheralFrequency; /* Don't use pDriverGlobals. */
        if (nClockFreq < 1000000 || nClockFreq > 100000000) {
            /* Under 1MHz or over 100MHz frequency detected. */
            /* This maybe uninitialized or incorrectly set.  */ 
            PrintLED("BadPClk");
            while (1); /* Stop here to prevent problems. */
        }

        nDiv1 = nClockFreq / 32 / BAUD_RATE;
        nDiv2 = nDiv1 + 1;
        /* Calculates error rate in permil. (1/1000) */
        nError1 = (nClockFreq * 1000 / 32 / nDiv1 - BAUD_RATE * 1000) / BAUD_RATE;
        nError2 = (nClockFreq * 1000 / 32 / nDiv2 - BAUD_RATE * 1000) / BAUD_RATE;
        /* nError1 must be grater or equal 0. */
        /* nError2 must be lesser than 0.     */
        if (nError1 < -nError2) nDiv = nDiv1;
        else nDiv = nDiv2;

        if (nDiv > 255) {
            /* Display too slow warning and skip initialization. */
            PrintLED("SerSlow");
            goto SerInitFail;
        }
        else if (nError1 > 20 && nError2 < -20) {
            /* Display high error rate warning and continue. */
            PrintLED("SerHiErr");
        }

        SCSCR = 0x00;       /* Clear all enable bits.                    */
        SCSCR &= 0xFC;      /* Clear CKE1 and CKE0 bits.                 */

        SCSMR = 0x0000;     /* 8 bit data, non parity, 1 stop bit,       */
                            /* serial clock = Pclk.                      */
        SCBRR = (BYTE)--nDiv; /* divider for specified baud rate           */

        for (i = 0; i < 100000; i++); /* Wait at least 1 bit time. */

        SCSCR |= 0x30;      /* Set TE, RE.                               */
        SCSPTR = 0x00;      /* Disable I/O port shared with SCI.         */

	}

SerInitFail:
    ;
#ifndef BOOT_LOADER

    InitTransport ();					//2001.10.09 P00001

#endif // BOOT_LOADER

}

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


/*****************************************************************************
*
*
*   @func   void    |   OEMWriteDebugByte | Output byte to the monitor port.
*
*   @parm   unsigned char *| str |
*           Points to the output buffer.
*/
void OEMWriteDebugByte(UCHAR ch)
{
	if (ENABLE_DEBUG_SERIAL)
	{
waitTX:
	if((SCSSR & 0x80)==0x80)
	{
		SCTDR = ch;
		SCSSR &= 0x7F;
		return;
	}
        goto waitTX;
	}
}

/*****************************************************************************
*
*
*   @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()
{
	UCHAR ch;
	if (ENABLE_DEBUG_SERIAL)
	{
		if (SCSSR & 0x38)			// See if there is an error
		{
			OEMClearDebugCommError();
		}

		if( !( SCSSR & 0x40 ) )	// See if RDRF = 1
		{
			DWORD dwWaitCount=8;
			while(dwWaitCount--);

			return OEM_DEBUG_READ_NODATA;
		}
		ch = SCRDR;
		SCSSR &= ~0x40;		// Clear RDF
		return ch;
	}
	return (0);
}
/*****************************************************************************
*
*
*   @func   void    |   OEMClearDebugComError | Clear a debug communications error
*
*/
void OEMClearDebugCommError(void)
{
	if (ENABLE_DEBUG_SERIAL)
	{
		SCSSR &= ~0x38;			// Clear ORER,PER,FER
	}
}

⌨️ 快捷键说明

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