]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
SourceLevelDebugPkg: Fix spelling errors
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibSerialPort / DebugCommunicationLibSerialPort.c
CommitLineData
18b144ea 1/** @file\r
2 Debug Port Library implementation based on serial port.\r
3\r
77695f4d 4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
85f7e110 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
18b144ea 6\r
7**/\r
8\r
9#include <Base.h>\r
10\r
11#include <Library/DebugCommunicationLib.h>\r
12#include <Library/SerialPortLib.h>\r
e2104834 13#include <Library/DebugLib.h>\r
18b144ea 14\r
15/**\r
16 Initialize the debug port.\r
17\r
1825c24f 18 This function will initialize debug port to get it ready for data transmission. If\r
18b144ea 19 certain Debug Communication Library instance has to save some private data in the\r
20 stack, this function must work on the mode that doesn't return to the caller, then\r
21 the caller needs to wrap up all rest of logic after DebugPortInitialize() into one\r
22 function and pass it into DebugPortInitialize(). DebugPortInitialize() is\r
74cdb367 23 responsible to invoke the passing-in function at the end of DebugPortInitialize().\r
18b144ea 24\r
74cdb367 25 If the parameter Function is not NULL, Debug Communication Library instance will\r
18b144ea 26 invoke it by passing in the Context to be the first parameter. Debug Communication\r
27 Library instance could create one debug port handle to be the second parameter\r
28 passing into the Function. Debug Communication Library instance also could pass\r
29 NULL to be the second parameter if it doesn't create the debug port handle.\r
30\r
31 If the parameter Function is NULL, and Context is not NULL. At this time, Context\r
32 is the debug port handle created by the previous Debug Communication Library\r
33 instance.\r
34 a) If the instance can understand and continue use the private data of the previous\r
35 instance, it could return the same handle as passed in (as Context parameter).\r
36 b) If the instance does not understand, or does not want to continue use the\r
37 private data of the previous instance, it could ignore the input Context parameter\r
f95e6f6b 38 and create the new handle to be returned.\r
18b144ea 39\r
40 If Function() is NULL and Context is NULL, Debug Communication Library could create a\r
41 new handle and return it. NULL is also a valid handle to be returned.\r
42\r
43 @param[in] Context Context needed by callback function; it was optional.\r
44 @param[in] Function Continue function called by Debug Communication library;\r
45 it was optional.\r
46\r
47 @return The debug port handle created by Debug Communication Library if Function\r
48 is not NULL.\r
49\r
50**/\r
51DEBUG_PORT_HANDLE\r
52EFIAPI\r
53DebugPortInitialize (\r
54 IN VOID *Context,\r
55 IN DEBUG_PORT_CONTINUE Function\r
56 )\r
57{\r
c1e126b1 58 RETURN_STATUS Status;\r
e2104834 59\r
60 Status = SerialPortInitialize ();\r
c1e126b1 61 if (RETURN_ERROR (Status)) {\r
586fda48 62 DEBUG ((DEBUG_ERROR, "Debug Serial Port: Initialization failed!\n"));\r
e2104834 63 }\r
18b144ea 64\r
65 if (Function != NULL) {\r
08021523 66 Function (Context, NULL);\r
18b144ea 67 }\r
68\r
08021523 69 return NULL;\r
18b144ea 70}\r
71\r
72/**\r
d6d4a81f 73 Read data from debug device and save the data in a buffer.\r
18b144ea 74\r
75 Reads NumberOfBytes data bytes from a debug device into the buffer\r
76 specified by Buffer. The number of bytes actually read is returned.\r
77 If the return value is less than NumberOfBytes, then the rest operation failed.\r
78 If NumberOfBytes is zero, then return 0.\r
79\r
80 @param Handle Debug port handle.\r
81 @param Buffer Pointer to the data buffer to store the data read from the debug device.\r
82 @param NumberOfBytes Number of bytes which will be read.\r
83 @param Timeout Timeout value for reading from debug device. It unit is Microsecond.\r
84\r
85 @retval 0 Read data failed, no data is to be read.\r
86 @retval >0 Actual number of bytes read from debug device.\r
87\r
88**/\r
89UINTN\r
90EFIAPI\r
91DebugPortReadBuffer (\r
c1e126b1
MK
92 IN DEBUG_PORT_HANDLE Handle,\r
93 IN UINT8 *Buffer,\r
94 IN UINTN NumberOfBytes,\r
95 IN UINTN Timeout\r
18b144ea 96 )\r
97{\r
c1e126b1 98 if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {\r
08021523 99 return 0;\r
18b144ea 100 }\r
101\r
08021523 102 return SerialPortRead (Buffer, 1);\r
18b144ea 103}\r
104\r
105/**\r
106 Write data from buffer to debug device.\r
107\r
108 Writes NumberOfBytes data bytes from Buffer to the debug device.\r
109 The number of bytes actually written to the debug device is returned.\r
110 If the return value is less than NumberOfBytes, then the write operation failed.\r
111 If NumberOfBytes is zero, then return 0.\r
112\r
113 @param Handle Debug port handle.\r
114 @param Buffer Pointer to the data buffer to be written.\r
115 @param NumberOfBytes Number of bytes to written to the debug device.\r
116\r
117 @retval 0 NumberOfBytes is 0.\r
118 @retval >0 The number of bytes written to the debug device.\r
119 If this value is less than NumberOfBytes, then the read operation failed.\r
120\r
121**/\r
122UINTN\r
123EFIAPI\r
124DebugPortWriteBuffer (\r
c1e126b1
MK
125 IN DEBUG_PORT_HANDLE Handle,\r
126 IN UINT8 *Buffer,\r
127 IN UINTN NumberOfBytes\r
18b144ea 128 )\r
129{\r
130 return SerialPortWrite (Buffer, NumberOfBytes);\r
131}\r
132\r
133/**\r
134 Polls a debug device to see if there is any data waiting to be read.\r
135\r
136 Polls a debug device to see if there is any data waiting to be read.\r
137 If there is data waiting to be read from the debug device, then TRUE is returned.\r
138 If there is no data waiting to be read from the debug device, then FALSE is returned.\r
139\r
140 @param Handle Debug port handle.\r
141\r
142 @retval TRUE Data is waiting to be read from the debug device.\r
143 @retval FALSE There is no data waiting to be read from the serial device.\r
144\r
145**/\r
146BOOLEAN\r
147EFIAPI\r
148DebugPortPollBuffer (\r
c1e126b1 149 IN DEBUG_PORT_HANDLE Handle\r
18b144ea 150 )\r
151{\r
152 return SerialPortPoll ();\r
153}\r