StuBS
Serial Class Reference

Serial interface. More...

#include <serial.h>

Inheritance diagram for Serial:

Public Types

enum  ComPort
 COM-Port. More...
 
enum  BaudRate
 Transmission speed. More...
 
enum  DataBits
 Number of data bits per character.
 
enum  StopBits
 Number of stop bits per character.
 
enum  Parity
 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.
 
int write (char out, bool blocking=true)
 Write one byte to the serial interface.
 

Protected Attributes

const ComPort port
 Selected COM port.
 

Private Types

enum  RegisterIndex {
  RECEIVE_BUFFER_REGISTER = 0 , TRANSMIT_BUFFER_REGISTER = 0 , INTERRUPT_ENABLE_REGISTER = 1 , DIVISOR_LOW_REGISTER = 0 ,
  DIVISOR_HIGH_REGISTER = 1 , INTERRUPT_IDENT_REGISTER = 2 , FIFO_CONTROL_REGISTER = 2 , LINE_CONTROL_REGISTER = 3 ,
  MODEM_CONTROL_REGISTER = 4 , LINE_STATUS_REGISTER = 5 , MODEM_STATUS_REGISTER = 6
}
 register index More...
 
enum  RegisterMask : uint8_t { }
 Mask for the respective register. More...
 

Private Member Functions

char readReg (RegisterIndex reg)
 Read value from register.
 
void writeReg (RegisterIndex reg, char out)
 Write value to register.
 

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

◆ 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..

◆ ComPort

COM-Port.

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

◆ RegisterIndex

enum Serial::RegisterIndex
private

register index

Enumerator
RECEIVE_BUFFER_REGISTER 

read only

TRANSMIT_BUFFER_REGISTER 

write only

INTERRUPT_IDENT_REGISTER 

read only

FIFO_CONTROL_REGISTER 

write only – 16550 and newer (esp. not 8250a)

LINE_CONTROL_REGISTER 

highest-order bit is DLAB (see above)

◆ RegisterMask

enum Serial::RegisterMask : uint8_t
private

Mask for the respective register.

Enumerator
INTERRUPT_PENDING 

0 means interrupt pending

ENABLE_FIFO 

0 means disabled ^= conforming to 8250a

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.

Member Function Documentation

◆ readReg()

char Serial::readReg ( RegisterIndex  reg)
private

Read value from register.

Parameters
regRegister index
Returns
The value read from register

◆ write()

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

Write one byte to the serial interface.

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

◆ writeReg()

void Serial::writeReg ( RegisterIndex  reg,
char  out 
)
private

Write value to register.

Parameters
regRegister index
outvalue to be written

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