New rewritten serial driver + dev interface
This commit is contained in:
42
kernel/drivers/serial/serial.c
Normal file
42
kernel/drivers/serial/serial.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <stdint.h>
|
||||
#include "hal/hal.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
// https://wiki.osdev.org/Serial_Ports
|
||||
|
||||
#define PORT 0x3f8
|
||||
|
||||
void serial_init(void) {
|
||||
io_out8(PORT+1, 0x00);
|
||||
io_out8(PORT+3, 0x80);
|
||||
io_out8(PORT+0, 0x03);
|
||||
io_out8(PORT+1, 0x00);
|
||||
io_out8(PORT+3, 0x03);
|
||||
io_out8(PORT+2, 0xC7);
|
||||
io_out8(PORT+4, 0x0B);
|
||||
io_out8(PORT+4, 0x1E);
|
||||
io_out8(PORT+0, 0xAE);
|
||||
|
||||
if (io_in8(PORT+0) != 0xAE) {
|
||||
ERR("serial", "serial is faulty!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
io_out8(PORT+4, 0x0F);
|
||||
}
|
||||
|
||||
int serial_recvready(void) {
|
||||
return io_in8(PORT+5) & 1;
|
||||
}
|
||||
|
||||
uint8_t serial_recvb(void) {
|
||||
return io_in8(PORT);
|
||||
}
|
||||
|
||||
int serial_sendready(void) {
|
||||
return io_in8(PORT+5) & 0x20;
|
||||
}
|
||||
|
||||
void serial_sendb(uint8_t b) {
|
||||
io_out8(PORT, b);
|
||||
}
|
12
kernel/drivers/serial/serial.h
Normal file
12
kernel/drivers/serial/serial.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef DRIVERS_SERIAL_SERIAL_H_
|
||||
#define DRIVERS_SERIAL_SERIAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void serial_init(void);
|
||||
int serial_recvready(void);
|
||||
uint8_t serial_recvb(void);
|
||||
int serial_sendready(void);
|
||||
void serial_sendb(uint8_t b);
|
||||
|
||||
#endif // DRIVERS_SERIAL_SERIAL_H_
|
Reference in New Issue
Block a user