2013-01-08 22:40:58 +08:00
|
|
|
/*
|
2021-03-12 10:22:45 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2013-01-08 22:40:58 +08:00
|
|
|
*
|
2021-02-19 23:55:17 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-01-08 22:40:58 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-09-15 QiuYi the first version
|
2009-07-03 07:19:19 +08:00
|
|
|
* 2006-10-10 Bernard use keyboard instead of serial
|
2013-01-08 22:40:58 +08:00
|
|
|
*/
|
2021-02-19 23:55:17 +08:00
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
|
|
|
#include <bsp.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup QEMU
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function initializes serial
|
|
|
|
*/
|
|
|
|
void rt_serial_init(void)
|
|
|
|
{
|
2021-03-12 10:22:45 +08:00
|
|
|
outb(COM1+3,0x80); /* set DLAB of line control reg */
|
|
|
|
outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
|
|
|
|
outb(COM1+1,0x00); /* MS of divisor */
|
|
|
|
outb(COM1+3,0x03); /* reset DLAB */
|
|
|
|
outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
|
|
|
|
outb(COM1+1,0x0d); /* enable all intrs but writes */
|
|
|
|
inb(COM1); /* read data port to reset things (?) */
|
2013-01-08 22:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-12 10:22:45 +08:00
|
|
|
* This function read a character from serial without interrupt enable mode
|
2013-01-08 22:40:58 +08:00
|
|
|
*
|
|
|
|
* @return the read char
|
|
|
|
*/
|
|
|
|
char rt_serial_getc(void)
|
|
|
|
{
|
2021-02-19 23:55:17 +08:00
|
|
|
while(!(inb(COM1+COMSTATUS) & COMDATA));
|
2013-01-08 22:40:58 +08:00
|
|
|
|
2021-02-19 23:55:17 +08:00
|
|
|
return inb(COM1+COMREAD);
|
2013-01-08 22:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will write a character to serial without interrupt enable mode
|
|
|
|
*
|
|
|
|
* @param c the char to write
|
|
|
|
*/
|
|
|
|
void rt_serial_putc(const char c)
|
|
|
|
{
|
2021-02-19 23:55:17 +08:00
|
|
|
int val;
|
2021-03-12 10:22:45 +08:00
|
|
|
|
2021-02-19 23:55:17 +08:00
|
|
|
while(1)
|
|
|
|
{
|
2021-03-12 10:22:45 +08:00
|
|
|
if ((val = inb(COM1+COMSTATUS)) & THRE)
|
2021-02-19 23:55:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-03-12 10:22:45 +08:00
|
|
|
|
2021-02-19 23:55:17 +08:00
|
|
|
outb(COM1+COMWRITE, c&0xff);
|
2013-01-08 22:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|