|
|
|
@ -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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|