1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2006-09-15 QiuYi the first version
9 * 2006-10-10 Bernard use keyboard instead of serial
10 */
11
12 #include <rtthread.h>
13 #include <rthw.h>
14
15 #include <bsp.h>
16
17 /**
18 * @addtogroup QEMU
19 */
20 /*@{*/
21
22 /**
23 * This function initializes serial
24 */
rt_serial_init(void)25 void rt_serial_init(void)
26 {
27 outb(COM1+3,0x80); /* set DLAB of line control reg */
28 outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
29 outb(COM1+1,0x00); /* MS of divisor */
30 outb(COM1+3,0x03); /* reset DLAB */
31 outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
32 outb(COM1+1,0x0d); /* enable all intrs but writes */
33 inb(COM1); /* read data port to reset things (?) */
34 }
35
36 /**
37 * This function read a character from serial without interrupt enable mode
38 *
39 * @return the read char
40 */
rt_serial_getc(void)41 char rt_serial_getc(void)
42 {
43 while(!(inb(COM1+COMSTATUS) & COMDATA));
44
45 return inb(COM1+COMREAD);
46 }
47
48 /**
49 * This function will write a character to serial without interrupt enable mode
50 *
51 * @param c the char to write
52 */
rt_serial_putc(const char c)53 void rt_serial_putc(const char c)
54 {
55 int val;
56
57 while(1)
58 {
59 if ((val = inb(COM1+COMSTATUS)) & THRE)
60 break;
61 }
62
63 outb(COM1+COMWRITE, c&0xff);
64 }
65
66 /*@}*/
67