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

📄 dbgserial.c

📁 WinCE5.0BSP for Renesas SH7770
💻 C
字号:
//
//  Copyright(C) Renesas Technology Corp. 2002-2005. All rights reserved.
//
//  debug serial routine for ITS-DS7 Ver.1.0.0
//
//  FILE      : dbgserial.c
//  CREATED   : 2002.04.25
//  MODIFIED  : 2005.11.14
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS ITS-DS7
//  HISTORY   : 
//              2003.06.12
//              - Created release code.
//                (based on RENESAS ITS-DS4 Source Kit Ver.1.2.0 for WCE4.2)
//              2005.11.14
//              - Changed OAL file and directory structures to production-qualiry OAL model.

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  dbgserial.c            
//
//  This module is provides the interface to the serial port.
//

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

#include "shx.h"
#include "platform.h"
#include "sh7770.h"
#include "drv_glob.h"
 
//------------------------------------------------------------------------------
// Defines 
//
#define pDriverGlobals  ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)

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

#define SCIF_SCSMR_OFFSET			0x0000		// Serial Mode Register 
#define	SCIF_SCBRR_OFFSET			0x0004		// Bit rate register 
#define SCIF_SCSCR_OFFSET			0x0008		// Serial Control Register 
#define SCIF_SCFTDR_OFFSET			0x000c		// transmit FIFO data register 
#define	SCIF_SCFSR_OFFSET			0x0010		// Serail Status Register 
#define SCIF_SCFRDR_OFFSET			0x0014		// Receive Data FIFO register 
#define	SCIF_SCFCR_OFFSET			0x0018		// FIFO Control Register 
#define	SCIF_SCFDR_OFFSET			0x001c		// FIFO Data Count set register 
#define	SCIF_SCSPTR_OFFSET			0x0020		// FIFO Data Count set register 
#define	SCIF_SCLSR_OFFSET			0x0024		// FIFO Data Count set register 
#define	SCIF_BRG_DL_OFFSET			0x0030		// DL register
#define	SCIF_BRG_CKS_OFFSET			0x0034		// CKS register


#define SCSMR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCSMR_OFFSET)   // Serial Mode
#define SCBRR2  *(UCHAR  volatile *)(SCIF2_REGBASE + SCIF_SCBRR_OFFSET)   // Serial Bit Rate
#define SCSCR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCSCR_OFFSET)   // Serial Control
#define SCFTDR2 *(UCHAR  volatile *)(SCIF2_REGBASE + SCIF_SCFTDR_OFFSET)  // Transmit FIFO Data
#define SCFSR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCFSR_OFFSET)   // Serial Status
#define SCFRDR2 *(UCHAR  volatile *)(SCIF2_REGBASE + SCIF_SCFRDR_OFFSET)  // Receive FIFO Data
#define SCSPTR2 *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCSPTR_OFFSET)  // Port I/O Control
#define SCFCR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCFCR_OFFSET)   // FIFO Control
#define SCFDR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCFDR_OFFSET)   // FIFO Data Count
#define SCLSR2  *(USHORT volatile *)(SCIF2_REGBASE + SCIF_SCLSR_OFFSET)   // Line Status
#define BRG_DL  *(DWORD  volatile *)(SCIF2_REGBASE + SCIF_BRG_DL_OFFSET)  // Baudrate Generator (DL)
#define BRG_CKS *(DWORD  volatile *)(SCIF2_REGBASE + SCIF_BRG_CKS_OFFSET) // Baudrate Generator (CKS)
 
//------------------------------------------------------------------------------
// Externs
//
 
//------------------------------------------------------------------------------
// Global Variables 

//------------------------------------------------------------------------------
// Local Variables 
//
static BOOL DebugEtherPresent;


//------------------------------------------------------------------------------
// Local Functions 
//
/* 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
    }
}

//------------------------------------------------------------------------------
//
//  Function: OEMInitDebugSerial
//
//  Initializes the debug serial port
//

VOID InitDebugSerial() 
{
	if (ENABLE_DEBUG_SERIAL)
	{
		SCSCR2 = 0x0000;		// Clear TE, RE bits.

		SCFCR2 = 0x0006;		// Set TFRST, RFRST bits and clear FIFOs.

		SCFSR2 = 0x0000;		// clear Status Register.

		SCSCR2 = 0x0002;		// CKE1

		SCSMR2 = 0x0000;		// 8 bit data, non parity, 1 stop bit

//		SCBRR2  = 0x00;			// 

		BRG_DL  = 0x0006;		// 38400
//		BRG_DL  = 0x0002;		// 115200

		BRG_CKS = 0x0000;		// CKS = 0;

		SCFCR2  = 0x0000;		// Trigger count, receive = 1, transmit = 1.

		SCSCR2 |= 0x0032;		// Set TE, RE, CKE1

	}
}


//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugByte
//
//  Transmits a character out the debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch) 
{
	if (ENABLE_DEBUG_SERIAL)
	{
waitTX:
	if ((SCFSR2 & 0x0020)==0x20){
		SCFTDR2 = ch;
		SCFSR2 &= 0xFF9F;
		return;
	}
		goto waitTX;
	}
}


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

		if( !( SCFSR2 & 0x0002 ) )	// See if RDF = 1
		{
			DWORD dwWaitCount=8;
			while(dwWaitCount--);

			return OEM_DEBUG_READ_NODATA;
		}
		ch = SCFRDR2;
		SCFSR2 &= ~0x0002;		// Clear RDF
		return ch;
	}
	return (0);
}


//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugLED
//
//  Writes a pattern to the on-board hex LEDs.
//
void OEMWriteDebugLED(UINT16 Index, DWORD Pattern)
{
	WriteLED(Pattern);
}


//------------------------------------------------------------------------------
//
//  Function: OEMClearDebugCommError
//
//  Clears communications errors (flushes the serial FIFO).
//
void OEMClearDebugCommError(void) 
{
	if (ENABLE_DEBUG_SERIAL)
	{
		SCFSR2 &= ~0x0090;			// Clear ORER,PER,FER
	}
}


//------------------------------------------------------------------------------
/*****************************************************************************
*
*
*   @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++);
	}
}

⌨️ 快捷键说明

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