Unit UART

From Ultibo.org
Jump to: navigation, search

Return to Unit Reference


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



[Expand]
UART specific constants UART_*


[Expand]
UART device type UART_TYPE_*


[Expand]
UART device mode UART_MODE_*


[Expand]
UART device state UART_STATE_*


[Expand]
UART device flag UART_FLAG_*


[Expand]
UART read flag UART_READ_*


[Expand]
UART write flag UART_WRITE_*


[Expand]
UART wait direction UART_WAIT_*


[Expand]
UART status flag UART_STATUS_*


[Expand]
UART logging UART_LOG_*


Type definitions



UART properties

[Expand]

PUARTProperties = ^TUARTProperties;

TUARTProperties = record

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 wait

TUARTDeviceWait = function(UART:PUARTDevice; Direction,Timeout:LongWord):LongWord;

UART device get status

TUARTDeviceGetStatus = function(UART:PUARTDevice):LongWord;

UART device set status

TUARTDeviceSetStatus = function(UART:PUARTDevice; Status:LongWord):LongWord;

UART device get properties

TUARTDeviceGetProperties = function(UART:PUARTDevice; Properties:PUARTProperties):LongWord;

UART device set properties

TUARTDeviceSetProperties = function(UART:PUARTDevice; Properties:PUARTProperties):LongWord;

UART device

[Expand]

PUARTDevice = ^TUARTDevice;

TUARTDevice = record


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

[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: Open a UART device ready for sending and receiving


[Expand]
function UARTDeviceClose(UART:PUARTDevice):LongWord;
Description: Close a UART device and terminate sending and receiving


[Expand]
function UARTDeviceRead(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
Description: Read data from a UART device


[Expand]
function UARTDeviceWrite(UART:PUARTDevice; Buffer:Pointer; Size,Flags:LongWord;var Count:LongWord):LongWord;
Description: Write data to a UART device


[Expand]
function UARTDeviceWait(UART:PUARTDevice; Direction,Timeout:LongWord):LongWord;
Description: Wait for data to be available in the receive or transmit FIFO of a UART device


[Expand]
function UARTDeviceStatus(UART:PUARTDevice):LongWord; inline;
Description: Get the current line status of a UART device


[Expand]
function UARTDeviceGetStatus(UART:PUARTDevice):LongWord;
Description: Get the current line status of a UART device


[Expand]
function UARTDeviceSetStatus(UART:PUARTDevice;Status:LongWord):LongWord;
Description: Set the current line status of a UART device


[Expand]
function UARTDeviceProperties(UART:PUARTDevice; Properties:PUARTProperties):LongWord; inline;
Description: Get the properties for the specified UART device


[Expand]
function UARTDeviceGetProperties(UART:PUARTDevice;Properties:PUARTProperties):LongWord;
Description: Get the properties for the specified UART device


[Expand]
function UARTDeviceSetProperties(UART:PUARTDevice; Properties:PUARTProperties):LongWord;
Description: Set the properties for the specified UART device


[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: Find a UART device by Id in the UART table


[Expand]
function UARTDeviceFindByName(const Name:String):PUARTDevice; inline;
Description: Find a UART device by name in the UART table


[Expand]
function UARTDeviceFindByDescription(const Description:String):PUARTDevice; inline;
Description: Find a UART device by description in the UART table


[Expand]
function UARTDeviceEnumerate(Callback:TUARTEnumerate; Data:Pointer):LongWord;
Description: Enumerate all UART devices in the UART table


[Expand]
function UARTDeviceNotification(UART:PUARTDevice; Callback:TUARTNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for UART device changes


UART serial functions

[Expand]
function UARTSerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
Description: Implementation of SerialDeviceOpen API for UART Serial


[Expand]
function UARTSerialDeviceClose(Serial:PSerialDevice):LongWord;
Description: Implementation of SerialDeviceClose API for UART Serial


[Expand]
function UARTSerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Implementation of SerialDeviceRead API for UART Serial


[Expand]
function UARTSerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Implementation of SerialDeviceWrite API for UART Serial


[Expand]
function UARTSerialDeviceWait(Serial:PSerialDevice; Direction,Timeout:LongWord; var Count:LongWord):LongWord;
Description: Implementation of SerialDeviceWait API for UART Serial


[Expand]
function UARTSerialDeviceStatus(Serial:PSerialDevice):LongWord; inline;
Description: Implementation of SerialDeviceStatus API for UART Serial


[Expand]
function UARTSerialDeviceGetStatus(Serial:PSerialDevice):LongWord;
Description: Implementation of SerialDeviceGetStatus API for UART Serial


[Expand]
function UARTSerialDeviceSetStatus(Serial:PSerialDevice; Status:LongWord):LongWord;
Description: Implementation of SerialDeviceSetStatus API for UART Serial


[Expand]
function UARTSerialDeviceGetProperties(Serial:PSerialDevice;Properties:PSerialProperties):LongWord;
Description: Implementation of SerialDeviceGetProperties API for UART Serial


UART helper functions

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


[Expand]
function UARTDeviceGetDefault:PUARTDevice;
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]
function UARTTypeToString(UARTType:LongWord):String;
Description: Convert a UART type value to a string


[Expand]
function UARTModeToString(UARTMode:LongWord):String;
Description: Convert a UART mode to a string


[Expand]
function UARTStateToString(UARTState:LongWord):String;
Description: Convert a UART state value to a string


[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 UARTLogWarn(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: Read data from a UART device into the receive buffer of the associated Serial device


[Expand]
function UARTSerialDeviceTransmit(UART:PUARTDevice):LongWord;
Description: Write data to a UART device from the transmit buffer of the associated Serial device


Return to Unit Reference