StuBS
|
Serial interface. More...
#include <machine/serial.h>
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... | |
bool | receiveInterrupt (bool enable) |
Activate or deactivate interrupts on data reception. More... | |
Protected Attributes | |
const ComPort | port |
Selected COM port. | |
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::ComPort |
COM-Port.
The serial interface and its hardware addresses. Modern desktop PCs have, at most, a single, physical COM-port (COM1
)
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..
|
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.
int Serial::read | ( | bool | blocking = true | ) |
Read one byte from the serial interface.
blocking | If set, read() blocks until one byte was read |
-1
if non-blocking and no data ready) 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) bool Serial::receiveInterrupt | ( | bool | enable | ) |
Activate or deactivate interrupts on data reception.
Calling this function reconfigures the respective register and flushes the receive buffer.
INTERRUPT_ENABLE_REGISTER
, the bit OUT_2
must be set in the MODEM_CONTROL_REGISTER
to enable interrupts.enable | If true , interrupts will be enabled, otherwise disabled. |