26#ifndef _ULTIBO_SERIAL_H
27#define _ULTIBO_SERIAL_H
38#define SERIAL_NAME_PREFIX "Serial"
40#define SERIAL_LOGGING_DESCRIPTION "Serial Logging"
42#define SERIAL_RECEIVE_DEPTH_DEFAULT SIZE_2K
43#define SERIAL_TRANSMIT_DEPTH_DEFAULT SIZE_2K
45#define SERIAL_PUSH_TIMEOUT 50
48#define SERIAL_TYPE_NONE 0
49#define SERIAL_TYPE_UART 1
50#define SERIAL_TYPE_USB 2
52#define SERIAL_TYPE_MAX 2
55#define SERIAL_STATE_CLOSED 0
56#define SERIAL_STATE_CLOSING 1
57#define SERIAL_STATE_OPENING 2
58#define SERIAL_STATE_OPEN 3
60#define SERIAL_STATE_MAX 3
63#define SERIAL_FLAG_NONE 0x00000000
64#define SERIAL_FLAG_DATA_8BIT 0x00000001
65#define SERIAL_FLAG_DATA_7BIT 0x00000002
66#define SERIAL_FLAG_DATA_6BIT 0x00000004
67#define SERIAL_FLAG_DATA_5BIT 0x00000008
68#define SERIAL_FLAG_STOP_1BIT 0x00000010
69#define SERIAL_FLAG_STOP_2BIT 0x00000020
70#define SERIAL_FLAG_STOP_1BIT5 0x00000040
71#define SERIAL_FLAG_PARITY_ODD 0x00000080
72#define SERIAL_FLAG_PARITY_EVEN 0x00000100
73#define SERIAL_FLAG_PARITY_MARK 0x00000200
74#define SERIAL_FLAG_PARITY_SPACE 0x00000400
75#define SERIAL_FLAG_FLOW_RTS_CTS 0x00000800
76#define SERIAL_FLAG_FLOW_DSR_DTR 0x00001000
77#define SERIAL_FLAG_PUSH_RX 0x00002000
78#define SERIAL_FLAG_PUSH_TX 0x00004000
81#define SERIAL_READ_NONE 0x00000000
82#define SERIAL_READ_NON_BLOCK 0x00000001
83#define SERIAL_READ_PEEK_BUFFER 0x00000002
86#define SERIAL_WRITE_NONE 0x00000000
87#define SERIAL_WRITE_NON_BLOCK 0x00000001
88#define SERIAL_WRITE_PEEK_BUFFER 0x00000002
91#define SERIAL_WAIT_NONE 0
92#define SERIAL_WAIT_RECEIVE 1
93#define SERIAL_WAIT_TRANSMIT 2
96#define SERIAL_FLUSH_NONE 0x00000000
97#define SERIAL_FLUSH_RECEIVE 0x00000001
98#define SERIAL_FLUSH_TRANSMIT 0x00000002
101#define SERIAL_STATUS_NONE 0x00000000
102#define SERIAL_STATUS_RTS 0x00000001
103#define SERIAL_STATUS_CTS 0x00000002
104#define SERIAL_STATUS_DSR 0x00000004
105#define SERIAL_STATUS_DTR 0x00000008
106#define SERIAL_STATUS_RX_FULL 0x00000010
107#define SERIAL_STATUS_RX_EMPTY 0x00000020
108#define SERIAL_STATUS_TX_FULL 0x00000040
109#define SERIAL_STATUS_TX_EMPTY 0x00000080
110#define SERIAL_STATUS_BUSY 0x00000100
111#define SERIAL_STATUS_BREAK_ERROR 0x00000200
112#define SERIAL_STATUS_PARITY_ERROR 0x00000400
113#define SERIAL_STATUS_FRAMING_ERROR 0x00000800
114#define SERIAL_STATUS_OVERRUN_ERROR 0x00001000
115#define SERIAL_STATUS_DCD 0x00002000
116#define SERIAL_STATUS_RI 0x00004000
220uint32_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);
struct _DEVICE DEVICE
Definition devices.h:373
HANDLE EVENT_HANDLE
Definition globaltypes.h:117
#define STDCALL
Definition globaltypes.h:45
_Bool BOOL
Built in Boolean type (1 byte) (Redeclared here for flexibility).
Definition globaltypes.h:55
HANDLE MUTEX_HANDLE
Definition globaltypes.h:105
uint32_t STDCALL serial_flow_control_to_string(uint32_t flow, char *string, uint32_t len)
SERIAL_DEVICE *STDCALL serial_device_get_default(void)
Get the current default Serial device.
uint32_t STDCALL(* serial_enumerate_cb)(SERIAL_DEVICE *serial, void *data)
Definition serial.h:151
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_device_deregister(SERIAL_DEVICE *serial)
Deregister a Serial from the Serial table.
uint32_t STDCALL(* serial_device_get_status_proc)(SERIAL_DEVICE *serial)
Definition serial.h:165
SERIAL_DEVICE *STDCALL serial_device_create(void)
Create a new Serial entry.
uint32_t STDCALL serial_device_close(SERIAL_DEVICE *serial)
Close a Serial device and terminate sending and receiving.
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.
uint32_t STDCALL(* serial_device_flush_proc)(SERIAL_DEVICE *serial, uint32_t flags)
Definition serial.h:163
uint32_t STDCALL serial_device_destroy(SERIAL_DEVICE *serial)
Destroy an existing Serial entry.
uint32_t STDCALL serial_logging_device_remove(SERIAL_DEVICE *serial)
Remove a serial logging device on receipt of a device deregister notification.
struct _SERIAL_PROPERTIES SERIAL_PROPERTIES
Definition serial.h:121
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_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_stop_bits_to_string(uint32_t bits, char *string, uint32_t len)
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_device_set_default(SERIAL_DEVICE *serial)
Set the current default Serial device.
uint32_t STDCALL serial_device_set_properties(SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
Set the properties for the specified Serial device.
uint32_t STDCALL serial_state_to_string(uint32_t serialstate, char *string, uint32_t len)
Convert a Serial state value to a string.
uint32_t STDCALL serial_device_status(SERIAL_DEVICE *serial)
Get the current line status of a Serial device.
struct _SERIAL_DEVICE SERIAL_DEVICE
Definition serial.h:148
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_get_properties_proc)(SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
Definition serial.h:168
uint32_t STDCALL serial_device_enumerate(serial_enumerate_cb callback, void *data)
Enumerate all serial devices in the serial table.
BOOL STDCALL serial_buffer_read_complete(SERIAL_BUFFER *buffer, uint32_t removed)
Update the buffer to reflect the number of bytes removed when reading.
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.
SERIAL_DEVICE *STDCALL serial_device_find(uint32_t serialid)
Find a serial device by ID in the serial table.
uint32_t STDCALL(* serial_notification_cb)(DEVICE *device, void *data, uint32_t notification)
Definition serial.h:153
uint32_t STDCALL serial_parity_to_string(uint32_t parity, char *string, uint32_t len)
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)
Definition serial.h:156
uint32_t STDCALL(* serial_device_set_status_proc)(SERIAL_DEVICE *serial, uint32_t status)
Definition serial.h:166
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_register(SERIAL_DEVICE *serial)
Register a new Serial in the Serial table.
uint32_t STDCALL serial_device_get_status(SERIAL_DEVICE *serial)
Get the current line status of a Serial device.
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.
uint32_t STDCALL(* serial_device_wait_proc)(SERIAL_DEVICE *serial, uint32_t direction, uint32_t timeout, uint32_t *count)
Definition serial.h:162
SERIAL_DEVICE *STDCALL serial_device_find_by_name(const char *name)
Find a serial device by name in the serial table.
uint32_t STDCALL(* serial_device_read_proc)(SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
Definition serial.h:159
int STDCALL uint32_t STDCALL serial_get_count(void)
Get the current Serial count.
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_proc)(SERIAL_DEVICE *serial)
Definition serial.h:157
BOOL STDCALL serial_device_redirect_input(SERIAL_DEVICE *serial)
Redirect standard input to the serial device specified by Serial.
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_device_redirect_output(SERIAL_DEVICE *serial)
Redirect standard output to the serial device specified by Serial.
struct _SERIAL_BUFFER SERIAL_BUFFER
Definition serial.h:137
SERIAL_DEVICE *STDCALL serial_device_check(SERIAL_DEVICE *serial)
Check if the supplied Serial is in the Serial table.
uint32_t STDCALL serial_data_bits_to_string(uint32_t bits, char *string, uint32_t len)
uint32_t STDCALL(* serial_device_set_properties_proc)(SERIAL_DEVICE *serial, SERIAL_PROPERTIES *properties)
Definition serial.h:169
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.
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_type_to_string(uint32_t serialtype, char *string, uint32_t len)
Convert a Serial type value to a string.
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 ...
int STDCALL serial_device_printf(SERIAL_DEVICE *serial, const char *format,...) _ATTRIBUTE((__format__(__printf__
Print formatted text to a Serial device.
SERIAL_DEVICE *STDCALL serial_device_create_ex(uint32_t size)
Create a new Serial entry.
uint32_t STDCALL(* serial_device_write_proc)(SERIAL_DEVICE *serial, void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
Definition serial.h:160
EVENT_HANDLE wait
Data ready / Buffer free event.
Definition serial.h:140
uint32_t start
Index of first byte in buffer.
Definition serial.h:141
void * data
Buffered data.
Definition serial.h:144
uint32_t count
Number of bytes in buffer.
Definition serial.h:142
uint32_t size
Size of buffer.
Definition serial.h:143
uint32_t transmitcount
Definition serial.h:198
MUTEX_HANDLE lock
Device lock.
Definition serial.h:190
uint32_t serialstate
Serial state (eg SERIAL_STATE_OPEN).
Definition serial.h:177
uint32_t receiveerrors
Definition serial.h:196
serial_device_set_properties_proc devicesetproperties
A Device specific DeviceSetProperties method implementing the standard Serial device interface (Or ni...
Definition serial.h:188
SERIAL_BUFFER receive
Serial receive buffer.
Definition serial.h:191
serial_device_close_proc deviceclose
A Device specific DeviceClose method implementing the standard Serial device interface (Mandatory).
Definition serial.h:180
uint32_t transmitoverruns
Definition serial.h:200
DEVICE device
The Device entry for this Serial.
Definition serial.h:174
SERIAL_PROPERTIES properties
Device properties.
Definition serial.h:193
serial_device_write_proc devicewrite
A Device specific DeviceWrite method implementing the standard Serial device interface (Mandatory).
Definition serial.h:182
uint32_t receivecount
Definition serial.h:195
SERIAL_BUFFER transmit
Serial transmit buffer.
Definition serial.h:192
serial_device_set_status_proc devicesetstatus
A Device specific DeviceSetStatus method implementing the standard Serial device interface (Optional)...
Definition serial.h:186
uint32_t receiveoverruns
Definition serial.h:197
SERIAL_DEVICE * prev
Previous entry in Serial table.
Definition serial.h:202
SERIAL_DEVICE * next
Next entry in Serial table.
Definition serial.h:203
serial_device_get_properties_proc devicegetproperties
A Device specific DeviceGetProperties method implementing the standard Serial device interface (Or ni...
Definition serial.h:187
serial_device_get_status_proc devicegetstatus
A Device specific DeviceGetStatus method implementing the standard Serial device interface (Or nil if...
Definition serial.h:185
serial_device_flush_proc deviceflush
A Device specific DeviceFlush method implementing the standard Serial device interface (Or nil if the...
Definition serial.h:184
uint32_t serialid
Unique Id of this Serial device in the Serial device table.
Definition serial.h:176
uint32_t transmiterrors
Definition serial.h:199
uint32_t serialstatus
Serial status (eg SERIAL_STATUS_RX_FULL)(May not be real time status depending on the driver).
Definition serial.h:178
serial_device_wait_proc devicewait
A Device specific DeviceWait method implementing the standard Serial device interface (Or nil if the ...
Definition serial.h:183
serial_device_read_proc deviceread
A Device specific DeviceRead method implementing the standard Serial device interface (Mandatory).
Definition serial.h:181
serial_device_open_proc deviceopen
A Device specific DeviceOpen method implementing the standard Serial device interface (Mandatory).
Definition serial.h:179
uint32_t minrate
Minimum supported baud rate (0 for any rate supported).
Definition serial.h:125
uint32_t transmitdepth
Current transmit depth setting.
Definition serial.h:133
uint32_t parity
Current parity setting.
Definition serial.h:130
uint32_t flags
Device flags (eg SERIAL_FLAG_DATA_8BIT).
Definition serial.h:124
uint32_t maxrate
Maximum supported baud rate (0 for any rate supported).
Definition serial.h:126
uint32_t stopbits
Current stop bits setting.
Definition serial.h:129
uint32_t flowcontrol
Current flow control setting.
Definition serial.h:131
uint32_t databits
Current data bits setting.
Definition serial.h:128
uint32_t baudrate
Current baud rate setting.
Definition serial.h:127
uint32_t receivedepth
Current receive depth setting.
Definition serial.h:132