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

A driver for the serial output. More...

#include <serial.h>

Inheritance diagram for MaxOS::drivers::SerialConsole:
MaxOS::drivers::Driver MaxOS::common::OutputStream MaxOS::common::GenericOutputStream< string > MaxOS::common::InputStreamProcessor< Type, ProcessorType > MaxOS::common::InputStreamEventHandler< Type > MaxOS::common::GenericInputStream< ProcessorType >

Public Member Functions

 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
 Writes a character to the output stream.
 
- Public Member Functions inherited from MaxOS::drivers::Driver
virtual void activate ()
 Activate the driver.
 
virtual void deactivate ()
 Deactivate the driver.
 
virtual void initialise ()
 Initialise the driver.
 
virtual uint32_t reset ()
 Reset the driver.
 
virtual string vendor_name ()
 Get who created the device.
 
virtual string device_name ()
 Get the device name of the driver.
 
- Public Member Functions inherited from MaxOS::common::OutputStream
 OutputStream ()
 Constructs an OutputStream object that uses strings as the underlying data type.
 
virtual void line_feed ()
 Writes a newline to the output stream.
 
virtual void carriage_return ()
 Writes a carriage return to the output stream.
 
virtual void clear ()
 Clears the output stream.
 
void write (string string_to_write) override
 Writes a string to the output stream.
 
void write (const char *string_to_write)
 Writes a string to the output stream.
 
virtual void write_int (int int_to_write)
 Writes an integer to the output stream.
 
virtual void write_hex (uint64_t hex_to_write)
 Writes a hex to the output stream.
 
OutputStreamoperator<< (string string_to_write) override
 Writes a string to the output stream.
 
OutputStreamoperator<< (const char *string_to_write)
 Writes a string to the output stream.
 
OutputStreamoperator<< (int int_to_write)
 Writes a integer to the output stream.
 
OutputStreamoperator<< (uint64_t hex_to_write)
 Writes a hexadecimal to the output stream.
 
OutputStreamoperator<< (char char_to_write)
 Writes a character to the output stream.
 
- Public Member Functions inherited from MaxOS::common::GenericOutputStream< string >
 GenericOutputStream ()
 __________________________________________Templates__________________________________________________///
 
 ~GenericOutputStream ()
 Destructor of the GenericOutputStream class.
 
void on_stream_read (string) override
 Writes the date that was read from the input stream to the output stream.
 
void on_end_of_stream (GenericInputStream< string > *) override
 Close the stream and remove it from the list of streams when the end of the stream is reached.
 
virtual void write (string)
 write an element to the stream.
 
virtual void close ()
 Close the stream.
 
virtual GenericOutputStream< string > & operator<< (string)
 Overload the << operator to write an element to the stream.
 
- Public Member Functions inherited from MaxOS::common::InputStreamProcessor< Type, ProcessorType >
 InputStreamProcessor ()
 Creates a new InputStreamProcessor.
 
 InputStreamProcessor (InputStreamEventHandler< ProcessorType > *generic_stream_event_handler)
 Creates a new InputStreamProcessor.
 
 ~InputStreamProcessor ()
 Destroys the InputStreamProcessor.
 
void on_end_of_stream (GenericInputStream< Type > *stream) override
 Called when a stream has finished. Passes the event on to the handlers and then removes the stream from the array of streams.
 
- Public Member Functions inherited from MaxOS::common::InputStreamEventHandler< Type >
 InputStreamEventHandler ()
 _______________________________________________TEMPLATES_________________________________________________________________///
 
 ~InputStreamEventHandler ()
 Destroys the InputStreamProcessor and disconnects it from all streams.
 
- Public Member Functions inherited from MaxOS::common::GenericInputStream< ProcessorType >
 GenericInputStream ()
 Creates a new GenericInputStream.
 
 GenericInputStream (InputStreamEventHandler< ProcessorType > *)
 Creates a new GenericInputStream and connects it to the handler.
 
 ~GenericInputStream ()
 Destroys the GenericInputStream and disconnects all handlers.
 
void connect_input_stream_event_handler (InputStreamEventHandler< ProcessorType > *)
 Adds a inputStreamEventHandler to the list of internetProtocolHandlers.
 
void disconnect_input_stream_event_handler (InputStreamEventHandler< ProcessorType > *)
 Removes a handler from the list of handlers.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::common::InputStreamEventHandler< Type >
common::Vector< GenericInputStream< Type > * > m_generic_input_streams
 List of streams being observed by this handler.
 
- Protected Attributes inherited from MaxOS::common::GenericInputStream< ProcessorType >
common::Vector< InputStreamEventHandler< ProcessorType > * > m_input_stream_event_handlers
 List of streams being observed by this handler.
 

Detailed Description

A driver for the serial output.

Definition at line 24 of file serial.h.

Constructor & Destructor Documentation

◆ SerialConsole()

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 18 of file serial.cpp.

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}
void add_log_writer(OutputStream *log_writer)
Adds an output stream to the logger.
Definition logger.cpp:44
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

References MaxOS::Logger::add_log_writer(), MaxOS::hardwarecommunication::Port8Bit::read(), and MaxOS::hardwarecommunication::Port8Bit::write().

Member Function Documentation

◆ 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 66 of file serial.cpp.

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

References MaxOS::hardwarecommunication::Port8Bit::read(), and MaxOS::hardwarecommunication::Port8Bit::write().

Referenced by write_char().

◆ write_char()

void SerialConsole::write_char ( char  char_to_write)
finalvirtual

Writes a character to the output stream.

Parameters
char_to_writeThe character to write to the output stream.

Reimplemented from MaxOS::common::OutputStream.

Definition at line 76 of file serial.cpp.

76 {
78}
void put_character(char c)
Waits for the serial port to be ready, then writes a character to it.
Definition serial.cpp:66

References put_character().


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