diff --git a/arch/serial.cc b/arch/serial.cc index 0f79b16..2a6b2bc 100644 --- a/arch/serial.cc +++ b/arch/serial.cc @@ -1,18 +1,23 @@ #include "serial.h" +#include "ioport.h" Serial::Serial(ComPort port, BaudRate baud_rate, DataBits data_bits, StopBits stop_bits, Parity parity) : port(port) { // initialize FIFO mode, no irqs for sending, irq if first byte was received + writeReg(INTERRUPT_ENABLE_REGISTER, RECEIVED_DATA_AVAILABLE); // line control, select r/w of divisor latch register writeReg(LINE_CONTROL_REGISTER, DIVISOR_LATCH_ACCESS_BIT); - // TODO: Implement here the correct handling of input arguments - (void)baud_rate; - (void)data_bits; - (void)stop_bits; - (void)parity; + writeReg(DIVISOR_LOW_REGISTER, baud_rate & 0xFF); + writeReg(DIVISOR_HIGH_REGISTER, (baud_rate>>8) & 0xFF); + + // also turns DLAB off + uint8_t val = parity; + val |= stop_bits; + val |= data_bits; + writeReg(LINE_CONTROL_REGISTER, val); // FIFO: Enable & clear buffers writeReg(FIFO_CONTROL_REGISTER, @@ -23,19 +28,22 @@ Serial::Serial(ComPort port, BaudRate baud_rate, DataBits data_bits, } void Serial::writeReg(RegisterIndex reg, char out) { - // TODO: Implement - (void)reg; - (void)out; + uint16_t addr = port; + IOPort iop = IOPort(addr += reg); + iop.outb(out); } char Serial::readReg(RegisterIndex reg) { - // TODO: Implement - (void)reg; - return '\0'; + uint16_t addr = port; + IOPort iop = IOPort(addr += reg); + return iop.inb(); } int Serial::write(char out) { // TODO: Implement - (void)out; - return 0; + if(readReg(LINE_STATUS_REGISTER) & TRANSMITTER_EMPTY){ + writeReg(TRANSMIT_BUFFER_REGISTER, out); + return out; + } + return -1; } diff --git a/main.cc b/main.cc index fe0bcef..29a6d64 100644 --- a/main.cc +++ b/main.cc @@ -4,6 +4,7 @@ #include "arch/cga.h" #include "arch/textwindow.h" +#include "arch/serial.h" // Main function // (the bootstrap processor starts here)} @@ -19,19 +20,22 @@ extern "C" int main() { //for(uint8_t i = 0; i < 10; i++) // CGA::show(i, i, i+0x30, CGA::Attribute()); - //test textwindow implemantation - TextWindow tw_global = TextWindow(0, 80, 0, 25, true); - tw_global.reset(' ', CGA::Attribute(CGA::LIGHT_GREEN, CGA::BLUE, false)); - - TextWindow tw = TextWindow(0, 10, 0, 10, true); - tw.reset(); - tw.setPos(0,0); - tw.print("lorem ipsum dolor sit amit", 26); - tw.setPos(0,-1); - tw.print("test", 4, CGA::Attribute(CGA::BLACK, CGA::BLUE)); - int x,y; - tw.getPos(x,y); - tw.setPos(x+1,y); + ////test textwindow implemantation + //TextWindow tw_global = TextWindow(0, 80, 0, 25, true); + //tw_global.reset(' ', CGA::Attribute(CGA::LIGHT_GREEN, CGA::BLUE, false)); + //TextWindow tw = TextWindow(0, 10, 0, 10, true); + //tw.reset(); + //tw.setPos(0,0); + //tw.print("lorem ipsum dolor sit amit", 26); + //tw.setPos(0,-1); + //tw.print("test", 4, CGA::Attribute(CGA::BLACK, CGA::BLUE)); + //int x,y; + //tw.getPos(x,y); + //tw.setPos(x+1,y); + + //test Serial + Serial s = Serial(); + s.write('a'); /* Start application processors * To avoid unexpected behaviour, make sure that interrupts are not