Difference between revisions of "Unit UART"

From Ultibo.org
Jump to: navigation, search
Line 17: Line 17:
 
----
 
----
  
''To be documented''
+
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART specific constants''' <code> UART_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_NAME_PREFIX = 'UART';</code>
 +
| Name prefix for UART Devices
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART device type constants''' <code> UART_TYPE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_TYPE_NONE = 0;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_TYPE_8250 = 1;</code>
 +
| 8250 UART and similar variants (Differences are handled by driver)
 +
|-
 +
| <code>UART_TYPE_16550 = 2;</code>
 +
| 16550 UART and similar variants (eg 16550A) (Differences are handled by driver)
 +
|-
 +
| <code>UART_TYPE_16650 = 3;</code>
 +
| 16650 UART and similar variants (eg 16C650) (Differences are handled by driver)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART device mode constants''' <code> UART_MODE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_MODE_NONE = 0;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_MODE_UART = 1;</code>
 +
| The UART was opened as a UART device and all reads and writes are direct
 +
|-
 +
| <code>UART_MODE_SERIAL = 2;</code>
 +
| The UART was opened as a Serial device so reads and writes are being buffered
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART device state constants''' <code> UART_STATE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_STATE_DISABLED = 0;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>UART_STATE_ENABLED = 1;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART device flag constants''' <code> UART_FLAG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_FLAG_NONE = SERIAL_FLAG_NONE;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_FLAG_DATA_8BIT = SERIAL_FLAG_DATA_8BIT;</code>
 +
| Device supports 8 data bits
 +
|-
 +
| <code>UART_FLAG_DATA_7BIT = SERIAL_FLAG_DATA_7BIT;</code>
 +
| Device supports 7 data bits
 +
|-
 +
| <code>UART_FLAG_DATA_6BIT = SERIAL_FLAG_DATA_6BIT;</code>
 +
| Device supports 6 data bits
 +
|-
 +
| <code>UART_FLAG_DATA_5BIT = SERIAL_FLAG_DATA_5BIT;</code>
 +
| Device supports 5 data bits
 +
|-
 +
| <code>UART_FLAG_STOP_1BIT = SERIAL_FLAG_STOP_1BIT;</code>
 +
| Device supports 1 stop bit
 +
|-
 +
| <code>UART_FLAG_STOP_2BIT = SERIAL_FLAG_STOP_2BIT;</code>
 +
| Device supports 2 stop bits
 +
|-
 +
| <code>UART_FLAG_STOP_1BIT5 = SERIAL_FLAG_STOP_1BIT5;</code>
 +
| Device supports 1.5 stop bits
 +
|-
 +
| <code>UART_FLAG_PARITY_ODD = SERIAL_FLAG_PARITY_ODD;</code>
 +
| Device supports odd parity
 +
|-
 +
| <code>UART_FLAG_PARITY_EVEN = SERIAL_FLAG_PARITY_EVEN;</code>
 +
| Device supports even parity
 +
|-
 +
| <code>UART_FLAG_PARITY_MARK = SERIAL_FLAG_PARITY_MARK;</code>
 +
| Device supports mark parity
 +
|-
 +
| <code>UART_FLAG_PARITY_SPACE = SERIAL_FLAG_PARITY_SPACE;</code>
 +
| Device supports space parity
 +
|-
 +
| <code>UART_FLAG_FLOW_RTS_CTS = SERIAL_FLAG_FLOW_RTS_CTS;</code>
 +
| Device supports RTS/CTS flow control
 +
|-
 +
| <code>UART_FLAG_FLOW_DSR_DTR = SERIAL_FLAG_FLOW_DSR_DTR;</code>
 +
| Device supports DSR/DTR flow control
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART read flag constants''' <code> UART_READ_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_READ_NONE = SERIAL_READ_NONE;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_READ_NON_BLOCK = SERIAL_READ_NON_BLOCK;</code>
 +
| Do not block when receiving, if the FIFO is empty return immediately
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART write flag constants''' <code> UART_WRITE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_WRITE_NONE = SERIAL_WRITE_NONE;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_WRITE_NON_BLOCK = SERIAL_WRITE_NON_BLOCK;</code>
 +
| Do not block when transmitting, if the FIFO is full return immediately
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART status flag constants''' <code> UART_STATUS_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_STATUS_NONE = SERIAL_STATUS_NONE;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>UART_STATUS_RTS = SERIAL_STATUS_RTS;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_CTS = SERIAL_STATUS_CTS;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_DSR = SERIAL_STATUS_DSR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_DTR = SERIAL_STATUS_DTR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_RX_FULL = SERIAL_STATUS_RX_FULL;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_RX_EMPTY = SERIAL_STATUS_RX_EMPTY;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_TX_FULL = SERIAL_STATUS_TX_FULL;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_TX_EMPTY = SERIAL_STATUS_TX_EMPTY;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_BUSY = SERIAL_STATUS_BUSY;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_BREAK_ERROR = SERIAL_STATUS_BREAK_ERROR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_PARITY_ERROR = SERIAL_STATUS_PARITY_ERROR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_FRAMING_ERROR = SERIAL_STATUS_FRAMING_ERROR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_OVERRUN_ERROR = SERIAL_STATUS_OVERRUN_ERROR;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_DCD = SERIAL_STATUS_DCD;</code>
 +
| &nbsp;
 +
|-
 +
| <code>UART_STATUS_RI = SERIAL_STATUS_RI;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UART logging constants''' <code> UART_LOG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UART_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;</code>
 +
| UART debugging messages
 +
|-
 +
| <code>UART_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code>
 +
| UART informational messages, such as a device being attached or detached
 +
|-
 +
| <code>UART_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
 +
| UART error messages
 +
|-
 +
| <code>UART_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 +
| No UART messages
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===

Revision as of 03:24, 29 November 2016

Return to Unit Reference


Description


UART (Universal Asynchronous Receiver Transmitter) devices represent the industry standard serial communications devices that are available on almost every system.

This unit implements the framework for UART devices and provides a standardized API to allow driver specific implementation to be abstracted. All UART devices are also represented as a serial device and this unit handles the relationship between the two devices.

Each UART device returns a set of properties that describe the capabilities of the device and includes a set of flags that indicate what features are supported.

Reads and writes to UART devices are unbuffered and simply pass raw data to and from the caller unless the serial interface is used instead which includes buffering of transmitted and received data. Both reads and writes allow for non blocking so that a caller can avoid waiting for received data to be available or the device to be ready to transmit.

Constants



[Expand]
UART specific constants UART_*


[Expand]
UART device type constants UART_TYPE_*


[Expand]
UART device mode constants UART_MODE_*


[Expand]
UART device state constants UART_STATE_*


[Expand]
UART device flag constants UART_FLAG_*


[Expand]
UART read flag constants UART_READ_*


[Expand]
UART write flag constants UART_WRITE_*


[Expand]
UART status flag constants UART_STATUS_*


[Expand]
UART logging constants UART_LOG_*


Type definitions


To be documented

Public variables


To be documented

Function declarations



Initialization functions

[Expand]
procedure UARTInit;
Description: Initialize the UART unit and UART device table


UART functions

[Expand]
function UARTDeviceOpen(UART:PUARTDevice; BaudRate,DataBits,StopBits,Parity,FlowControl:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTDeviceClose(UART:PUARTDevice):LongWord;
Description: To be documented


[Expand]
function UARTDeviceRead(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTDeviceWrite(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTDeviceStatus(UART:PUARTDevice):LongWord;
Description: To be documented


[Expand]
function UARTDeviceProperties(UART:PUARTDevice; Properties:PUARTProperties):LongWord;
Description: To be documented


[Expand]
function UARTDeviceCreate:PUARTDevice;
Description: Create a new UART entry


[Expand]
function UARTDeviceCreateEx(Size:LongWord):PUARTDevice;
Description: Create a new UART entry


[Expand]
function UARTDeviceDestroy(UART:PUARTDevice):LongWord;
Description: Destroy an existing UART entry


[Expand]
function UARTDeviceRegister(UART:PUARTDevice):LongWord;
Description: Register a new UART in the UART table


[Expand]
function UARTDeviceDeregister(UART:PUARTDevice):LongWord;
Description: Deregister a UART from the UART table


[Expand]
function UARTDeviceFind(UARTId:LongWord):PUARTDevice;
Description: To be documented


[Expand]
function UARTDeviceFindByName(const Name:String):PUARTDevice; inline;
Description: To be documented


[Expand]
function UARTDeviceFindByDescription(const Description:String):PUARTDevice; inline;
Description: To be documented


[Expand]
function UARTDeviceEnumerate(Callback:TUARTEnumerate; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function UARTDeviceNotification(UART:PUARTDevice; Callback:TUARTNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented


UART serial functions

[Expand]
function UARTSerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceClose(Serial:PSerialDevice):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceStatus(Serial:PSerialDevice):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
Description: To be documented


UART helper functions

[Expand]
function UARTGetCount:LongWord; inline;
Description: Get the current UART count


[Expand]
function UARTDeviceGetDefault:PUARTDevice; inline;
Description: Get the current default UART device


[Expand]
function UARTDeviceSetDefault(UART:PUARTDevice):LongWord;
Description: Set the current default UART device


[Expand]
function UARTDeviceCheck(UART:PUARTDevice):PUARTDevice;
Description: Check if the supplied UART is in the UART table


[Expand]
procedure UARTLog(Level:LongWord;UART:PUARTDevice; const AText:String);
Description: To be documented


[Expand]
procedure UARTLogInfo(UART:PUARTDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure UARTLogError(UART:PUARTDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure UARTLogDebug(UART:PUARTDevice; const AText:String); inline;
Description: To be documented


UART serial helper functions

[Expand]
function UARTSerialDeviceReceive(UART:PUARTDevice):LongWord;
Description: To be documented


[Expand]
function UARTSerialDeviceTransmit(UART:PUARTDevice):LongWord;
Description: To be documented


Return to Unit Reference