Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
serial.h File Reference

Go to the source code of this file.

Data Structures

struct  _SERIAL_PROPERTIES
struct  _SERIAL_BUFFER
struct  _SERIAL_DEVICE

Macros

#define SERIAL_NAME_PREFIX   "Serial"
 Name prefix for Serial Devices.
#define SERIAL_LOGGING_DESCRIPTION   "Serial Logging"
#define SERIAL_RECEIVE_DEPTH_DEFAULT   SIZE_2K
 Default receive buffer size in bytes.
#define SERIAL_TRANSMIT_DEPTH_DEFAULT   SIZE_2K
 Default transmit buffer size in bytes.
#define SERIAL_PUSH_TIMEOUT   50
 Timeout (Milliseconds) for Push RX/TX (Implementation specific).
#define SERIAL_TYPE_NONE   0
#define SERIAL_TYPE_UART   1
#define SERIAL_TYPE_USB   2
#define SERIAL_TYPE_MAX   2
#define SERIAL_STATE_CLOSED   0
#define SERIAL_STATE_CLOSING   1
#define SERIAL_STATE_OPENING   2
#define SERIAL_STATE_OPEN   3
#define SERIAL_STATE_MAX   3
#define SERIAL_FLAG_NONE   0x00000000
#define SERIAL_FLAG_DATA_8BIT   0x00000001
 Device supports 8 data bits.
#define SERIAL_FLAG_DATA_7BIT   0x00000002
 Device supports 7 data bits.
#define SERIAL_FLAG_DATA_6BIT   0x00000004
 Device supports 6 data bits.
#define SERIAL_FLAG_DATA_5BIT   0x00000008
 Device supports 5 data bits.
#define SERIAL_FLAG_STOP_1BIT   0x00000010
 Device supports 1 stop bit.
#define SERIAL_FLAG_STOP_2BIT   0x00000020
 Device supports 2 stop bits.
#define SERIAL_FLAG_STOP_1BIT5   0x00000040
 Device supports 1.5 stop bits.
#define SERIAL_FLAG_PARITY_ODD   0x00000080
 Device supports odd parity.
#define SERIAL_FLAG_PARITY_EVEN   0x00000100
 Device supports even parity.
#define SERIAL_FLAG_PARITY_MARK   0x00000200
 Device supports mark parity.
#define SERIAL_FLAG_PARITY_SPACE   0x00000400
 Device supports space parity.
#define SERIAL_FLAG_FLOW_RTS_CTS   0x00000800
 Device supports RTS/CTS flow control.
#define SERIAL_FLAG_FLOW_DSR_DTR   0x00001000
 Device supports DSR/DTR flow control.
#define SERIAL_FLAG_PUSH_RX   0x00002000
 Device requires pushed receive (Implementation specific).
#define SERIAL_FLAG_PUSH_TX   0x00004000
 Device requires pushed transmit (Implementation specific).
#define SERIAL_READ_NONE   0x00000000
#define SERIAL_READ_NON_BLOCK   0x00000001
 Do not block when reading, if the buffer is empty return immediately.
#define SERIAL_READ_PEEK_BUFFER   0x00000002
 Return the number of bytes available in the receive buffer without reading them.
#define SERIAL_WRITE_NONE   0x00000000
#define SERIAL_WRITE_NON_BLOCK   0x00000001
 Do not block when writing, if the buffer is full return immediately.
#define SERIAL_WRITE_PEEK_BUFFER   0x00000002
 Return the number of bytes free in the transmit buffer without writing anything.
#define SERIAL_WAIT_NONE   0
#define SERIAL_WAIT_RECEIVE   1
 Wait for data to be available in the receive buffer.
#define SERIAL_WAIT_TRANSMIT   2
 Wait for space to be available in the transmit buffer.
#define SERIAL_FLUSH_NONE   0x00000000
#define SERIAL_FLUSH_RECEIVE   0x00000001
 Flush the receive buffer.
#define SERIAL_FLUSH_TRANSMIT   0x00000002
 Flush the transmit buffer.
#define SERIAL_STATUS_NONE   0x00000000
#define SERIAL_STATUS_RTS   0x00000001
 RTS (Request to Send) is set (If applicable).
#define SERIAL_STATUS_CTS   0x00000002
 CTS (Clear to Send) is set (If applicable).
#define SERIAL_STATUS_DSR   0x00000004
 DSR (Data Set Ready) is set (If applicable).
#define SERIAL_STATUS_DTR   0x00000008
 DTR (Data Terminal Ready) is set (If applicable).
#define SERIAL_STATUS_RX_FULL   0x00000010
 Receive buffer is full.
