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