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. More...
 
enum  StopBits {
  STOP_1BIT = 0 ,
  STOP_1_5BIT = 4 ,
  STOP_2BIT = 4
}
 Number of stop bits per character. More...
 
enum  Parity {
  PARITY_NONE = 0 ,
  PARITY_ODD = 8 ,
  PARITY_EVEN = 24 ,
  PARITY_MARK = 40 ,
  PARITY_SPACE = 56
}
 parity bit More...
 

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 read (bool blocking=true)
 Read one byte from the serial interface.
 
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 {
  RECEIVED_DATA_AVAILABLE = 1 << 0 ,
  TRANSMITTER_HOLDING_REGISTER_EMPTY = 1 << 1 ,
  RECEIVER_LINE_STATUS = 1 << 2 ,
  MODEM_STATUS = 1 << 3 ,
  INTERRUPT_PENDING = 1 << 0 ,
  INTERRUPT_ID_0 = 1 << 1 ,
  INTERRUPT_ID_1 = 1 << 2 ,
  ENABLE_FIFO = 1 << 0 ,
  CLEAR_RECEIVE_FIFO = 1 << 1 ,
  CLEAR_TRANSMIT_FIFO = 1 << 2 ,
  DMA_MODE_SELECT = 1 << 3 ,
  TRIGGER_RECEIVE = 1 << 6 ,
  WORD_LENGTH_SELECT_0 = 1 << 0 ,
  WORD_LENGTH_SELECT_1 = 1 << 1 ,
  NUMBER_OF_STOP_BITS = 1 << 2 ,
  PARITY_ENABLE = 1 << 3 ,
  EVEN_PARITY_SELECT = 1 << 4 ,
  STICK_PARITY = 1 << 5 ,
  SET_BREAK = 1 << 6 ,
  DIVISOR_LATCH_ACCESS_BIT = 1 << 7 ,
  DATA_TERMINAL_READY = 1 << 0 ,
  REQUEST_TO_SEND = 1 << 1 ,
  OUT_1 = 1 << 2 ,
  OUT_2 = 1 << 3 ,
  LOOP = 1 << 4 ,
  DATA_READY = 1 << 0 ,
  OVERRUN_ERROR = 1 << 1 ,
  PARITY_ERROR = 1 << 2 ,
  FRAMING_ERROR = 1 << 3 ,
  BREAK_INTERRUPT = 1 << 4 ,
  TRANSMITTER_HOLDING_REGISTER = 1 << 5 ,
  TRANSMITTER_EMPTY = 1 << 6 ,
  DELTA_CLEAR_TO_SEND = 1 << 0 ,
  DELTA_DATA_SET_READY = 1 << 1 ,
  TRAILING_EDGE_RING_INDICATOR = 1 << 2 ,
  DELTA_DATA_CARRIER_DETECT = 1 << 3 ,
  CLEAR_TO_SEND = 1 << 4 ,
  DATA_SET_READY = 1 << 5 ,
  RING_INDICATOR = 1 << 6 ,
  DATA_CARRIER_DETECT = 1 << 7
}
 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

◆ ComPort

COM-Port.

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

Enumerator
COM1 
COM2 
COM3 
COM4 

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

Enumerator
BAUD_300 
BAUD_600 
BAUD_1200 
BAUD_2400 
BAUD_4800 
BAUD_9600 
BAUD_19200 
BAUD_38400 
BAUD_57600 
BAUD_115200 

◆ DataBits

Number of data bits per character.

Enumerator
DATA_5BIT 
DATA_6BIT 
DATA_7BIT 
DATA_8BIT 

◆ StopBits

Number of stop bits per character.

Enumerator
STOP_1BIT 
STOP_1_5BIT 
STOP_2BIT 

◆ Parity

parity bit

Enumerator
PARITY_NONE 
PARITY_ODD 
PARITY_EVEN 
PARITY_MARK 
PARITY_SPACE 

◆ RegisterIndex

enum Serial::RegisterIndex
private

register index

Enumerator
RECEIVE_BUFFER_REGISTER 

read only

TRANSMIT_BUFFER_REGISTER 

write only

INTERRUPT_ENABLE_REGISTER 
DIVISOR_LOW_REGISTER 
DIVISOR_HIGH_REGISTER 
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)

MODEM_CONTROL_REGISTER 
LINE_STATUS_REGISTER 
MODEM_STATUS_REGISTER 

◆ RegisterMask

enum Serial::RegisterMask : uint8_t
private

Mask for the respective register.

Enumerator
RECEIVED_DATA_AVAILABLE 
TRANSMITTER_HOLDING_REGISTER_EMPTY 
RECEIVER_LINE_STATUS 
MODEM_STATUS 
INTERRUPT_PENDING 

0 means interrupt pending

INTERRUPT_ID_0 
INTERRUPT_ID_1 
ENABLE_FIFO 

0 means disabled ^= conforming to 8250a

CLEAR_RECEIVE_FIFO 
CLEAR_TRANSMIT_FIFO 
DMA_MODE_SELECT 
TRIGGER_RECEIVE 
WORD_LENGTH_SELECT_0 
WORD_LENGTH_SELECT_1 
NUMBER_OF_STOP_BITS 
PARITY_ENABLE 
EVEN_PARITY_SELECT 
STICK_PARITY 
SET_BREAK 
DIVISOR_LATCH_ACCESS_BIT 
DATA_TERMINAL_READY 
REQUEST_TO_SEND 
OUT_1 
OUT_2 
LOOP 
DATA_READY 
OVERRUN_ERROR 
PARITY_ERROR 
FRAMING_ERROR 
BREAK_INTERRUPT 
TRANSMITTER_HOLDING_REGISTER 
TRANSMITTER_EMPTY 
DELTA_CLEAR_TO_SEND 
DELTA_DATA_SET_READY 
TRAILING_EDGE_RING_INDICATOR 
DELTA_DATA_CARRIER_DETECT 
CLEAR_TO_SEND 
DATA_SET_READY 
RING_INDICATOR 
DATA_CARRIER_DETECT 

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

◆ writeReg()

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

Write value to register.

Parameters
regRegister index
outvalue to be written

◆ read()

int Serial::read ( bool  blocking = true)

Read one byte from the serial interface.

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.

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

Member Data Documentation

◆ port

const ComPort Serial::port
protected

Selected COM port.


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