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

📄 discouart.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
/* $Id: discouart.c,v 1.2 2003/06/11 13:08:36 pefo Exp $ *//* * Copyright (c) 2002 Opsycon AB  (www.opsycon.se) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <termio.h>#include <machine/pio.h>#include <machine/bus.h>#include <pmon.h>extern int getbaudval __P((int));int discouart (int op, struct DevEntry *dev, unsigned long param, int data);static intdiscoinit (volatile void *dp){	return 0;}static intdiscoprogram (volatile void *dp, unsigned long freq, int baudrate){#if 0static int rates[] = {	50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,	4800, 9600, 19200, 38400, 57600, 115200, 0 };	unsigned short brtc;	int timeout, *p;	/* wait for Tx fifo to completely drain */	timeout = 1000000;	while (!(inb(&dp->lsr) & LSR_TSRE)) {		if (--timeout == 0)			break;	}	baudrate = getbaudval (baudrate);	for (p = rates; *p; p++)		if (*p == baudrate)			break;	if (*p == 0)		return 1;	brtc = (freq) / (16*(baudrate));	outb(&dp->cfcr, CFCR_DLAB);	outb(&dp->data, brtc & 0xff);	outb(&dp->ier, brtc >> 8);	outb(&dp->cfcr, CFCR_8BITS);	outb(&dp->mcr, MCR_DTR | MCR_RTS);	outb(&dp->ier, 0);#endif	return 0;}intdiscouart (int op, struct DevEntry *dev, unsigned long param, int data){	volatile void *dp = (volatile void *) dev->sio;	int tmp;	switch (op) {		case OP_INIT:			tmp = (GTSYSCLK / (32 * CONS_BAUD) / 2) - 1;			GT_WRITE(BRG0_CFG_REG, 0x00210000 + tmp);			GT_WRITE(BRG0_BAUD_TUNING_REG, 0x0);			GT_WRITE(MPSC0_MAIN_CONFIGURATION_LOW, 0x04c4);			GT_WRITE(MPSC0_MAIN_CONFIGURATION_HIGH, 0x06400600);			GT_WRITE(MPSC0_PROTOCOL_CONFIGURATION, 0x00003000);			/* Kill any SDMA activity on this channel */			GT_WRITE(CHANNEL0_COMMAND_REGISTER, 0x00008000);			/* Setup debug tty */			GT_WRITE(CHANNEL0_REGISTER4, 0x20000000);			GT_WRITE(CHANNEL0_REGISTER5, 0x00009000);			GT_WRITE(CHANNEL0_REGISTER2,				 GT_READ(CHANNEL0_REGISTER2) | 0x80000000);			return discoinit (dp);		case OP_XBAUD:		case OP_BAUD:			return discoprogram (dp, dev->freq, data);		case OP_TXRDY:			return (!(GT_READ(CHANNEL0_REGISTER2) & 0x200));		case OP_TX:			GT_WRITE(CHANNEL0_REGISTER1, data);			GT_WRITE(CHANNEL0_REGISTER2,				 GT_READ(CHANNEL0_REGISTER2) | 0x200);			break;		case OP_RXRDY:			return(GT_READ(MPSC0_CAUSE) & 0x0040);		case OP_RX:			tmp = GT_READ(CHANNEL0_REGISTER10);			GT_WRITE(CHANNEL0_REGISTER10, tmp);			GT_WRITE(MPSC0_CAUSE, 0xffffffbf);			return (tmp >> 16) & 0xff;#if 0		case OP_RXSTOP:			if (data)				outb(&dp->mcr, inb(&dp->mcr) & ~MCR_RTS);			else				outb(&dp->mcr, inb(&dp->mcr) | MCR_RTS);			break;#endif	}	return 0;}

⌨️ 快捷键说明

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