2 Debug Port Library implementation based on serial port.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugCommunicationLib.h>
12 #include <Library/SerialPortLib.h>
13 #include <Library/DebugLib.h>
16 Initialize the debug port.
18 This function will initialize debug port to get it ready for data transmission. If
19 certain Debug Communication Library instance has to save some private data in the
20 stack, this function must work on the mode that doesn't return to the caller, then
21 the caller needs to wrap up all rest of logic after DebugPortInitialize() into one
22 function and pass it into DebugPortInitialize(). DebugPortInitialize() is
23 responsible to invoke the passing-in function at the end of DebugPortInitialize().
25 If the parameter Function is not NULL, Debug Communication Library instance will
26 invoke it by passing in the Context to be the first parameter. Debug Communication
27 Library instance could create one debug port handle to be the second parameter
28 passing into the Function. Debug Communication Library instance also could pass
29 NULL to be the second parameter if it doesn't create the debug port handle.
31 If the parameter Function is NULL, and Context is not NULL. At this time, Context
32 is the debug port handle created by the previous Debug Communication Library
34 a) If the instance can understand and continue use the private data of the previous
35 instance, it could return the same handle as passed in (as Context parameter).
36 b) If the instance does not understand, or does not want to continue use the
37 private data of the previous instance, it could ignore the input Context parameter
38 and create the new handle to be returned.
40 If Function() is NULL and Context is NULL, Debug Communication Library could create a
41 new handle and return it. NULL is also a valid handle to be returned.
43 @param[in] Context Context needed by callback function; it was optional.
44 @param[in] Function Continue function called by Debug Communication library;
47 @return The debug port handle created by Debug Communication Library if Function
55 IN DEBUG_PORT_CONTINUE Function
60 Status
= SerialPortInitialize ();
61 if (RETURN_ERROR(Status
)) {
62 DEBUG ((EFI_D_ERROR
, "Debug Serial Port: Initialization failed!\n"));
65 if (Function
!= NULL
) {
66 Function (Context
, NULL
);
73 Read data from debug device and save the datas in buffer.
75 Reads NumberOfBytes data bytes from a debug device into the buffer
76 specified by Buffer. The number of bytes actually read is returned.
77 If the return value is less than NumberOfBytes, then the rest operation failed.
78 If NumberOfBytes is zero, then return 0.
80 @param Handle Debug port handle.
81 @param Buffer Pointer to the data buffer to store the data read from the debug device.
82 @param NumberOfBytes Number of bytes which will be read.
83 @param Timeout Timeout value for reading from debug device. It unit is Microsecond.
85 @retval 0 Read data failed, no data is to be read.
86 @retval >0 Actual number of bytes read from debug device.
92 IN DEBUG_PORT_HANDLE Handle
,
94 IN UINTN NumberOfBytes
,
98 if (NumberOfBytes
!= 1 || Buffer
== NULL
|| Timeout
!= 0) {
102 return SerialPortRead (Buffer
, 1);
106 Write data from buffer to debug device.
108 Writes NumberOfBytes data bytes from Buffer to the debug device.
109 The number of bytes actually written to the debug device is returned.
110 If the return value is less than NumberOfBytes, then the write operation failed.
111 If NumberOfBytes is zero, then return 0.
113 @param Handle Debug port handle.
114 @param Buffer Pointer to the data buffer to be written.
115 @param NumberOfBytes Number of bytes to written to the debug device.
117 @retval 0 NumberOfBytes is 0.
118 @retval >0 The number of bytes written to the debug device.
119 If this value is less than NumberOfBytes, then the read operation failed.
124 DebugPortWriteBuffer (
125 IN DEBUG_PORT_HANDLE Handle
,
127 IN UINTN NumberOfBytes
130 return SerialPortWrite (Buffer
, NumberOfBytes
);
134 Polls a debug device to see if there is any data waiting to be read.
136 Polls a debug device to see if there is any data waiting to be read.
137 If there is data waiting to be read from the debug device, then TRUE is returned.
138 If there is no data waiting to be read from the debug device, then FALSE is returned.
140 @param Handle Debug port handle.
142 @retval TRUE Data is waiting to be read from the debug device.
143 @retval FALSE There is no data waiting to be read from the serial device.
148 DebugPortPollBuffer (
149 IN DEBUG_PORT_HANDLE Handle
152 return SerialPortPoll ();