2 Debug Port Library implementation based on serial port.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugCommunicationLib.h>
18 #include <Library/SerialPortLib.h>
19 #include <Library/DebugLib.h>
22 Initialize the debug port.
24 This function will initialize debug port to get it ready for data transmition. If
25 certain Debug Communication Library instance has to save some private data in the
26 stack, this function must work on the mode that doesn't return to the caller, then
27 the caller needs to wrap up all rest of logic after DebugPortInitialize() into one
28 function and pass it into DebugPortInitialize(). DebugPortInitialize() is
29 responsible to invoke the passing-in function at the end of DebugPortInitialize().
31 If the parameter Function is not NULL, Debug Communication Library instance will
32 invoke it by passing in the Context to be the first parameter. Debug Communication
33 Library instance could create one debug port handle to be the second parameter
34 passing into the Function. Debug Communication Library instance also could pass
35 NULL to be the second parameter if it doesn't create the debug port handle.
37 If the parameter Function is NULL, and Context is not NULL. At this time, Context
38 is the debug port handle created by the previous Debug Communication Library
40 a) If the instance can understand and continue use the private data of the previous
41 instance, it could return the same handle as passed in (as Context parameter).
42 b) If the instance does not understand, or does not want to continue use the
43 private data of the previous instance, it could ignore the input Context parameter
44 and create the new handle to be returned.
46 If Function() is NULL and Context is NULL, Debug Communication Library could create a
47 new handle and return it. NULL is also a valid handle to be returned.
49 @param[in] Context Context needed by callback function; it was optional.
50 @param[in] Function Continue function called by Debug Communication library;
53 @return The debug port handle created by Debug Communication Library if Function
61 IN DEBUG_PORT_CONTINUE Function
66 Status
= SerialPortInitialize ();
67 if (RETURN_ERROR(Status
)) {
68 DEBUG ((EFI_D_ERROR
, "Debug Serial Port: Initialization failed!\n"));
71 if (Function
!= NULL
) {
72 Function (Context
, NULL
);
79 Read data from debug device and save the datas in buffer.
81 Reads NumberOfBytes data bytes from a debug device into the buffer
82 specified by Buffer. The number of bytes actually read is returned.
83 If the return value is less than NumberOfBytes, then the rest operation failed.
84 If NumberOfBytes is zero, then return 0.
86 @param Handle Debug port handle.
87 @param Buffer Pointer to the data buffer to store the data read from the debug device.
88 @param NumberOfBytes Number of bytes which will be read.
89 @param Timeout Timeout value for reading from debug device. It unit is Microsecond.
91 @retval 0 Read data failed, no data is to be read.
92 @retval >0 Actual number of bytes read from debug device.
98 IN DEBUG_PORT_HANDLE Handle
,
100 IN UINTN NumberOfBytes
,
104 if (NumberOfBytes
!= 1 || Buffer
== NULL
|| Timeout
!= 0) {
108 return SerialPortRead (Buffer
, 1);
112 Write data from buffer to debug device.
114 Writes NumberOfBytes data bytes from Buffer to the debug device.
115 The number of bytes actually written to the debug device is returned.
116 If the return value is less than NumberOfBytes, then the write operation failed.
117 If NumberOfBytes is zero, then return 0.
119 @param Handle Debug port handle.
120 @param Buffer Pointer to the data buffer to be written.
121 @param NumberOfBytes Number of bytes to written to the debug device.
123 @retval 0 NumberOfBytes is 0.
124 @retval >0 The number of bytes written to the debug device.
125 If this value is less than NumberOfBytes, then the read operation failed.
130 DebugPortWriteBuffer (
131 IN DEBUG_PORT_HANDLE Handle
,
133 IN UINTN NumberOfBytes
136 return SerialPortWrite (Buffer
, NumberOfBytes
);
140 Polls a debug device to see if there is any data waiting to be read.
142 Polls a debug device to see if there is any data waiting to be read.
143 If there is data waiting to be read from the debug device, then TRUE is returned.
144 If there is no data waiting to be read from the debug device, then FALSE is returned.
146 @param Handle Debug port handle.
148 @retval TRUE Data is waiting to be read from the debug device.
149 @retval FALSE There is no data waiting to be read from the serial device.
154 DebugPortPollBuffer (
155 IN DEBUG_PORT_HANDLE Handle
158 return SerialPortPoll ();