start work on serial
This commit is contained in:
@@ -1,18 +1,23 @@
|
|||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
#include "ioport.h"
|
||||||
|
|
||||||
Serial::Serial(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
Serial::Serial(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
||||||
StopBits stop_bits, Parity parity)
|
StopBits stop_bits, Parity parity)
|
||||||
: port(port) {
|
: port(port) {
|
||||||
// initialize FIFO mode, no irqs for sending, irq if first byte was received
|
// 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
|
// line control, select r/w of divisor latch register
|
||||||
writeReg(LINE_CONTROL_REGISTER, DIVISOR_LATCH_ACCESS_BIT);
|
writeReg(LINE_CONTROL_REGISTER, DIVISOR_LATCH_ACCESS_BIT);
|
||||||
|
|
||||||
// TODO: Implement here the correct handling of input arguments
|
writeReg(DIVISOR_LOW_REGISTER, baud_rate & 0xFF);
|
||||||
(void)baud_rate;
|
writeReg(DIVISOR_HIGH_REGISTER, (baud_rate>>8) & 0xFF);
|
||||||
(void)data_bits;
|
|
||||||
(void)stop_bits;
|
// also turns DLAB off
|
||||||
(void)parity;
|
uint8_t val = parity;
|
||||||
|
val |= stop_bits;
|
||||||
|
val |= data_bits;
|
||||||
|
writeReg(LINE_CONTROL_REGISTER, val);
|
||||||
|
|
||||||
// FIFO: Enable & clear buffers
|
// FIFO: Enable & clear buffers
|
||||||
writeReg(FIFO_CONTROL_REGISTER,
|
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) {
|
void Serial::writeReg(RegisterIndex reg, char out) {
|
||||||
// TODO: Implement
|
uint16_t addr = port;
|
||||||
(void)reg;
|
IOPort iop = IOPort(addr += reg);
|
||||||
(void)out;
|
iop.outb(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
char Serial::readReg(RegisterIndex reg) {
|
char Serial::readReg(RegisterIndex reg) {
|
||||||
// TODO: Implement
|
uint16_t addr = port;
|
||||||
(void)reg;
|
IOPort iop = IOPort(addr += reg);
|
||||||
return '\0';
|
return iop.inb();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Serial::write(char out) {
|
int Serial::write(char out) {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
(void)out;
|
if(readReg(LINE_STATUS_REGISTER) & TRANSMITTER_EMPTY){
|
||||||
return 0;
|
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/cga.h"
|
||||||
#include "arch/textwindow.h"
|
#include "arch/textwindow.h"
|
||||||
|
#include "arch/serial.h"
|
||||||
|
|
||||||
// Main function
|
// Main function
|
||||||
// (the bootstrap processor starts here)}
|
// (the bootstrap processor starts here)}
|
||||||
@@ -19,19 +20,22 @@ extern "C" int main() {
|
|||||||
//for(uint8_t i = 0; i < 10; i++)
|
//for(uint8_t i = 0; i < 10; i++)
|
||||||
// CGA::show(i, i, i+0x30, CGA::Attribute());
|
// CGA::show(i, i, i+0x30, CGA::Attribute());
|
||||||
|
|
||||||
//test textwindow implemantation
|
////test textwindow implemantation
|
||||||
TextWindow tw_global = TextWindow(0, 80, 0, 25, true);
|
//TextWindow tw_global = TextWindow(0, 80, 0, 25, true);
|
||||||
tw_global.reset(' ', CGA::Attribute(CGA::LIGHT_GREEN, CGA::BLUE, false));
|
//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);
|
//test Serial
|
||||||
tw.reset();
|
Serial s = Serial();
|
||||||
tw.setPos(0,0);
|
s.write('a');
|
||||||
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);
|
|
||||||
|
|
||||||
/* Start application processors
|
/* Start application processors
|
||||||
* To avoid unexpected behaviour, make sure that interrupts are not
|
* To avoid unexpected behaviour, make sure that interrupts are not
|
||||||
|
|||||||
Reference in New Issue
Block a user