#define SERIAL_STATUS_RX_EMPTY   0x00000020
 Receive buffer is empty.
#define SERIAL_STATUS_TX_FULL   0x00000040
 Transmit buffer is full.
#define SERIAL_STATUS_TX_EMPTY   0x00000080
 Transmit buffer is empty.
#define SERIAL_STATUS_BUSY   0x00000100
 Device is busy.
#define SERIAL_STATUS_BREAK_ERROR   0x00000200
 Break error reported.
#define SERIAL_STATUS_PARITY_ERROR   0x00000400
 Parity error reported.
#define SERIAL_STATUS_FRAMING_ERROR   0x00000800
 Framing error reported.
#define SERIAL_STATUS_OVERRUN_ERROR   0x00001000
 Overrun error reported.
#define SERIAL_STATUS_DCD   0x00002000
 DCD (Data Carrier Detect) is set (If applicable).
#define SERIAL_STATUS_RI   0x00004000
 RI (Ring Indicator) is set (If applicable).

Typedefs

typedef struct _SERIAL_PROPERTIES SERIAL_PROPERTIES
typedef struct _SERIAL_BUFFER SERIAL_BUFFER
typedef struct _SERIAL_DEVICE SERIAL_DEVICE
typedef uint32_t STDCALL(* serial_enumerate_cb) (SERIAL_DEVICE *serial, void *data)
typedef uint32_t STDCALL(* serial_notification_cb) (DEVICE *device, void *data, uint32_t notification)
typedef uint32_t STDCALL(* serial_device_open_proc) (SERIAL_DEVICE *serial, uint32_t baudrate, uint32_t databits, uint32_t stopbits, uint32_t parity, uint32_t flowcontrol, uint32_t receivedepth, uint32_t transmitdepth)
typedef uint32_t STDCALL(* serial_device_close_proc) (SERIAL_DEVICE *serial)
typedef uint32_t STDCALL(* serial_device_read_proc) (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
typedef uint32_t STDCALL(* serial_device_write_proc) (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
typedef uint32_t STDCALL(* serial_device_wait_proc) (SERIAL_DEVICE *serial, uint32_t direction, uint32_t timeout, uint32_t *count)
typedef uint32_t STDCALL(* serial_device_flush_proc) (SERIAL_DEVICE *serial, uint32_t flags)
typedef uint32_t STDCALL(* serial_device_get_status_proc) (SERIAL_DEVICE *serial)
typedef uint32_t STDCALL(* serial_device_set_status_proc) (SERIAL_DEVICE *serial, uint32_t status)
typedef uint32_t STDCALL(* serial_device_get_properties_proc) (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
typedef uint32_t STDCALL(* serial_device_set_properties_proc) (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)

Functions

uint32_t STDCALL serial_device_open (SERIAL_DEVICE *serial, uint32_t baudrate, uint32_t databits, uint32_t stopbits, uint32_t parity, uint32_t flowcontrol, uint32_t receivedepth, uint32_t transmitdepth)
 Open a Serial device ready for sending and receiving.
uint32_t STDCALL serial_device_close (SERIAL_DEVICE *serial)
 Close a Serial device and terminate sending and receiving.
uint32_t STDCALL serial_device_read (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
 Read data from a Serial device.
uint32_t STDCALL serial_device_write (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
 Write data to a Serial device.
uint32_t STDCALL serial_device_wait (SERIAL_DEVICE *serial, uint32_t direction, uint32_t timeout, uint32_t *count)
 Wait for data to be available in the receive or transmit buffers of a Serial device.
uint32_t STDCALL serial_device_flush (SERIAL_DEVICE *serial, uint32_t flags)
 Discard the contents of the receive and/or transmit buffers of a Serial device.
uint32_t STDCALL serial_device_status (SERIAL_DEVICE *serial)
 Get the current line status of a Serial device.
uint32_t STDCALL serial_device_get_status (SERIAL_DEVICE *serial)
 Get the current line status of a Serial device.
uint32_t STDCALL serial_device_set_status (SERIAL_DEVICE *serial, uint32_t status)
 Set the current line status of a Serial device.
uint32_t STDCALL serial_device_properties (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
 Get the properties for the specified Serial device.
uint32_t STDCALL serial_device_get_properties (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
 Get the properties for the specified Serial device.
uint32_t STDCALL serial_device_set_properties (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
 Set the properties for the specified Serial device.
SERIAL_DEVICE *STDCALL serial_device_create (void)
 Create a new Serial entry.
SERIAL_DEVICE *STDCALL serial_device_create_ex (uint32_t size)
 Create a new Serial entry.
uint32_t STDCALL serial_device_destroy (SERIAL_DEVICE *serial)
 Destroy an existing Serial entry.
uint32_t STDCALL serial_device_register (SERIAL_DEVICE *serial)
 Register a new Serial in the Serial table.
uint32_t STDCALL serial_device_deregister (SERIAL_DEVICE *serial)
 Deregister a Serial from the Serial table.
SERIAL_DEVICE *STDCALL serial_device_find (uint32_t serialid)
 Find a serial device by ID in the serial table.
SERIAL_DEVICE *STDCALL serial_device_find_by_name (const char *name)
 Find a serial device by name in the serial table.
SERIAL_DEVICE *STDCALL serial_device_find_by_description (const char *description)
 Find a serial device by description in the serial table.
uint32_t STDCALL serial_device_enumerate (serial_enumerate_cb callback, void *data)
 Enumerate all serial devices in the serial table.
uint32_t STDCALL serial_device_notification (SERIAL_DEVICE *serial, serial_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
 Register a notification for serial device changes.
int STDCALL serial_device_printf (SERIAL_DEVICE *serial, const char *format,...) _ATTRIBUTE((__format__(__printf__
 Print formatted text to a Serial device.
int STDCALL uint32_t STDCALL serial_get_count (void)
 Get the current Serial count.
SERIAL_DEVICE *STDCALL serial_device_get_default (void)
 Get the current default Serial device.
uint32_t STDCALL serial_device_set_default (SERIAL_DEVICE *serial)
 Set the current default Serial device.
SERIAL_DEVICE *STDCALL serial_device_check (SERIAL_DEVICE *serial)
 Check if the supplied Serial is in the Serial table.
uint32_t STDCALL serial_type_to_string (uint32_t serialtype, char *string, uint32_t len)
 Convert a Serial type value to a string.
uint32_t STDCALL serial_state_to_string (uint32_t serialstate, char *string, uint32_t len)
 Convert a Serial state value to a string.
BOOL STDCALL serial_device_redirect_input (SERIAL_DEVICE *serial)
 Redirect standard input to the serial device specified by Serial.
BOOL STDCALL serial_device_redirect_output (SERIAL_DEVICE *serial)
 Redirect standard output to the serial device specified by Serial.
void *STDCALL serial_buffer_read_start (SERIAL_BUFFER *buffer, uint32_t *available)
 Return a pointer to the next read from the buffer and the number of bytes that can be read.
BOOL STDCALL serial_buffer_read_complete (SERIAL_BUFFER *buffer, uint32_t removed)
 Update the buffer to reflect the number of bytes removed when reading.
void *STDCALL serial_buffer_write_start (SERIAL_BUFFER *buffer, uint32_t *available)
 Return a pointer to the next write to the buffer and the number of bytes that can be written.
BOOL STDCALL serial_buffer_write_complete (SERIAL_BUFFER *buffer, uint32_t added)
 Update the buffer to reflect the number of bytes added when writing.
uint32_t STDCALL serial_data_bits_to_string (uint32_t bits, char *string, uint32_t len)
uint32_t STDCALL serial_stop_bits_to_string (uint32_t bits, char *string, uint32_t len)
uint32_t STDCALL serial_parity_to_string (uint32_t parity, char *string, uint32_t len)
uint32_t STDCALL serial_flow_control_to_string (uint32_t flow, char *string, uint32_t len)
uint32_t STDCALL serial_logging_device_add (SERIAL_DEVICE *serial)
 Add a new serial logging device on receipt of a device register notification.
uint32_t STDCALL serial_logging_device_remove (SERIAL_DEVICE *serial)
 Remove a serial logging device on receipt of a device deregister notification.
uint32_t STDCALL serial_logging_device_parameters (SERIAL_DEVICE *serial, const char *parameters, uint32_t *baudrate, uint32_t *parity, uint32_t *databits, uint32_t *stopbits)
 Break down the serial parameters value into component parts of baud rate, parity, data bits and stop bits The parameters must be in the form 'BaudRate,Parity,DataBits,StopBits' (eg '115200,N,8,1').

Macro Definition Documentation

◆ SERIAL_NAME_PREFIX

#define SERIAL_NAME_PREFIX   "Serial"

Name prefix for Serial Devices.

Serial specific constants

◆ SERIAL_LOGGING_DESCRIPTION

#define SERIAL_LOGGING_DESCRIPTION   "Serial Logging"

◆ SERIAL_RECEIVE_DEPTH_DEFAULT

#define SERIAL_RECEIVE_DEPTH_DEFAULT   SIZE_2K

Default receive buffer size in bytes.

◆ SERIAL_TRANSMIT_DEPTH_DEFAULT

#define SERIAL_TRANSMIT_DEPTH_DEFAULT   SIZE_2K

Default transmit buffer size in bytes.

◆ SERIAL_PUSH_TIMEOUT

#define SERIAL_PUSH_TIMEOUT   50

Timeout (Milliseconds) for Push RX/TX (Implementation specific).

◆ SERIAL_TYPE_NONE

#define SERIAL_TYPE_NONE   0

Serial Device Types

◆ SERIAL_TYPE_UART

#define SERIAL_TYPE_UART   1

◆ SERIAL_TYPE_USB

#define SERIAL_TYPE_USB   2

◆ SERIAL_TYPE_MAX

#define SERIAL_TYPE_MAX   2

◆ SERIAL_STATE_CLOSED

#define SERIAL_STATE_CLOSED   0

Serial Device States

◆ SERIAL_STATE_CLOSING

#define SERIAL_STATE_CLOSING   1

◆ SERIAL_STATE_OPENING

#define SERIAL_STATE_OPENING   2

◆ SERIAL_STATE_OPEN

#define SERIAL_STATE_OPEN   3

◆ SERIAL_STATE_MAX

#define SERIAL_STATE_MAX   3

◆ SERIAL_FLAG_NONE

#define SERIAL_FLAG_NONE   0x00000000

Serial Device Flags

◆ SERIAL_FLAG_DATA_8BIT

#define SERIAL_FLAG_DATA_8BIT   0x00000001

Device supports 8 data bits.

◆ SERIAL_FLAG_DATA_7BIT

#define SERIAL_FLAG_DATA_7BIT   0x00000002

Device supports 7 data bits.

◆ SERIAL_FLAG_DATA_6BIT

#define SERIAL_FLAG_DATA_6BIT   0x00000004

Device supports 6 data bits.

◆ SERIAL_FLAG_DATA_5BIT

#define SERIAL_FLAG_DATA_5BIT   0x00000008

Device supports 5 data bits.

◆ SERIAL_FLAG_STOP_1BIT

#define SERIAL_FLAG_STOP_1BIT   0x00000010

Device supports 1 stop bit.

◆ SERIAL_FLAG_STOP_2BIT

#define SERIAL_FLAG_STOP_2BIT   0x00000020

Device supports 2 stop bits.

◆ SERIAL_FLAG_STOP_1BIT5

#define SERIAL_FLAG_STOP_1BIT5   0x00000040

Device supports 1.5 stop bits.

◆ SERIAL_FLAG_PARITY_ODD

#define SERIAL_FLAG_PARITY_ODD   0x00000080

Device supports odd parity.

◆ SERIAL_FLAG_PARITY_EVEN

#define SERIAL_FLAG_PARITY_EVEN   0x00000100

Device supports even parity.

◆ SERIAL_FLAG_PARITY_MARK

#define SERIAL_FLAG_PARITY_MARK   0x00000200

Device supports mark parity.

◆ SERIAL_FLAG_PARITY_SPACE

#define SERIAL_FLAG_PARITY_SPACE   0x00000400

Device supports space parity.

◆ SERIAL_FLAG_FLOW_RTS_CTS

#define SERIAL_FLAG_FLOW_RTS_CTS   0x00000800

Device supports RTS/CTS flow control.

◆ SERIAL_FLAG_FLOW_DSR_DTR

#define SERIAL_FLAG_FLOW_DSR_DTR   0x00001000

Device supports DSR/DTR flow control.

◆ SERIAL_FLAG_PUSH_RX

#define SERIAL_FLAG_PUSH_RX   0x00002000

Device requires pushed receive (Implementation specific).

◆ SERIAL_FLAG_PUSH_TX

#define SERIAL_FLAG_PUSH_TX   0x00004000

Device requires pushed transmit (Implementation specific).

◆ SERIAL_READ_NONE

#define SERIAL_READ_NONE   0x00000000

Serial Read Flags

◆ SERIAL_READ_NON_BLOCK

#define SERIAL_READ_NON_BLOCK   0x00000001

Do not block when reading, if the buffer is empty return immediately.

◆ SERIAL_READ_PEEK_BUFFER

#define SERIAL_READ_PEEK_BUFFER   0x00000002

Return the number of bytes available in the receive buffer without reading them.

◆ SERIAL_WRITE_NONE

#define SERIAL_WRITE_NONE   0x00000000

Serial Write Flags

◆ SERIAL_WRITE_NON_BLOCK

#define SERIAL_WRITE_NON_BLOCK   0x00000001

Do not block when writing, if the buffer is full return immediately.

◆ SERIAL_WRITE_PEEK_BUFFER

#define SERIAL_WRITE_PEEK_BUFFER   0x00000002

Return the number of bytes free in the transmit buffer without writing anything.

◆ SERIAL_WAIT_NONE

#define SERIAL_WAIT_NONE   0

Serial Wait Directions

◆ SERIAL_WAIT_RECEIVE

#define SERIAL_WAIT_RECEIVE   1

Wait for data to be available in the receive buffer.

◆ SERIAL_WAIT_TRANSMIT

#define SERIAL_WAIT_TRANSMIT   2

Wait for space to be available in the transmit buffer.

◆ SERIAL_FLUSH_NONE

#define SERIAL_FLUSH_NONE   0x00000000

Serial Flush Flags

◆ SERIAL_FLUSH_RECEIVE

#define SERIAL_FLUSH_RECEIVE   0x00000001

Flush the receive buffer.

◆ SERIAL_FLUSH_TRANSMIT

#define SERIAL_FLUSH_TRANSMIT   0x00000002

Flush the transmit buffer.

◆ SERIAL_STATUS_NONE

#define SERIAL_STATUS_NONE   0x00000000

Serial Status Flags

◆ SERIAL_STATUS_RTS

#define SERIAL_STATUS_RTS   0x00000001

RTS (Request to Send) is set (If applicable).

◆ SERIAL_STATUS_CTS

#define SERIAL_STATUS_CTS   0x00000002

CTS (Clear to Send) is set (If applicable).

◆ SERIAL_STATUS_DSR

#define SERIAL_STATUS_DSR   0x00000004

DSR (Data Set Ready) is set (If applicable).

◆ SERIAL_STATUS_DTR

#define SERIAL_STATUS_DTR   0x00000008

DTR (Data Terminal Ready) is set (If applicable).

◆ SERIAL_STATUS_RX_FULL

#define SERIAL_STATUS_RX_FULL   0x00000010

Receive buffer is full.

◆ SERIAL_STATUS_RX_EMPTY

#define SERIAL_STATUS_RX_EMPTY   0x00000020

Receive buffer is empty.

◆ SERIAL_STATUS_TX_FULL

#define SERIAL_STATUS_TX_FULL   0x00000040

Transmit buffer is full.

◆ SERIAL_STATUS_TX_EMPTY

#define SERIAL_STATUS_TX_EMPTY   0x00000080

Transmit buffer is empty.

◆ SERIAL_STATUS_BUSY

#define SERIAL_STATUS_BUSY   0x00000100

Device is busy.

◆ SERIAL_STATUS_BREAK_ERROR

#define SERIAL_STATUS_BREAK_ERROR   0x00000200

Break error reported.

◆ SERIAL_STATUS_PARITY_ERROR

#define SERIAL_STATUS_PARITY_ERROR   0x00000400

Parity error reported.

◆ SERIAL_STATUS_FRAMING_ERROR

#define SERIAL_STATUS_FRAMING_ERROR   0x00000800

Framing error reported.

◆ SERIAL_STATUS_OVERRUN_ERROR

#define SERIAL_STATUS_OVERRUN_ERROR   0x00001000

Overrun error reported.

◆ SERIAL_STATUS_DCD

#define SERIAL_STATUS_DCD   0x00002000

DCD (Data Carrier Detect) is set (If applicable).

◆ SERIAL_STATUS_RI

#define SERIAL_STATUS_RI   0x00004000

RI (Ring Indicator) is set (If applicable).

Typedef Documentation

◆ SERIAL_PROPERTIES

Serial specific types Serial Properties

◆ SERIAL_BUFFER

typedef struct _SERIAL_BUFFER SERIAL_BUFFER

Serial Buffer

◆ SERIAL_DEVICE

typedef struct _SERIAL_DEVICE SERIAL_DEVICE

Serial Device

◆ serial_enumerate_cb

typedef uint32_t STDCALL(* serial_enumerate_cb) (SERIAL_DEVICE *serial, void *data)

Serial Enumeration Callback

◆ serial_notification_cb

typedef uint32_t STDCALL(* serial_notification_cb) (DEVICE *device, void *data, uint32_t notification)

Serial Notification Callback

◆ serial_device_open_proc

typedef uint32_t STDCALL(* serial_device_open_proc) (SERIAL_DEVICE *serial, uint32_t baudrate, uint32_t databits, uint32_t stopbits, uint32_t parity, uint32_t flowcontrol, uint32_t receivedepth, uint32_t transmitdepth)

Serial Device Methods

◆ serial_device_close_proc

typedef uint32_t STDCALL(* serial_device_close_proc) (SERIAL_DEVICE *serial)

◆ serial_device_read_proc

typedef uint32_t STDCALL(* serial_device_read_proc) (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)

◆ serial_device_write_proc

typedef uint32_t STDCALL(* serial_device_write_proc) (SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)

◆ serial_device_wait_proc

typedef uint32_t STDCALL(* serial_device_wait_proc) (SERIAL_DEVICE *serial, uint32_t direction, uint32_t timeout, uint32_t *count)

◆ serial_device_flush_proc

typedef uint32_t STDCALL(* serial_device_flush_proc) (SERIAL_DEVICE *serial, uint32_t flags)

◆ serial_device_get_status_proc

typedef uint32_t STDCALL(* serial_device_get_status_proc) (SERIAL_DEVICE *serial)

◆ serial_device_set_status_proc

typedef uint32_t STDCALL(* serial_device_set_status_proc) (SERIAL_DEVICE *serial, uint32_t status)

◆ serial_device_get_properties_proc

typedef uint32_t STDCALL(* serial_device_get_properties_proc) (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)

◆ serial_device_set_properties_proc

typedef uint32_t STDCALL(* serial_device_set_properties_proc) (SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)

Function Documentation

◆ serial_device_open()

uint32_t STDCALL serial_device_open ( SERIAL_DEVICE * serial,
uint32_t baudrate,
uint32_t databits,
uint32_t stopbits,
uint32_t parity,
uint32_t flowcontrol,
uint32_t receivedepth,
uint32_t transmitdepth )

Open a Serial device ready for sending and receiving.

Serial Functions

Parameters
SerialThe Serial device to open
BaudRateBaud rate for the connection (eg 9600, 57600, 115200 etc
DataBitsSize of the data (eg SERIAL_DATA_8BIT)
StopBitsNumber of stop bits (eg SERIAL_STOP_1BIT)
ParityParity type for the data (eg SERIAL_PARITY_NONE)
FlowControlFlow control for the connection (eg SERIAL_FLOW_NONE)
ReceiveDepthSize of the receive buffer (0 = Default size)
TransmitDepthSize of the transmit buffer (0 = Default size)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_close()

uint32_t STDCALL serial_device_close ( SERIAL_DEVICE * serial)

Close a Serial device and terminate sending and receiving.

Parameters
SerialThe Serial device to close
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_read()

uint32_t STDCALL serial_device_read ( SERIAL_DEVICE * serial,
void * buffer,
uint32_t size,
uint32_t flags,
uint32_t * count )

Read data from a Serial device.

Parameters
SerialThe Serial device to read from
BufferPointer to a buffer to receive the data
SizeThe size of the buffer
FlagsThe flags to control reading (eg SERIAL_READ_NON_BLOCK)
CountThe number of bytes read on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_write()

uint32_t STDCALL serial_device_write ( SERIAL_DEVICE * serial,
void * buffer,
uint32_t size,
uint32_t flags,
uint32_t * count )

Write data to a Serial device.

Parameters
SerialThe Serial device to write to
BufferPointer to a buffer of data to transmit
SizeThe size of the buffer
FlagsThe flags to control writing (eg SERIAL_WRITE_NON_BLOCK)
CountThe number of bytes written on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_wait()

uint32_t STDCALL serial_device_wait ( SERIAL_DEVICE * serial,
uint32_t direction,
uint32_t timeout,
uint32_t * count )

Wait for data to be available in the receive or transmit buffers of a Serial device.

Parameters
SerialThe Serial device to wait for
DirectionThe direction of data to wait for (eg SERIAL_WAIT_RECEIVE)
TimeoutThe number of milliseconds to wait for data (INFINITE to wait forever)
CountThe number of bytes available on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_flush()

uint32_t STDCALL serial_device_flush ( SERIAL_DEVICE * serial,
uint32_t flags )

Discard the contents of the receive and/or transmit buffers of a Serial device.

Parameters
SerialThe Serial device to flush
FlagsThe flags to indicate what to flush (eg SERIAL_FLUSH_RECEIVE)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_status()

uint32_t STDCALL serial_device_status ( SERIAL_DEVICE * serial)

Get the current line status of a Serial device.

Parameters
SerialThe Serial device to get the status from
Returns
A set of flags containing the device status (eg SERIAL_STATUS_RTS)
Note
Replaced by SerialDeviceGetStatus for consistency

◆ serial_device_get_status()

uint32_t STDCALL serial_device_get_status ( SERIAL_DEVICE * serial)

Get the current line status of a Serial device.

Parameters
SerialThe Serial device to get the status from
Returns
A set of flags containing the device status (eg SERIAL_STATUS_RTS)

◆ serial_device_set_status()

uint32_t STDCALL serial_device_set_status ( SERIAL_DEVICE * serial,
uint32_t status )

Set the current line status of a Serial device.

Parameters
SerialThe Serial device to set the status for
StatusThe device status flags to be set (eg SERIAL_STATUS_RTS)
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Not all SERIAL_STATUS_* flags can be set, the device may ignore invalid values
Not all serial devices support set status, returns ERROR_CALL_NOT_IMPLEMENTED if not supported

◆ serial_device_properties()

uint32_t STDCALL serial_device_properties ( SERIAL_DEVICE * serial,
SERIAL_PROPERTIES * properties )

Get the properties for the specified Serial device.

Parameters
SerialThe Serial device to get properties from
PropertiesPointer to a PSerialProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Replaced by SerialDeviceGetProperties for consistency

◆ serial_device_get_properties()

uint32_t STDCALL serial_device_get_properties ( SERIAL_DEVICE * serial,
SERIAL_PROPERTIES * properties )

Get the properties for the specified Serial device.

Parameters
SerialThe Serial device to get properties from
PropertiesPointer to a PSerialProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_set_properties()

uint32_t STDCALL serial_device_set_properties ( SERIAL_DEVICE * serial,
SERIAL_PROPERTIES * properties )

Set the properties for the specified Serial device.

Parameters
SerialThe Serial device to set properties for
PropertiesPointer to a PSerialProperties structure to use
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_create()

SERIAL_DEVICE *STDCALL serial_device_create ( void )

Create a new Serial entry.

Returns
Pointer to new Serial entry or nil if Serial could not be created

◆ serial_device_create_ex()

SERIAL_DEVICE *STDCALL serial_device_create_ex ( uint32_t size)

Create a new Serial entry.

Parameters
SizeSize in bytes to allocate for new Serial (Including the Serial entry)
Returns
Pointer to new Serial entry or nil if Serial could not be created

◆ serial_device_destroy()

uint32_t STDCALL serial_device_destroy ( SERIAL_DEVICE * serial)

Destroy an existing Serial entry.

Parameters
SerialThe serial device to destroy
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_register()

uint32_t STDCALL serial_device_register ( SERIAL_DEVICE * serial)

Register a new Serial in the Serial table.

Parameters
SerialThe serial device to register
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_deregister()

uint32_t STDCALL serial_device_deregister ( SERIAL_DEVICE * serial)

Deregister a Serial from the Serial table.

Parameters
SerialThe serial device to deregister
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_find()

SERIAL_DEVICE *STDCALL serial_device_find ( uint32_t serialid)

Find a serial device by ID in the serial table.

Parameters
SerialIdThe ID number of the serial to find
Returns
Pointer to serial device entry or nil if not found

◆ serial_device_find_by_name()

SERIAL_DEVICE *STDCALL serial_device_find_by_name ( const char * name)

Find a serial device by name in the serial table.

Parameters
NameThe name of the serial to find (eg Serial0)
Returns
Pointer to serial device entry or nil if not found

◆ serial_device_find_by_description()

SERIAL_DEVICE *STDCALL serial_device_find_by_description ( const char * description)

Find a serial device by description in the serial table.

Parameters
DescriptionThe description of the serial to find (eg BCM2836 PL011 UART)
Returns
Pointer to serial device entry or nil if not found

◆ serial_device_enumerate()

uint32_t STDCALL serial_device_enumerate ( serial_enumerate_cb callback,
void * data )

Enumerate all serial devices in the serial table.

Parameters
CallbackThe callback function to call for each serial in the table
DataA private data pointer to pass to callback for each serial in the table
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ serial_device_notification()

uint32_t STDCALL serial_device_notification ( SERIAL_DEVICE * serial,
serial_notification_cb callback,
void * data,
uint32_t notification,
uint32_t flags )

Register a notification for serial device changes.

Parameters
SerialThe serial device to notify changes for (Optional, pass nil for all serial devices)
CallbackThe function to call when a notification event occurs
DataA private data pointer to pass to callback when a notification event occurs
NotificationThe events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
FlagsThe flags to control the notification (eg NOTIFIER_FLAG_WORKER)

◆ serial_device_printf()

int STDCALL serial_device_printf ( SERIAL_DEVICE * serial,
const char * format,
... )

Print formatted text to a Serial device.

Parameters
SerialThe serial device to print text to
FormatThe formatted text to print (As per printf in standard C library)
Returns
On success the total number of characters sent to the serial device, on error a negative value is returned and errno is set to the error code

◆ serial_get_count()

int STDCALL uint32_t STDCALL serial_get_count ( void )

Get the current Serial count.

Serial Helper Functions

◆ serial_device_get_default()

SERIAL_DEVICE *STDCALL serial_device_get_default ( void )

Get the current default Serial device.

◆ serial_device_set_default()

uint32_t STDCALL serial_device_set_default ( SERIAL_DEVICE * serial)

Set the current default Serial device.

◆ serial_device_check()

SERIAL_DEVICE *STDCALL serial_device_check ( SERIAL_DEVICE * serial)

Check if the supplied Serial is in the Serial table.

◆ serial_type_to_string()

uint32_t STDCALL serial_type_to_string ( uint32_t serialtype,
char * string,
uint32_t len )

Convert a Serial type value to a string.

◆ serial_state_to_string()

uint32_t STDCALL serial_state_to_string ( uint32_t serialstate,
char * string,
uint32_t len )

Convert a Serial state value to a string.

◆ serial_device_redirect_input()

BOOL STDCALL serial_device_redirect_input ( SERIAL_DEVICE * serial)

Redirect standard input to the serial device specified by Serial.

Parameters
SerialThe serial device to redirect input to (or nil to stop redirection)
Returns
True if completed successfully or False if an error occurred
Note
Redirects the input of the text file Input which also redirects the input of Read, ReadLn and the standard C library

◆ serial_device_redirect_output()

BOOL STDCALL serial_device_redirect_output ( SERIAL_DEVICE * serial)

Redirect standard output to the serial device specified by Serial.

Parameters
SerialThe serial device to redirect output to (or nil to stop redirection)
Returns
True if completed successfully or False if an error occurred
Note
Redirects the output of the text files Output, ErrOutput, StdOut and StdErr which also redirects the output of Write, WriteLn and the standard C library

◆ serial_buffer_read_start()

void *STDCALL serial_buffer_read_start ( SERIAL_BUFFER * buffer,
uint32_t * available )

Return a pointer to the next read from the buffer and the number of bytes that can be read.

Note
Caller must hold the lock on the serial device which owns the buffer

◆ serial_buffer_read_complete()

BOOL STDCALL serial_buffer_read_complete ( SERIAL_BUFFER * buffer,
uint32_t removed )

Update the buffer to reflect the number of bytes removed when reading.

Note
Caller must hold the lock on the serial device which owns the buffer

◆ serial_buffer_write_start()

void *STDCALL serial_buffer_write_start ( SERIAL_BUFFER * buffer,
uint32_t * available )

Return a pointer to the next write to the buffer and the number of bytes that can be written.

Note
Caller must hold the lock on the serial device which owns the buffer

◆ serial_buffer_write_complete()

BOOL STDCALL serial_buffer_write_complete ( SERIAL_BUFFER * buffer,
uint32_t added )

Update the buffer to reflect the number of bytes added when writing.

Note
Caller must hold the lock on the serial device which owns the buffer

◆ serial_data_bits_to_string()

uint32_t STDCALL serial_data_bits_to_string ( uint32_t bits,
char * string,
uint32_t len )

◆ serial_stop_bits_to_string()

uint32_t STDCALL serial_stop_bits_to_string ( uint32_t bits,
char * string,
uint32_t len )

◆ serial_parity_to_string()

uint32_t STDCALL serial_parity_to_string ( uint32_t parity,
char * string,
uint32_t len )

◆ serial_flow_control_to_string()

uint32_t STDCALL serial_flow_control_to_string ( uint32_t flow,
char * string,
uint32_t len )

◆ serial_logging_device_add()

uint32_t STDCALL serial_logging_device_add ( SERIAL_DEVICE * serial)

Add a new serial logging device on receipt of a device register notification.

Serial Logging Helper Functions

◆ serial_logging_device_remove()

uint32_t STDCALL serial_logging_device_remove ( SERIAL_DEVICE * serial)

Remove a serial logging device on receipt of a device deregister notification.

◆ serial_logging_device_parameters()

uint32_t STDCALL serial_logging_device_parameters ( SERIAL_DEVICE * serial,
const char * parameters,
uint32_t * baudrate,
uint32_t * parity,
uint32_t * databits,
uint32_t * stopbits )

Break down the serial parameters value into component parts of baud rate, parity, data bits and stop bits The parameters must be in the form 'BaudRate,Parity,DataBits,StopBits' (eg '115200,N,8,1').