2 This library class provides common serial I/O port functions.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __SERIAL_PORT_LIB__
11 #define __SERIAL_PORT_LIB__
13 #include <Uefi/UefiBaseType.h>
14 #include <Protocol/SerialIo.h>
17 Initialize the serial device hardware.
19 If no initialization is required, then return RETURN_SUCCESS.
20 If the serial device was successfully initialized, then return RETURN_SUCCESS.
21 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
23 @retval RETURN_SUCCESS The serial device was initialized.
24 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
29 SerialPortInitialize (
34 Write data from buffer to serial device.
36 Writes NumberOfBytes data bytes from Buffer to the serial device.
37 The number of bytes actually written to the serial device is returned.
38 If the return value is less than NumberOfBytes, then the write operation failed.
39 If Buffer is NULL, then ASSERT().
40 If NumberOfBytes is zero, then return 0.
42 @param Buffer Pointer to the data buffer to be written.
43 @param NumberOfBytes Number of bytes to written to the serial device.
45 @retval 0 NumberOfBytes is 0.
46 @retval >0 The number of bytes written to the serial device.
47 If this value is less than NumberOfBytes, then the write operation failed.
54 IN UINTN NumberOfBytes
58 Read data from serial device and save the datas in buffer.
60 Reads NumberOfBytes data bytes from a serial device into the buffer
61 specified by Buffer. The number of bytes actually read is returned.
62 If the return value is less than NumberOfBytes, then the rest operation failed.
63 If Buffer is NULL, then ASSERT().
64 If NumberOfBytes is zero, then return 0.
66 @param Buffer Pointer to the data buffer to store the data read from the serial device.
67 @param NumberOfBytes Number of bytes which will be read.
69 @retval 0 Read data failed, no data is to be read.
70 @retval >0 Actual number of bytes read from serial device.
77 IN UINTN NumberOfBytes
81 Polls a serial device to see if there is any data waiting to be read.
83 Polls a serial device to see if there is any data waiting to be read.
84 If there is data waiting to be read from the serial device, then TRUE is returned.
85 If there is no data waiting to be read from the serial device, then FALSE is returned.
87 @retval TRUE Data is waiting to be read from the serial device.
88 @retval FALSE There is no data waiting to be read from the serial device.
98 Sets the control bits on a serial device.
100 @param Control Sets the bits of Control that are settable.
102 @retval RETURN_SUCCESS The new control bits were set on the serial device.
103 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
104 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
109 SerialPortSetControl (
114 Retrieve the status of the control bits on a serial device.
116 @param Control A pointer to return the current control signals from the serial device.
118 @retval RETURN_SUCCESS The control bits were read from the serial device.
119 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
120 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
125 SerialPortGetControl (
130 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
131 data bits, and stop bits on a serial device.
133 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
134 device's default interface speed.
135 On output, the value actually set.
136 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
137 serial interface. A ReceiveFifoDepth value of 0 will use
138 the device's default FIFO depth.
139 On output, the value actually set.
140 @param Timeout The requested time out for a single character in microseconds.
141 This timeout applies to both the transmit and receive side of the
142 interface. A Timeout value of 0 will use the device's default time
144 On output, the value actually set.
145 @param Parity The type of parity to use on this serial device. A Parity value of
146 DefaultParity will use the device's default parity value.
147 On output, the value actually set.
148 @param DataBits The number of data bits to use on the serial device. A DataBits
149 vaule of 0 will use the device's default data bit setting.
150 On output, the value actually set.
151 @param StopBits The number of stop bits to use on this serial device. A StopBits
152 value of DefaultStopBits will use the device's default number of
154 On output, the value actually set.
156 @retval RETURN_SUCCESS The new attributes were set on the serial device.
157 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
158 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
159 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
164 SerialPortSetAttributes (
165 IN OUT UINT64
*BaudRate
,
166 IN OUT UINT32
*ReceiveFifoDepth
,
167 IN OUT UINT32
*Timeout
,
168 IN OUT EFI_PARITY_TYPE
*Parity
,
169 IN OUT UINT8
*DataBits
,
170 IN OUT EFI_STOP_BITS_TYPE
*StopBits