start work on serial
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
28
main.cc
28
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));
|
||||
////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);
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user