jankos/serial.c
shockrah 897c23faca # Serial port configurations
* Implementing some serial port control in preparation to do debugging with bochs

* Changed naming of io to fb_ports to finally[tm] ports
2019-10-05 20:45:22 -07:00

39 lines
1.0 KiB
C

#include "serial.h"
/*
* SERIAL_LINE_COMMAND_PORT configuration
* Bit: | 7 | 6 | 5 4 3 | 2 | 1 0 |
* Content: | d | b | prty | s | dl |
* d = enable/disable DLAB
* b = enable/disable break control
* prty = # of parity bits to use
* s = # no of stop bits [0 is 1] and [1 is 1.5 or 2]
* dl = length of data
*
*/
void serial_set_buad_rate(const u16 com_port, const u16 divisor) {
// Activate line - ready to send higher 8 bits of data
// send the higher 8 bits first
// send the lower 8 bits next
serial_control(SERIAL_LINE_COMMAND_PORT(com_port),
SERIAL_LINE_ENABLE);
serial_control(SERIAL_DATA_PORT(com_port),
(divisor>>8) & 0x00ff);
serial_control(SERIAL_DATA_PORT(com_port),
divisor & 0x00ff);
}
// Payload described above
void serial_configure_line(const u16 line, const u8 payload) {
serial_control(SERIAL_LINE_COMMAND_PORT(line), payload);
}
u8 serial_fifo_empty(const u16 com_port) {
// If the 5th bit is set then we know that the fifo queue is empty
return serial_read_buffer(SERIAL_LINE_STATUS_PORT(com_port)) & 0x20;
}