Created a proper driver for the serial bus

* The driver can write to any of the pre-defined serial COM ports
* The driver can read from any of the pre-defined serial COM ports (Untested)
This commit is contained in:
2023-10-28 21:51:04 +02:00
parent 2522492835
commit 9c5667c454
5 changed files with 87 additions and 89 deletions

View File

@ -1,19 +1,52 @@
#include "serial.h"
#include "../../io/io.h"
Serial Serial::init() {
// No clue what to setup yet!
// Initializes communication according to the spec given
Serial::Serial(SerialConfig config) {
port = config.port;
// Disable interrupts
outb(config.port + 1, 0x00);
return Serial();
// Enable DLAB
outb(config.port + 3, 0x80);
// set the baudrate
outb(config.port + 0, 0x03);
outb(config.port + 1, 0x00);
// configure for 8bits, no parity, one stop bit
outb(config.port + 3, 0x03);
// Enable FIFO, clear them, with 14-byte threshhold
outb(config.port + 2, 0xC7);
// Enable IRQ's, RTS/DSR set
outb(config.port + 4, 0x0B );
// Set in loopback mode, test the serial chip.
outb(config.port + 4, 0x1E);
// TEST
outb(config.port + 0 , 0xAE);
if(inb(config.port + 0) != 0xAE)
return ; // FAIL
outb(config.port + 4, 0x0F);
return ;
}
void Serial::print(){
// Do nothing!
void Serial::write(void* data, int len) {
while (is_transmit_empty() == 0); // Wait for transmit queue to be free
for (int i = 0; i < len ; i++){
outb(port, ((uint8_t*)data)[i]);
}
}
Serial::Serial(){
// Do nothing!
char Serial::read() {
return inb(port);
}
Serial::~Serial(){
// Do nothing!
}
int Serial::is_transmit_empty() {
return inb(port + 5) & 0x20;
}

View File

@ -1,19 +1,29 @@
#pragma once
// For now these are the standard
// serial ports we can talk to
enum SERIALPORT {
COM1 = 0x3F8,
COM2 = 0x2F8,
COM3 = 0x3E8,
COM4 = 0x2E8
};
class Serial {
struct SerialConfig {
SERIALPORT port;
char baud_rate_lo ;
char baud_rate_hi;
};
class Serial {
public:
static Serial init();
void print();
Serial (SerialConfig config );
private:
const int COM1 = 0x3F8;
const int COM2 = 0x2F8;
const int COM3 = 0x3E8;
const int COM4 = 0x2E8;
char read();
void write(void* data, int length);
Serial();
~Serial();
private:
SERIALPORT port;
int is_transmit_empty();
};