refactor: one more step towards arch-agnostic design
[lunaix-os.git] / lunaix-os / kernel / peripheral / serial.c
index 69fb290942ed942c1e6b89041de942378f696481..516d569c088fe03836b57c33201ac2369dc74e12 100644 (file)
@@ -1,7 +1,7 @@
 #include <hal/cpu.h>
 #include <hal/cpu.h>
-#include <hal/io.h>
 #include <lunaix/peripheral/serial.h>
 #include <lunaix/syslog.h>
 #include <lunaix/peripheral/serial.h>
 #include <lunaix/syslog.h>
+#include <sys/port_io.h>
 
 LOG_MODULE("UART")
 
 
 LOG_MODULE("UART")
 
@@ -9,30 +9,30 @@ void
 serial_init_port(ptr_t port)
 {
     // disable interrupt, use irq instead
 serial_init_port(ptr_t port)
 {
     // disable interrupt, use irq instead
-    io_outb(COM_RIE(port), 0);
+    port_wrbyte(COM_RIE(port), 0);
 
     // baud rate config (DLAB = 1)
 
     // baud rate config (DLAB = 1)
-    io_outb(COM_RCLINE(port), 0x80);
-    io_outb(COM_RRXTX(port), BAUD_9600);
-    io_outb(COM_RIE(port), 0);
+    port_wrbyte(COM_RCLINE(port), 0x80);
+    port_wrbyte(COM_RRXTX(port), BAUD_9600);
+    port_wrbyte(COM_RIE(port), 0);
 
     // transmission size = 7bits, no parity, 1 stop bits
 
     // transmission size = 7bits, no parity, 1 stop bits
-    io_outb(COM_RCLINE(port), 0x2);
+    port_wrbyte(COM_RCLINE(port), 0x2);
 
     // rx trigger level = 14, clear rx/tx buffer, enable buffer
 
     // rx trigger level = 14, clear rx/tx buffer, enable buffer
-    io_outb(COM_RCFIFO(port), 0xcf);
+    port_wrbyte(COM_RCFIFO(port), 0xcf);
 
 
-    io_outb(COM_RCMODEM(port), 0x1e);
+    port_wrbyte(COM_RCMODEM(port), 0x1e);
 
 
-    io_outb(COM_RRXTX(port), 0xaa);
+    port_wrbyte(COM_RRXTX(port), 0xaa);
 
 
-    if (io_inb(COM_RRXTX(port)) != 0xaa) {
+    if (port_rdbyte(COM_RRXTX(port)) != 0xaa) {
         kprintf(KWARN "port.%p: faulty\n", port);
         return;
     }
 
         kprintf(KWARN "port.%p: faulty\n", port);
         return;
     }
 
-    io_outb(COM_RCMODEM(port), 0xf);
-    io_outb(COM_RIE(port), 0x1);
+    port_wrbyte(COM_RCMODEM(port), 0xf);
+    port_wrbyte(COM_RIE(port), 0x1);
     kprintf("port.%p: ok\n", port);
 }
 
     kprintf("port.%p: ok\n", port);
 }
 
@@ -48,10 +48,10 @@ serial_init()
 char
 serial_rx_byte(ptr_t port)
 {
 char
 serial_rx_byte(ptr_t port)
 {
-    while (!(io_inb(COM_RSLINE(port)) & 0x01))
+    while (!(port_rdbyte(COM_RSLINE(port)) & 0x01))
         ;
 
         ;
 
-    return io_inb(COM_RRXTX(port));
+    return port_rdbyte(COM_RRXTX(port));
 }
 
 void
 }
 
 void
@@ -65,10 +65,10 @@ serial_rx_buffer(ptr_t port, char* data, size_t len)
 void
 serial_tx_byte(ptr_t port, char data)
 {
 void
 serial_tx_byte(ptr_t port, char data)
 {
-    while (!(io_inb(COM_RSLINE(port)) & 0x20))
+    while (!(port_rdbyte(COM_RSLINE(port)) & 0x20))
         ;
 
         ;
 
-    io_outb(COM_RRXTX(port), data);
+    port_wrbyte(COM_RRXTX(port), data);
 }
 
 void
 }
 
 void
@@ -82,21 +82,21 @@ serial_tx_buffer(ptr_t port, char* data, size_t len)
 void
 serial_clear_fifo(ptr_t port)
 {
 void
 serial_clear_fifo(ptr_t port)
 {
-    io_outb(COM_RIE(port), 0x0);
-    io_outb(COM_RCFIFO(port), 0x00);
+    port_wrbyte(COM_RIE(port), 0x0);
+    port_wrbyte(COM_RCFIFO(port), 0x00);
 
 
-    io_outb(COM_RCFIFO(port), 0xcf);
-    io_outb(COM_RIE(port), 0x1);
+    port_wrbyte(COM_RCFIFO(port), 0xcf);
+    port_wrbyte(COM_RIE(port), 0x1);
 }
 
 void
 serial_disable_irq(ptr_t port)
 {
 }
 
 void
 serial_disable_irq(ptr_t port)
 {
-    io_outb(COM_RIE(port), 0x0);
+    port_wrbyte(COM_RIE(port), 0x0);
 }
 
 void
 serial_enable_irq(ptr_t port)
 {
 }
 
 void
 serial_enable_irq(ptr_t port)
 {
-    io_outb(COM_RIE(port), 0x1);
+    port_wrbyte(COM_RIE(port), 0x1);
 }
\ No newline at end of file
 }
\ No newline at end of file