debug.c.org
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· ORG 代码 · 共 568 行 · 第 1/2 页
ORG
568 行
/*****************************************************************************
*
* File: debug.c
* Author: Naresh Gupta (nkgupta@hotmail.com)
* Purpose: Debug serial port routines for SCI and SCIF.
* Copyright (c) 1999 Hitachi,Ltd.
*
****************************************************************************/
#include <windows.h>
#include <ethdbg.h>
#include <halether.h>
#include "platform.h"
#include "nkintr.h"
#include "drv_glob.h"
#define SCI 1
#define SCIF 2
#define MHz 1000000 // 10 ** 6.
/*
* FLOW_CONTROL: Define this for the type of Flow control you want to use
* on SCIF
*
* 0 No Flow Control
* 1 Hardware Flow Control
* 2 Software Flow Control
*/
#define FLOW_NONE 0
#define FLOW_HW 1
#define FLOW_SW 2
/****************************************************************************
* User Modifiable parametes.
****************************************************************************/
/*
* 1. What is the BAUD_RATE ?
*
* 2. which serial port you want the output to go to ?
* Options are :-
* SCI : Output would go to SCI
* SCIF : Output would go to SCIF
* (SCI | SCIF) : For output to go to both. Input would be from SCI
*
* 3. SystemClockFreq
*/
#if (SH_PLATFORM == PLATFORM_ASPEN)
# define BAUD_RATE 57600 // 57600 // 38400 // 115200
# define DEBUG_SERIAL_PORT (SCIF)
# define SystemClockFreq (33 * MHz) // (16.5 * MHz) // 33 MHz.
#elif (SH_PLATFORN == PLATFORM_BIGSUR)
# define BAUD_RATE 57600 // 57600 // 38400 // 115200
# define DEBUG_SERIAL_PORT (SCIF)
# define SystemClockFreq (33 * MHz) // 33 MHz.
#else
# define BAUD_RATE 38400 // 38400 // 115200
# define DEBUG_SERIAL_PORT (SCI)
# define SystemClockFreq (33 * MHz) // 33 MHz.
#endif
#define FLOW_CONTROL 0
/*
* USE_EDBG_SERVICES:
* Define this if you want to boot Wince with Debug Ethernet support
*/
#define USE_EDBG_SERVICES 1
/****************************************************************************
* End of User Modifiable parametes.
****************************************************************************/
/* Stuff related to Debug Ethernet */
#ifdef USE_EDBG_SERVICES
#define pDriverGlobals ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)
static BOOL DebugEtherPresent;
#endif USE_EDBG_SERVICES
// Registers related to SCI
#define SCSMR *(UCHAR volatile *)(0xFFE00000)
#define SCBRR *(UCHAR volatile *)(0xFFE00004)
#define SCSCR *(UCHAR volatile *)(0xFFE00008)
#define SCTDR *(UCHAR volatile *)(0xFFE0000C)
#define SCSSR *(UCHAR volatile *)(0xFFE00010)
#define SCRDR *(UCHAR volatile *)(0xFFE00014)
#define SCSCMR *(UCHAR volatile *)(0xFFE00018)
#define SCSPTR *(UCHAR volatile *)(0xFFE0001C)
// Bit fields of Serial Status Register.
#define SCI_TDRE 0x80
#define SCI_RDRF 0x40
#define SCI_ORER 0x20
#define SCI_FER 0x10
#define SCI_PER 0x08
#define SCI_TEND 0x04
#define SCI_MPB 0x02
#define SCI_MPBT 0x01
// Registers related to SCIF
#define SCSMR2 *(USHORT volatile *)(0xFFE80000)
#define SCBRR2 *(UCHAR volatile *)(0xFFE80004)
#define SCSCR2 *(USHORT volatile *)(0xFFE80008)
#define SCFTDR2 *(UCHAR volatile *)(0xFFE8000C)
#define SCFSR2 *(USHORT volatile *)(0xFFE80010)
#define SCFRDR2 *(UCHAR volatile *)(0xFFE80014)
#define SCFCR2 *(USHORT volatile *)(0xFFE80018)
#define SCFDR2 *(USHORT volatile *)(0xFFE8001C)
#define SCSPTR2 *(USHORT volatile *)(0xFFE80020)
#define SCLSR2 *(USHORT volatile *)(0xFFE80024)
// Bit fields for Serial Status Register on SCIF
#define SCIF_ER 0x80
#define SCIF_TEND 0x40
#define SCIF_TDFE 0x20
#define SCIF_BRK 0x10
#define SCIF_FER 0x08
#define SCIF_PER 0x04
#define SCIF_RDF 0x02
#define SCIF_DR 0x01
#define SCIF_ORER 0x01 // in SCLSR2
/* Baud rate setting is calculated according to the following formula :-
* N = P * 10**6 / (64 * 2 ** (2n - 1) * B) -1
*/
#define cks 0.5 // 2**(2n-1) value for clock source P.
#define ceil(x) ((x > (float)(int)x) ? ((int)x + 1) : ((int) x))
#define brr(bps) ceil(((float)SystemClockFreq/(64 * cks * bps)) -1)
// I prefer keeping the current baud rate in a variable instead of using this
// formula because this formula may give a slightly different baud rate
// due to the rouding off done earlier.
#define brr2baud(N) ( ((float)SystemClockFreq)/(64 * cks * (N+1)) )
// Function prototypes.
void OutputFormatString(const unsigned char *sz, ...);
void OEMWriteDebugByte(UCHAR ch);
void HandleError(int port);
// This will keep the CurrentBaudRate.
static int CurrentBaudRate;
#if 0
//***********************************************************************
// [ITE] Cash 19971225
// I don't know why. When initilize SCI port must insert delay
// routine for SH7750. SH7709 do not need.
// Maybe check timming!!
//***********************************************************************
void DummyDelay(void)
{ unsigned int i;
for(i=0;i<0x00001;i++);
}
#endif
/* This routine sets the baud rate to the specified value and returns the
* new baud rate.
* If the input is 0, it just returns the current baud rate.
*/
int OEMSetDebugSerialBaudRate(unsigned baud)
{
if(baud == 0)
return CurrentBaudRate;
if (DEBUG_SERIAL_ON) {
if(DEBUG_SERIAL_PORT & SCI) {
// OutputFormatString("New Value of SCBRR = 0x%x, Old Value = 0x%x\n", brr(baud), SCBRR);
SCBRR = brr(baud);
CurrentBaudRate = baud;
}
if(DEBUG_SERIAL_PORT & SCIF) {
// OutputFormatString("New Value of SCBRR2 = 0x%x, Old Value = 0x%x\n", brr(baud), SCBRR);
SCBRR2 = brr(baud);
CurrentBaudRate = baud;
}
}
return CurrentBaudRate;
}
/*****************************************************************************
*
*
* @func void | OEMInitDebugSerial | Initialize debug monitor port.
*
* NOTE: This function MUST NOT use any global variables!!!!!!
*/
void OEMInitDebugSerial(void)
{
WRITE_REGISTER_UCHAR(ALPHA_LED, 46);
if (DEBUG_SERIAL_ON) {
if(DEBUG_SERIAL_PORT & SCI) {
SCSCR = 0x00;
SCSMR = 0x00; /* n=0 */
// NKCH: tried to increase baud rate.
// BRR for 33 MHz peripheral bus :-
// 38400: 0x1A
// 57600: 0x11
// 115200: 0x08: Fastest mode that works.
// 230400: 0x03
SCBRR = brr(BAUD_RATE);
CurrentBaudRate = BAUD_RATE;
// You need to wait for 1 bit time. To be on the safe side wait for
// longer duration
{
int i = 100000;
while(i--);
}
SCSCR = 0x30; /* TE,RE enabled */
#if 0
SCTDR = 0x41;
SCSSR = 0x80;
DummyDelay();
SCRDR = 0x00;
DummyDelay();
SCSPTR = 0;
#endif
}
if(DEBUG_SERIAL_PORT & SCIF) {
unsigned current;
SCSCR2 = 0x0000;
SCFCR2 = 0x06; // Reset FIFOs
SCSCR2 = 0x0000;
SCSMR2 = 0x0000; // 8N1. n = 0;
#ifdef ASPEN
current = SCBRR2;
if( (current == 8) || (current == 0x11)) {
/* Hopefull we booted from CMON. No need to change SCBRR2. */
} else {
SCBRR2 = brr(BAUD_RATE);
}
#else ASPEN
SCBRR2 = brr(BAUD_RATE);
#endif ASPEN
// #ifdef ASPEN
// SCBRR2 = 0x8;
// #endif ASPEN
CurrentBaudRate = BAUD_RATE;
// You need to wait for 1 bit time. To be on the safe side wait for
// longer duration
{
int i = 100000;
while(i--);
}
#if (!defined(FLOW_CONTROL) || (FLOW_CONTROL == FLOW_NONE))
SCFCR2 = 0x00;
#endif (FLOW_CONTROL == FLOW_NONE)
#if (FLOW_CONTROL == FLOW_HW)
SCFCR2 = 0x08; // MCE: Modem control enable. Use CTS, RTS
#endif (FLOW_CONTROL == FLOW_HW)
SCFSR2 = 0x00;
// SCFCR2 = 0x00; // Reset FIFOs
SCSCR2 |= 0x0030;
}
}
/* Add support for Ethernet Debug Services. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?