Max OS 0.3
Loading...
Searching...
No Matches
serial.cpp
Go to the documentation of this file.
1
9#include <console/serial.h>
10#include <runtime/gdbstub.h>
11
12using namespace MaxOS;
13using namespace MaxOS::runtime;
14using namespace MaxOS::console;
15
20: m_data_port(0x3F8),
21 m_interrupt_enable_port(0x3F9),
22 m_fifo_control_port(0x3FA),
23 m_line_control_port(0x3FB),
24 m_modem_control_port(0x3FC),
25 m_line_status_port(0x3FD)
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(0x07);
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 // Enable interrupts
56 m_interrupt_enable_port.write(0x01);
57
58 // Clear any prexisting state
59 m_fifo_control_port.read();
60 while (can_read())
61 read_char();
62}
63
71{
72 // Set the active serial console
73 if (!DO_DEBUGGING)
74 logger->add_log_writer(this);
75}
76
77SerialConsole::~SerialConsole() = default;
78
85
86 // Wait for the serial port to be ready
87 while (0 == (m_line_status_port.read() & 0x20));
88
89 // Write the character
90 m_data_port.write(c);
91
92}
93
100 put_character(c);
101}
102
109 return m_line_status_port.read() & 1;
110}
111
118 return m_data_port.read();
119}
A class that handles logging messages to the console and files.
Definition logger.h:51
void add_log_writer(OutputStream *log_writer)
Adds an output stream to the logger.
Definition logger.cpp:44
A driver for the serial output.
Definition serial.h:25
char read_char()
Read data from the serial port.
Definition serial.cpp:117
void write_char(char c) final
Waits for the serial port to be ready, then writes a character to it.
Definition serial.cpp:99
void put_character(char c)
Waits for the serial port to be ready, then writes a character to it.
Definition serial.cpp:84
bool can_read()
Checks if data can be read from the serial port.
Definition serial.cpp:108
SerialConsole()
Constructs a new Serial Console object and initialises the serial port.
Definition serial.cpp:19
GDB Stub definition for remote debugging userspace processes.
constexpr bool DO_DEBUGGING
Whether to use the serial for GDB communcation or for logging.
Definition gdbstub.h:26
Defines a SerialConsole driver for serial output.