StuBS
|
#include <serial.h>
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. | |
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.
enum Serial::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..
enum Serial::ComPort |
COM-Port.
The serial interface and its hardware addresses. Modern desktop PCs have, at most, a single, physical COM-port (COM1
)
|
private |
|
private |
|
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.
|
private |
Read value from register.
reg | Register index |
int Serial::write | ( | char | out, |
bool | blocking = true |
||
) |
Write one byte to the serial interface.
out | Byte to be written |
blocking | If set, write() blocks until the byte was written |
-1
if writing byte failed)
|
private |
Write value to register.
reg | Register index |
out | value to be written |