add btrie_map() for allocating free slot, remove isrm
[lunaix-os.git] / lunaix-os / hal / char / uart / 16x50_pmio.c
1 /**
2  * @file 16550_pmio.c
3  * @author Lunaixsky (lunaxisky@qq.com)
4  * @brief 16550 UART with port mapped IO
5  * @version 0.1
6  * @date 2023-08-30
7  *
8  * @copyright Copyright (c) 2023
9  *
10  */
11 #include <lunaix/device.h>
12
13 #include <asm/x86_pmio.h>
14
15 #include "16x50.h"
16
17 #define DELAY 50
18
19 static u32_t
20 com_regread(struct uart16550* uart, ptr_t regoff)
21 {
22     u8_t val = port_rdbyte(uart->base_addr + regoff);
23     port_delay(DELAY);
24
25     return (u32_t)val;
26 }
27
28 static void
29 com_regwrite(struct uart16550* uart, ptr_t regoff, u32_t val)
30 {
31     port_wrbyte(uart->base_addr + regoff, (u8_t)val);
32     port_delay(DELAY);
33 }
34
35
36 struct uart16550*
37 uart16x50_pmio_create(ptr_t base)
38 {
39     struct uart16550* uart;
40
41     uart = uart_alloc(base);
42     uart->read_reg = com_regread;
43     uart->write_reg = com_regwrite;
44
45     if (!uart_testport(uart, 0xe3)) {
46         uart_free(uart);
47         return NULL;
48     }
49
50     uart_enable_fifo(uart, UART_FIFO8);
51
52     return uart;
53 }