StuBS
Serial Class Reference

Serial interface. More...

#include <machine/serial.h>

Inheritance diagram for Serial:
[legend]

Public Types

enum  ComPort {
  COM1 = 0x3f8 ,
  COM2 = 0x2f8 ,
  COM3 = 0x3e8 ,
  COM4 = 0x2e8
}
 COM-Port. More...
 
enum  BaudRate {
  BAUD_300 = 384 ,
  BAUD_600 = 192 ,
  BAUD_1200 = 96 ,
  BAUD_2400 = 48 ,
  BAUD_4800 = 24 ,
  BAUD_9600 = 12 ,
  BAUD_19200 = 6 ,
  BAUD_38400 = 3 ,
  BAUD_57600 = 2 ,
  BAUD_115200 = 1
}
 Transmission speed. More...
 
enum  DataBits {
  DATA_5BIT = 0 ,
  DATA_6BIT = 1 ,
  DATA_7BIT = 2 ,
  DATA_8BIT = 3
}
 Number of data bits per character.
 
enum  StopBits {
  STOP_1BIT = 0 ,
  STOP_1_5BIT = 4 ,
  STOP_2BIT = 4
}
 Number of stop bits per character.
 
enum  Parity {
  PARITY_NONE = 0 ,
  PARITY_ODD = 8 ,
  PARITY_EVEN = 24 ,
  PARITY_MARK = 40 ,
  PARITY_SPACE = 56
}
 parity bit
 

Public Member Functions

 Serial (ComPort port=COM1, BaudRate baud_rate=BAUD_115200, DataBits data_bits=DATA_8BIT, StopBits stop_bits=STOP_1BIT, Parity parity=PARITY_NONE)
 Constructor. More...
 
int read (bool blocking=true)
 Read one byte from the serial interface. More...
 
int write (char out, bool blocking=true)
 Write one byte to the serial interface. More...
 

Protected Attributes

const ComPort port
 Selected COM port.
 

Detailed Description

Serial interface.

This class provides a serial interface (COM1 - COM4) for communication with the outside world.

The first IBM PC used the external chip 8250 UART, whereas, in today's systems, this functionality is commonly integrated into the southbridge, but remained compatible.

See also
PC8250A Data Sheet (Registers on page 11)
PC16550D Data Sheet (Successor, for optional FIFO buffer, page 16)

Member Enumeration Documentation

◆ ComPort

COM-Port.

The serial interface and its hardware addresses. Modern desktop PCs have, at most, a single, physical COM-port (COM1)

◆ BaudRate

Transmission speed.

The unit Baud describes the transmission speed in number of symbols per seconds. 1 Baud therefore equals the transmission of 1 symbol per second. The possible Baud rates are whole-number dividers of the clock frequency of 115200 Hz..

Constructor & Destructor Documentation

◆ Serial()

Serial::Serial ( ComPort  port = COM1,
BaudRate  baud_rate = BAUD_115200,
DataBits  data_bits = DATA_8BIT,
StopBits  stop_bits = STOP_1BIT,
Parity  parity = PARITY_NONE 
)
explicit

Constructor.

Creates a Serial object that encapsulates the used COM port, as well as the parameters used for the serial connection. Default values are 8N1 (8 bit, no parity bit, one stop bit) with 115200 Baud using COM1.

Optional:
Implement Constructor

Member Function Documentation

◆ read()

int Serial::read ( bool  blocking = true)

Read one byte from the serial interface.

Optional:
Implement Method
Parameters
blockingIf set, read() blocks until one byte was read
Returns
Value read from serial interface (or -1 if non-blocking and no data ready)

◆ write()

int Serial::write ( char  out,
bool  blocking = true 
)

Write one byte to the serial interface.

Optional:
Implement Method
Parameters
outByte to be written
blockingIf set, write() blocks until the byte was written
Returns
Byte written (or -1 if writing byte failed)

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