• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   This library class provides common serial I/O port functions.
3 
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef __SERIAL_PORT_LIB__
17 #define __SERIAL_PORT_LIB__
18 
19 #include <Uefi/UefiBaseType.h>
20 #include <Protocol/SerialIo.h>
21 
22 /**
23   Initialize the serial device hardware.
24 
25   If no initialization is required, then return RETURN_SUCCESS.
26   If the serial device was successfully initialized, then return RETURN_SUCCESS.
27   If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
28 
29   @retval RETURN_SUCCESS        The serial device was initialized.
30   @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.
31 
32 **/
33 RETURN_STATUS
34 EFIAPI
35 SerialPortInitialize (
36   VOID
37   );
38 
39 /**
40   Write data from buffer to serial device.
41 
42   Writes NumberOfBytes data bytes from Buffer to the serial device.
43   The number of bytes actually written to the serial device is returned.
44   If the return value is less than NumberOfBytes, then the write operation failed.
45   If Buffer is NULL, then ASSERT().
46   If NumberOfBytes is zero, then return 0.
47 
48   @param  Buffer           Pointer to the data buffer to be written.
49   @param  NumberOfBytes    Number of bytes to written to the serial device.
50 
51   @retval 0                NumberOfBytes is 0.
52   @retval >0               The number of bytes written to the serial device.
53                            If this value is less than NumberOfBytes, then the write operation failed.
54 
55 **/
56 UINTN
57 EFIAPI
58 SerialPortWrite (
59   IN UINT8     *Buffer,
60   IN UINTN     NumberOfBytes
61   );
62 
63 
64 /**
65   Read data from serial device and save the datas in buffer.
66 
67   Reads NumberOfBytes data bytes from a serial device into the buffer
68   specified by Buffer. The number of bytes actually read is returned.
69   If the return value is less than NumberOfBytes, then the rest operation failed.
70   If Buffer is NULL, then ASSERT().
71   If NumberOfBytes is zero, then return 0.
72 
73   @param  Buffer           Pointer to the data buffer to store the data read from the serial device.
74   @param  NumberOfBytes    Number of bytes which will be read.
75 
76   @retval 0                Read data failed, no data is to be read.
77   @retval >0               Actual number of bytes read from serial device.
78 
79 **/
80 UINTN
81 EFIAPI
82 SerialPortRead (
83   OUT UINT8   *Buffer,
84   IN  UINTN   NumberOfBytes
85   );
86 
87 /**
88   Polls a serial device to see if there is any data waiting to be read.
89 
90   Polls a serial device to see if there is any data waiting to be read.
91   If there is data waiting to be read from the serial device, then TRUE is returned.
92   If there is no data waiting to be read from the serial device, then FALSE is returned.
93 
94   @retval TRUE             Data is waiting to be read from the serial device.
95   @retval FALSE            There is no data waiting to be read from the serial device.
96 
97 **/
98 BOOLEAN
99 EFIAPI
100 SerialPortPoll (
101   VOID
102   );
103 
104 /**
105   Sets the control bits on a serial device.
106 
107   @param Control                Sets the bits of Control that are settable.
108 
109   @retval RETURN_SUCCESS        The new control bits were set on the serial device.
110   @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
111   @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
112 
113 **/
114 RETURN_STATUS
115 EFIAPI
116 SerialPortSetControl (
117   IN UINT32 Control
118   );
119 
120 /**
121   Retrieve the status of the control bits on a serial device.
122 
123   @param Control                A pointer to return the current control signals from the serial device.
124 
125   @retval RETURN_SUCCESS        The control bits were read from the serial device.
126   @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
127   @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
128 
129 **/
130 RETURN_STATUS
131 EFIAPI
132 SerialPortGetControl (
133   OUT UINT32 *Control
134   );
135 
136 /**
137   Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
138   data bits, and stop bits on a serial device.
139 
140   @param BaudRate           The requested baud rate. A BaudRate value of 0 will use the
141                             device's default interface speed.
142                             On output, the value actually set.
143   @param ReveiveFifoDepth   The requested depth of the FIFO on the receive side of the
144                             serial interface. A ReceiveFifoDepth value of 0 will use
145                             the device's default FIFO depth.
146                             On output, the value actually set.
147   @param Timeout            The requested time out for a single character in microseconds.
148                             This timeout applies to both the transmit and receive side of the
149                             interface. A Timeout value of 0 will use the device's default time
150                             out value.
151                             On output, the value actually set.
152   @param Parity             The type of parity to use on this serial device. A Parity value of
153                             DefaultParity will use the device's default parity value.
154                             On output, the value actually set.
155   @param DataBits           The number of data bits to use on the serial device. A DataBits
156                             vaule of 0 will use the device's default data bit setting.
157                             On output, the value actually set.
158   @param StopBits           The number of stop bits to use on this serial device. A StopBits
159                             value of DefaultStopBits will use the device's default number of
160                             stop bits.
161                             On output, the value actually set.
162 
163   @retval RETURN_SUCCESS            The new attributes were set on the serial device.
164   @retval RETURN_UNSUPPORTED        The serial device does not support this operation.
165   @retval RETURN_INVALID_PARAMETER  One or more of the attributes has an unsupported value.
166   @retval RETURN_DEVICE_ERROR       The serial device is not functioning correctly.
167 
168 **/
169 RETURN_STATUS
170 EFIAPI
171 SerialPortSetAttributes (
172   IN OUT UINT64             *BaudRate,
173   IN OUT UINT32             *ReceiveFifoDepth,
174   IN OUT UINT32             *Timeout,
175   IN OUT EFI_PARITY_TYPE    *Parity,
176   IN OUT UINT8              *DataBits,
177   IN OUT EFI_STOP_BITS_TYPE *StopBits
178   );
179 
180 #endif
181