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:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user