Max OS 0.3
Loading...
Searching...
No Matches
serial.cpp
Go to the documentation of this file.
1
10
11using namespace MaxOS;
12using namespace MaxOS::drivers;
13
19: m_data_port(0x3F8),
20 m_interrupt_enable_port(0x3F9),
21 m_fifo_control_port(0x3FA),
22 m_line_control_port(0x3FB),
23 m_modem_control_port(0x3FC),
24 m_line_status_port(0x3FD)
25{
26
27 // Disable all interrupts
28 m_interrupt_enable_port.write(0x00);
29
30 // Enable DLAB (set baud rate divisor)
31 m_line_control_port.write(0x80);
32
33 // Set divisor to 3
34 m_data_port.write(0x03);
35 m_interrupt_enable_port.write(0x00);
36
37 // 8 bits, no parity, one stop bit
38 m_line_control_port.write(0x03);
39
40 // Enable FIFO, clear them, with 14-byte threshold
41 m_fifo_control_port.write(0xC7);
42
43 // IRQs enabled, RTS/DSR set
44 m_modem_control_port.write(0x0B);
45
46 // Test serial chip
47 m_modem_control_port.write(0x1E);
48 m_data_port.write(0xAE);
49 if (m_data_port.read() != 0xAE)
50 return;
51
52 // Enable serial chip
53 m_modem_control_port.write(0x0F);
54
55 // Set the active serial console
56 logger->add_log_writer(this);
57}
58
59SerialConsole::~SerialConsole() = default;
60
67
68 // Wait for the serial port to be ready
69 while (0 == (m_line_status_port.read() & 0x20));
70
71 // Write the character
72 m_data_port.write(c);
73
74}
75
78}
A class that handles logging messages to the console and files.
Definition logger.h:44
void add_log_writer(OutputStream *log_writer)
Adds an output stream to the logger.
Definition logger.cpp:44
void write_char(char c) final
Writes a character to the output stream.
Definition serial.cpp:76
void put_character(char c)
Waits for the serial port to be ready, then writes a character to it.
Definition serial.cpp:66
SerialConsole(Logger *logger)
Constructs a new Serial Console object and initialises the serial port.
Definition serial.cpp:18
virtual uint8_t read()
read a byte from the port
Definition port.cpp:51
virtual void write(uint8_t data)
write a byte to the port
Definition port.cpp:41
Defines a SerialConsole driver for serial output.