Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::console::SerialConsole Class Reference

A driver for the serial output. More...

#include <serial.h>

Inheritance diagram for MaxOS::console::SerialConsole:

Public Member Functions

 SerialConsole ()
 Constructs a new Serial Console object and initialises the serial port.
 
 SerialConsole (Logger *logger)
 Constructs a new Serial Console object and initialises the serial port.
 
void put_character (char c)
 Waits for the serial port to be ready, then writes a character to it.
 
void write_char (char c) final
 Waits for the serial port to be ready, then writes a character to it.
 
bool can_read ()
 Checks if data can be read from the serial port.
 
char read_char ()
 Read data from the serial port.
 

Detailed Description

A driver for the serial output.

Definition at line 25 of file serial.h.

Constructor & Destructor Documentation

◆ SerialConsole() [1/2]

SerialConsole::SerialConsole ( )
explicit

Constructs a new Serial Console object and initialises the serial port.

Definition at line 19 of file serial.cpp.

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}
char read_char()
Read data from the serial port.
Definition serial.cpp:117
bool can_read()
Checks if data can be read from the serial port.
Definition serial.cpp:108

References can_read(), and read_char().

◆ SerialConsole() [2/2]

SerialConsole::SerialConsole ( Logger *  logger)
explicit

Constructs a new Serial Console object and initialises the serial port.

Parameters
loggerThe logger which will use this serial console as a log writer

Definition at line 69 of file serial.cpp.

71{
72 // Set the active serial console
73 if (!DO_DEBUGGING)
74 logger->add_log_writer(this);
75}
void add_log_writer(OutputStream *log_writer)
Adds an output stream to the logger.
Definition logger.cpp:44
SerialConsole()
Constructs a new Serial Console object and initialises the serial port.
Definition serial.cpp:19

References MaxOS::Logger::add_log_writer(), and MaxOS::runtime::DO_DEBUGGING.

Member Function Documentation

◆ can_read()

bool SerialConsole::can_read ( )

Checks if data can be read from the serial port.

Returns
True if data is ready to be read

Definition at line 108 of file serial.cpp.

108 {
109 return m_line_status_port.read() & 1;
110}

Referenced by SerialConsole().

◆ put_character()

void SerialConsole::put_character ( char  c)

Waits for the serial port to be ready, then writes a character to it.

Parameters
cThe character to write

Definition at line 84 of file serial.cpp.

84 {
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}

Referenced by write_char().

◆ read_char()

char SerialConsole::read_char ( )

Read data from the serial port.

Returns
The data read

Definition at line 117 of file serial.cpp.

117 {
118 return m_data_port.read();
119}

Referenced by SerialConsole().

◆ write_char()

void SerialConsole::write_char ( char  c)
final

Waits for the serial port to be ready, then writes a character to it.

Parameters
cThe character to write

Definition at line 99 of file serial.cpp.

99 {
100 put_character(c);
101}
void put_character(char c)
Waits for the serial port to be ready, then writes a character to it.
Definition serial.cpp:84

References put_character().

Referenced by MaxOS::runtime::GDBServer::handle_continue(), and MaxOS::runtime::GDBServer::handle_step_instruction().


The documentation for this class was generated from the following files: