Difference between revisions of "Unit UART"
Line 239: | Line 239: | ||
---- | ---- | ||
− | '' | + | |
+ | '''UART properties''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PUARTProperties = ^TUARTProperties;</code> | ||
+ | |||
+ | <code>TUARTProperties = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>Flags:LongWord;</code> | ||
+ | | Device flags (eg UART_FLAG_DATA_8BIT) | ||
+ | |- | ||
+ | | <code>MinRate:LongWord;</code> | ||
+ | | Minimum supported baud rate | ||
+ | |- | ||
+ | | <code>MaxRate:LongWord;</code> | ||
+ | | Maximum supported baud rate | ||
+ | |- | ||
+ | | <code>BaudRate:LongWord;</code> | ||
+ | | Current baud rate setting | ||
+ | |- | ||
+ | | <code>DataBits:LongWord;</code> | ||
+ | | Current data bits setting | ||
+ | |- | ||
+ | | <code>StopBits:LongWord;</code> | ||
+ | | Current stop bits setting | ||
+ | |- | ||
+ | | <code>Parity:LongWord;</code> | ||
+ | | Current parity setting | ||
+ | |- | ||
+ | | <code>FlowControl:LongWord;</code> | ||
+ | | Current flow control setting | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''UART enumeration callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTEnumerate = function(UART:PUARTDevice; Data:Pointer):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART notification callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device open''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceOpen = function(UART:PUARTDevice; BaudRate,DataBits,StopBits,Parity,FlowControl:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device close''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceClose = function(UART:PUARTDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device read''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceRead = function(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device write''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceWrite = function(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device status''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceStatus = function(UART:PUARTDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device properties''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TUARTDeviceProperties = function(UART:PUARTDevice; Properties:PUARTProperties):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''UART device''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PUARTDevice = ^TUARTDevice;</code> | ||
+ | |||
+ | <code>TUARTDevice = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''Device Properties'' | ||
+ | |- | ||
+ | | <code>Device:TDevice;</code> | ||
+ | | The Device entry for this UART | ||
+ | |- | ||
+ | |colspan="2"|''UART Properties'' | ||
+ | |- | ||
+ | | <code>UARTId:LongWord;</code> | ||
+ | | Unique Id of this UART in the UART table | ||
+ | |- | ||
+ | | <code>UARTMode:LongWord;</code> | ||
+ | | UART mode (eg UART_MODE_SERIAL) | ||
+ | |- | ||
+ | | <code>UARTState:LongWord;</code> | ||
+ | | UART state (eg UART_STATE_ENABLED) | ||
+ | |- | ||
+ | | <code>UARTStatus:LongWord;</code> | ||
+ | | UART status (eg UART_STATUS_RX_FULL)(May not be real time status depending on the driver) | ||
+ | |- | ||
+ | | <code>DeviceOpen:TUARTDeviceOpen;</code> | ||
+ | | A Device specific DeviceOpen method implementing the standard UART device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceClose:TUARTDeviceClose;</code> | ||
+ | | A Device specific DeviceClose method implementing the standard UART device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceRead:TUARTDeviceRead;</code> | ||
+ | | A Device specific DeviceRead method implementing the standard UART device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceWrite:TUARTDeviceWrite;</code> | ||
+ | | A Device specific DeviceWrite method implementing the standard UART device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceStatus:TUARTDeviceStatus;</code> | ||
+ | | A Device specific DeviceStatus method implementing the standard UART device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceProperties:TUARTDeviceProperties;</code> | ||
+ | | A Device specific DeviceProperties method implementing the standard UART device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | |colspan="2"|''Driver Properties'' | ||
+ | |- | ||
+ | | <code>Lock:TMutexHandle;</code> | ||
+ | | Device lock | ||
+ | |- | ||
+ | | <code>ReceiveWait:TEventHandle;</code> | ||
+ | | Read wait event | ||
+ | |- | ||
+ | | <code>TransmitWait:TEventHandle;</code> | ||
+ | | Write wait event | ||
+ | |- | ||
+ | | <code>Properties:TUARTProperties;</code> | ||
+ | | Device properties | ||
+ | |- | ||
+ | ''Serial Properties'' | ||
+ | |- | ||
+ | | <code>Serial:PSerialDevice;</code> | ||
+ | | The Serial device represented by this UART | ||
+ | |- | ||
+ | |colspan="2"|''Statistics Properties'' | ||
+ | |- | ||
+ | | <code>ReceiveCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ReceiveErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>TransmitCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>TransmitErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Internal Properties'' | ||
+ | |- | ||
+ | | <code>Prev:PUARTDevice;</code> | ||
+ | | Previous entry in UART table | ||
+ | |- | ||
+ | | <code>Next:PUARTDevice;</code> | ||
+ | | Next entry in UART table | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === |
Revision as of 03:25, 26 January 2017
Return to Unit Reference
Contents
[hide]Description
Ultibo UART interface unit
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
UART_*
UART_TYPE_*
UART_MODE_*
UART_STATE_*
UART_FLAG_*
UART_READ_*
UART_WRITE_*
UART_STATUS_*
UART_LOG_*
Type definitions
UART properties
UART enumeration callback
TUARTEnumerate = function(UART:PUARTDevice; Data:Pointer):LongWord;
|
UART notification callback
TUARTNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
UART device open
TUARTDeviceOpen = function(UART:PUARTDevice; BaudRate,DataBits,StopBits,Parity,FlowControl:LongWord):LongWord;
|
UART device close
TUARTDeviceClose = function(UART:PUARTDevice):LongWord;
|
UART device read
TUARTDeviceRead = function(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
UART device write
TUARTDeviceWrite = function(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
UART device status
TUARTDeviceStatus = function(UART:PUARTDevice):LongWord;
|
UART device properties
TUARTDeviceProperties = function(UART:PUARTDevice; Properties:PUARTProperties):LongWord;
|
UART device
Public variables
UART logging
UART_DEFAULT_LOG_LEVEL:LongWord = UART_LOG_LEVEL_DEBUG;
|
Minimum level for UART messages. Only messages with level greater than or equal to this will be printed. |
UART_LOG_ENABLED:Boolean;
|
Function declarations
Initialization functions
UART functions
function UARTDeviceOpen(UART:PUARTDevice; BaudRate,DataBits,StopBits,Parity,FlowControl:LongWord):LongWord;
function UARTDeviceRead(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
function UARTDeviceWrite(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
function UARTDeviceProperties(UART:PUARTDevice; Properties:PUARTProperties):LongWord;
function UARTDeviceCreateEx(Size:LongWord):PUARTDevice;
function UARTDeviceDestroy(UART:PUARTDevice):LongWord;
function UARTDeviceRegister(UART:PUARTDevice):LongWord;
function UARTDeviceDeregister(UART:PUARTDevice):LongWord;
function UARTDeviceFindByName(const Name:String):PUARTDevice; inline;
function UARTDeviceFindByDescription(const Description:String):PUARTDevice; inline;
function UARTDeviceEnumerate(Callback:TUARTEnumerate; Data:Pointer):LongWord;
function UARTDeviceNotification(UART:PUARTDevice; Callback:TUARTNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
UART serial functions
function UARTSerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
function UARTSerialDeviceClose(Serial:PSerialDevice):LongWord;
function UARTSerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function UARTSerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function UARTSerialDeviceStatus(Serial:PSerialDevice):LongWord;
function UARTSerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
UART helper functions
function UARTDeviceGetDefault:PUARTDevice; inline;
function UARTDeviceSetDefault(UART:PUARTDevice):LongWord;
function UARTDeviceCheck(UART:PUARTDevice):PUARTDevice;
procedure UARTLog(Level:LongWord;UART:PUARTDevice; const AText:String);
procedure UARTLogInfo(UART:PUARTDevice; const AText:String); inline;
procedure UARTLogError(UART:PUARTDevice; const AText:String); inline;
procedure UARTLogDebug(UART:PUARTDevice; const AText:String); inline;
UART serial helper functions
function UARTSerialDeviceTransmit(UART:PUARTDevice):LongWord;
Return to Unit Reference