serial.c

来自「国产CPU-龙芯(loongson)BIOS源代码」· C语言 代码 · 共 53 行

C
53
字号
#include <types.h>#define FCR_COM1_BASE 0x1f004090#define FCR_COM1_DATA  (FCR_COM1_BASE + 0x0)#define FCR_COM1_FCR   (FCR_COM1_BASE + 0x2)#define FCR_COM1_LSR   (FCR_COM1_BASE + 0x5)#define UART_SET(idx, value) KSEG1_STORE8(FCR_COM1_BASE + idx, value)#define UART_GET(idx) KSEG1_LOAD8(FCR_COM1_BASE + idx)static u8 init = 0;void init_serial(){    UART_SET(0x3, 0x80); /* LCR, set DLAB = 1 */    UART_SET(0x0, 0x6c); /* Crystal:16.6MHz, Baudrate = 9600bps ->0x6C  */    UART_SET(0x1, 0x00); /* Baudrate=9600. MSB should be 0 */    UART_SET(0x3, 0x0b); /* 8N1 */    UART_SET(0x2, 0x47); /* RCVR Trigger & FIFO Enable */}void serial_putc(u8 c){	u32 counter = 0x1000;	if (!init)	{		init_serial();		init = 1;	}	while ((counter--) && !(UART_GET(0x5) & 0x20));	if (counter)		UART_SET(0x0,c);}void serial_puts(u8 *buf){	u8 *p = NULL;	for (p = buf; *p != 0; p++)		serial_putc(*p);}void serial_put32(u32 value){	 char buf[11];	 buf[0] = '0';	 buf[1] = 'x';	 ctx(buf + 2, (value >> 24) & 0xff);	 ctx(buf + 4, (value >> 16) & 0xff);	 ctx(buf + 6, (value >> 8) & 0xff);	 ctx(buf + 8, value & 0xff);	 buf[10] = 0;	 serial_puts(buf);}

⌨️ 快捷键说明

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