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

📄 ns16550.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
#include <termio.h>#include <machine/bus.h>#include "target/ns16550.h"#include <pmon.h>extern int getbaudval __P((int));int ns16550 __P((int, char *, int, int));static intnsinit (volatile ns16550dev *dp, int chan){#if 0static int nsfifo;    unsigned int x;    /* force access to id reg */    outb(&dp->cfcr,0);    outb(&dp->iir, 0);    if ((inb(&dp->iir) & 0x38) != 0) {	return 1;    }    /* in case it really is a 16550, enable the fifos */    outb(&dp->fifo, FIFO_ENABLE);    for(x = 0; x < 1000000; x++);    outb(&dp->fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);    for(x = 0; x < 1000000; x++);    if ((inb(&dp->iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK)	nsfifo = 1;    else {	dp->fifo = 0;    }#endif    return 0;}static intnsprogram (volatile ns16550dev *dp, int chan, int baudrate){#if 0    unsigned short brtc;    int timeout;    /* wait for Tx fifo to completely drain */    timeout = 10000;    while (!(inb(&dp->lsr) & LSR_TSRE))	if (--timeout == 0)	    break;    baudrate = getbaudval (baudrate);    if (baudrate == 0)      return 1;    brtc = BRTC (baudrate);    outb(&dp->cfcr, CFCR_DLAB);    outb(&dp->data, brtc & 0xff);    outb(&dp->ier, brtc >> 8);    outb(&dp->cfcr, CFCR_8BITS);#if 0    outb(&dp->mcr, MCR_DTR | MCR_RTS | MCR_IENABLE);#endif    outb(&dp->ier, 0);#endif    return 0;}intns16550 (int op, char *dat, int chan, int data){    volatile ns16550dev *dp = (ns16550dev *) dat;    if (chan > 0)	return 1;    switch (op) {    case OP_INIT:	return nsinit (dp, chan);    case OP_XBAUD:    case OP_BAUD:	return nsprogram (dp, chan, data);    case OP_TXRDY:	return (inb(&dp->lsr) & LSR_TXRDY);    case OP_TX:	outb(&dp->data, data);	break;    case OP_RXRDY:	return (inb(&dp->lsr) & LSR_RXRDY);    case OP_RX:	return inb(&dp->data) & 0xff;    case OP_RXSTOP:	if (data)	    outb(&dp->mcr, inb(&dp->mcr) & ~MCR_RTS);	/* disable Rx */	else	    outb(&dp->mcr, inb(&dp->mcr) | MCR_RTS);	/* enable Rx */	break;    }    return 0;}

⌨️ 快捷键说明

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