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

📄 serial.c

📁 Linux下的类似softice的调试工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/serial.c,v $ * $Revision: 1.5 $ * $Date: 2004/02/17 23:07:37 $ * $Author: lightweave $ * $Name:  $ * * $Log: serial.c,v $ * Revision 1.5  2004/02/17 23:07:37  lightweave * * Improved the DEBUG facillity and replaced the configuration handler with a * new code which now can read MS Windows INI style files. See CHANGES.txt for * more details. * Also added a macro which prevents compiling for kernels before 2.4.19. * * Revision 1.4  2003/06/18 22:00:22  lightweave * DEBUG and DEBUG_SERIAL added * * *****************************************************************************/static char *ident = "$Header: /cvsroot/pice/pice/module/serial.c,v 1.5 2004/02/17 23:07:37 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. GerlicherModule Name:    serial.cAbstract:    serial debugger connectionEnvironment:    LINUX 2.2.X    Kernel mode onlyAuthor:     Klaus P. GerlicherRevision History:    19-Aug-2000:	created    15-Nov-2000:    general cleanup of source filesCopyright notice:  This file may be distributed under the terms of the GNU Public License.--*/#include "remods.h"#include <asm/io.h>#include "precomp.h"#include "serial_port.h"BOOLEAN SerialReadByte(PUCHAR px);// used for SERIAL window creation// NB: at the moment the terminal is 60 lines high.WINDOW wWindowSerial[4]={	{1,3,1,0,FALSE},	{5,8,1,0,FALSE},	{14,26,1,0,FALSE},	{41,18,1,0,FALSE}};PUCHAR pScreenBufferSerial;USHORT usSerialPortBase;UCHAR packet[PAGE_SIZE];UCHAR assemble_packet[2*PAGE_SIZE];UCHAR flush_buffer[PAGE_SIZE],g_x,g_y;ULONG ulFlushBufferPos = 0;UCHAR ucLastKeyRead;ECOLORS eForegroundColor=WHITE,eBackgroundColor=BLACK;///************************************************************************// SerialSetSpeed()/////************************************************************************void SerialSetSpeed(ULONG baudrate){    UCHAR c;    ULONG divisor;    divisor = (ULONG) (115200L/baudrate);    c = inportb((USHORT)(usSerialPortBase + LCR));    outportb((USHORT)(usSerialPortBase + LCR), (UCHAR)(c | 0x80)); // Set DLAB     outportb((USHORT)(usSerialPortBase + DLL), (UCHAR)(divisor & 0x00FF));    outportb((USHORT)(usSerialPortBase + DLH), (UCHAR)((divisor >> 8) & 0x00FF));    outportb((USHORT)(usSerialPortBase + LCR), c);          // Reset DLAB }///************************************************************************// SerialSetOthers()//// Set other communications parameters //************************************************************************void SerialSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit){    ULONG setting;    UCHAR c;    if (usSerialPortBase == 0)					return ;    if (Bits < 5 || Bits > 8)				return ;    if (StopBit != 1 && StopBit != 2)			return ;    if (Parity != NO_PARITY && Parity != ODD_PARITY && Parity != EVEN_PARITY)							return;    setting  = Bits-5;    setting |= ((StopBit == 1) ? 0x00 : 0x04);    setting |= Parity;    c = inportb((USHORT)(usSerialPortBase + LCR));    outportb((USHORT)(usSerialPortBase + LCR), (UCHAR)(c & ~0x80)); // Reset DLAB     // no ints    outportb((USHORT)(usSerialPortBase + IER), (UCHAR)0);    // clear FIFO and disable them    outportb((USHORT)(usSerialPortBase + FCR), (UCHAR)0);     outportb((USHORT)(usSerialPortBase + LCR), (UCHAR)setting);    outportb((USHORT)(usSerialPortBase + MCR),  DTR | RTS);    return ;}///************************************************************************// FlushSerialBuffer()/////************************************************************************void FlushSerialBuffer(void){    UCHAR c;    while(SerialReadByte(&c));}///************************************************************************// SetupSerial()/////************************************************************************void SetupSerial(ULONG port,ULONG baudrate){	USHORT ports[]={COM1BASE,COM2BASE,COM3BASE,COM4BASE};    usSerialPortBase = ports[port-1];	SerialSetOthers(NO_PARITY,8,1);	SerialSetSpeed(baudrate);    // clear out received bytes    // else we would think there's a terminal connected    FlushSerialBuffer();}///************************************************************************// SerialReadByte()//// Output a character to the serial port //************************************************************************BOOLEAN SerialReadByte(PUCHAR px){    ULONG timeout;    timeout = 0x0FFFFL;    // Wait for transmitter to clear     while ((inportb((USHORT)(usSerialPortBase + LSR)) & RCVRDY) == 0)        if (!(--timeout))        {			return FALSE;        }    *px = inportb((USHORT)(usSerialPortBase + RXR));    return TRUE;}///************************************************************************// SerialSendByte()//// Output a character to the serial port //************************************************************************BOOLEAN SerialSendByte(UCHAR x){    ULONG timeout;    timeout = 0x00FFFFL;    // Wait for transmitter to clear     while ((inportb((USHORT)(usSerialPortBase + LSR)) & XMTRDY) == 0)        if (!(--timeout))        {			return FALSE;        }    outportb((USHORT)(usSerialPortBase + TXR), x);	return TRUE;}//************************************************************************// CheckSum()////************************************************************************UCHAR CheckSum(LPSTR p,ULONG Len){	UCHAR ucCheckSum = 0;	ULONG i;	for(i=0;i<Len;i++)	{		ucCheckSum ^= *p++;        ucCheckSum += 1;	}	return ucCheckSum;}///************************************************************************// ReadPacket()/////************************************************************************BOOLEAN ReadPacket(PSERIAL_PACKET p){    return TRUE;}///************************************************************************// SendPacket()/////************************************************************************BOOLEAN SendPacket(PSERIAL_PACKET p){    PUCHAR pHeader = (PUCHAR)&p->header;    ULONG i;    UCHAR c;    ULONG timeout;    do    {        timeout = 10;        pHeader = (PUCHAR)&p->header;        for(i=0;i<(sizeof(SERIAL_PACKET_HEADER)+p->header.packet_size);i++)        {            if(!SerialSendByte(*pHeader++))            {                return FALSE;            }        }        do        {            c = 0;                            SerialReadByte(&c);            if(c != ACK)                ucLastKeyRead = c;        }while(c != ACK && timeout--);    }while(c != ACK);        return TRUE;}///************************************************************************// SendPacketTimeout()/////************************************************************************BOOLEAN SendPacketTimeout(PSERIAL_PACKET p){    PUCHAR pHeader = (PUCHAR)&p->header;    ULONG i;    UCHAR c;    ULONG timeout = 10;    BOOLEAN bResult = TRUE;    pHeader = (PUCHAR)&p->header;    for(i=0;i<(sizeof(SERIAL_PACKET_HEADER)+p->header.packet_size);i++)    {        if(!SerialSendByte(*pHeader++))        {            return FALSE;        }    }    do    {        c = 0xFF;        SerialReadByte(&c);    }while(c != ACK && timeout--);    if(c != ACK)        bResult = FALSE;    return bResult;}//************************************************************************// AssemblePacket()////************************************************************************PSERIAL_PACKET AssemblePacket(PUCHAR pData,ULONG ulSize){    PSERIAL_PACKET p;    ULONG ulCheckSum;        p = (PSERIAL_PACKET)assemble_packet;        // compress data    // fill in header    p->header.packet_chksum = CheckSum(pData,ulSize);    p->header.packet_size = ulSize;    p->header.packet_header_chksum = 0;    ulCheckSum = (ULONG)CheckSum((PUCHAR)p,sizeof(SERIAL_PACKET_HEADER));    p->header.packet_header_chksum = ulCheckSum;    PICE_memcpy(p->data,pData,ulSize);             return p;}// OUTPUT handlers//*************************************************************************// SetForegroundColorVga()////*************************************************************************void SetForegroundColorSerial(ECOLORS col){    eForegroundColor = col;}

⌨️ 快捷键说明

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