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