x86_64: serial: enable interrupts and announce incoming data
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <socks/console.h>
|
||||
#include <arch/irq.h>
|
||||
#include <socks/printk.h>
|
||||
#include <socks/panic.h>
|
||||
#include <arch/serial.h>
|
||||
@@ -33,6 +34,20 @@ void serial_send_byte(int device, char out)
|
||||
}
|
||||
}
|
||||
|
||||
char serial_recv_byte(int device)
|
||||
{
|
||||
volatile unsigned int _count = 0;
|
||||
while (!serial_received(device)) {
|
||||
_count++;
|
||||
}
|
||||
|
||||
char c = inportb(device);
|
||||
|
||||
outportb(device + 5, inportb(device + 5) & ~0x1);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void serial_putchar(int port, char ch)
|
||||
{
|
||||
if (ch == '\n') {
|
||||
@@ -100,12 +115,12 @@ static void init_serial_port(int port, int baud)
|
||||
|
||||
// Check if serial is faulty (i.e: not same byte as sent)
|
||||
if(inportb(port + 0) != 0xAE) {
|
||||
panic("serial: port %x init failed", port);
|
||||
return;
|
||||
}
|
||||
|
||||
// If serial is not faulty set it in normal operation mode
|
||||
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
|
||||
outportb(port + 1, 0x01);
|
||||
outportb(port + 4, 0x0F);
|
||||
printk("serial: port %x initialised", port);
|
||||
}
|
||||
@@ -117,8 +132,28 @@ static struct console serialcon = {
|
||||
.c_lock = SPIN_LOCK_INIT,
|
||||
};
|
||||
|
||||
static int serial_irq1(void)
|
||||
{
|
||||
if (serial_received(COM1)) {
|
||||
unsigned char c = serial_recv_byte(COM1);
|
||||
printk("serial: COM1 received %c", c);
|
||||
}
|
||||
|
||||
if (serial_received(COM3)) {
|
||||
unsigned char c = serial_recv_byte(COM3);
|
||||
printk("serial: COM3 received %c", c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct irq_hook irq1_hook = {
|
||||
.irq_callback = serial_irq1,
|
||||
};
|
||||
|
||||
void serialcon_init(int baud)
|
||||
{
|
||||
hook_irq(IRQ4, &irq1_hook);
|
||||
init_serial_port(COM1, baud);
|
||||
console_register(&serialcon);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user