1 /** @file 2 Debug Communication Library definitions. 3 4 Copyright (c) 2010 - 2014, 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. 9 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. 12 13 **/ 14 15 #ifndef __DEBUG_COMMUNICATION_LIB_H__ 16 #define __DEBUG_COMMUNICATION_LIB_H__ 17 18 typedef VOID * DEBUG_PORT_HANDLE; 19 20 /** 21 Caller provided function to be invoked at the end of DebugPortInitialize(). 22 23 Refer to the descrption for DebugPortInitialize() for more details. 24 25 @param[in] Context The first input argument of DebugPortInitialize(). 26 @param[in] DebugPortHandle Debug port handle created by Debug Communication Libary. 27 28 **/ 29 typedef 30 VOID 31 (EFIAPI * DEBUG_PORT_CONTINUE)( 32 IN VOID *Context, 33 IN DEBUG_PORT_HANDLE DebugPortHandle 34 ); 35 36 /** 37 Initialize the debug port. 38 39 This function will initialize debug port to get it ready for data transmition. If 40 certain Debug Communication Library instance has to save some private data in the 41 stack, this function must work on the mode that doesn't return to the caller, then 42 the caller needs to wrap up all rest of logic after DebugPortInitialize() into one 43 function and pass it into DebugPortInitialize(). DebugPortInitialize() is 44 responsible to invoke the passing-in funciton at the end of DebugPortInitialize(). 45 46 If the paramter Function is not NULL, Debug Communication Libary instance will 47 invoke it by passing in the Context to be the first parameter. Debug Communication 48 Library instance could create one debug port handle to be the second parameter 49 passing into the Function. Debug Communication Library instance also could pass 50 NULL to be the second parameter if it doesn't create the debug port handle. 51 52 If the parameter Function is NULL, and Context is not NULL. At this time, Context 53 is the debug port handle created by the previous Debug Communication Library 54 instance. 55 a) If the instance can understand and continue use the private data of the previous 56 instance, it could return the same handle as passed in (as Context parameter). 57 b) If the instance does not understand, or does not want to continue use the 58 private data of the previous instance, it could ignore the input Context parameter 59 and create the new handle to be returned. 60 61 If Function() is NULL and Context is NULL, Debug Communication Library could create a 62 new handle and return it. NULL is also a valid handle to be returned. 63 64 @param[in] Context Context needed by callback function; it was optional. 65 @param[in] Function Continue function called by Debug Communication library; 66 it was optional. 67 68 @return The debug port handle created by Debug Communication Library if Function 69 is not NULL. 70 71 **/ 72 DEBUG_PORT_HANDLE 73 EFIAPI 74 DebugPortInitialize ( 75 IN VOID *Context, 76 IN DEBUG_PORT_CONTINUE Function 77 ); 78 79 80 /** 81 Read data from debug device and save the datas in buffer. 82 83 Reads NumberOfBytes data bytes from a debug device into the buffer 84 specified by Buffer. The number of bytes actually read is returned. 85 If the return value is less than NumberOfBytes, then the rest operation failed. 86 If NumberOfBytes is zero, then return 0. 87 88 @param Handle Debug port handle. 89 @param Buffer Pointer to the data buffer to store the data read from the debug device. 90 @param NumberOfBytes Number of bytes which will be read. 91 @param Timeout Timeout value for reading from debug device. It unit is Microsecond. 92 93 @retval 0 Read data failed, no data is to be read. 94 @retval >0 Actual number of bytes read from debug device. 95 96 **/ 97 UINTN 98 EFIAPI 99 DebugPortReadBuffer ( 100 IN DEBUG_PORT_HANDLE Handle, 101 IN UINT8 *Buffer, 102 IN UINTN NumberOfBytes, 103 IN UINTN Timeout 104 ); 105 106 107 /** 108 Write data from buffer to debug device. 109 110 Writes NumberOfBytes data bytes from Buffer to the debug device. 111 The number of bytes actually written to the debug device is returned. 112 If the return value is less than NumberOfBytes, then the write operation failed. 113 If NumberOfBytes is zero, then return 0. 114 115 @param Handle Debug port handle. 116 @param Buffer Pointer to the data buffer to be written. 117 @param NumberOfBytes Number of bytes to written to the debug device. 118 119 @retval 0 NumberOfBytes is 0. 120 @retval >0 The number of bytes written to the debug device. 121 If this value is less than NumberOfBytes, then the read operation failed. 122 123 **/ 124 UINTN 125 EFIAPI 126 DebugPortWriteBuffer ( 127 IN DEBUG_PORT_HANDLE Handle, 128 IN UINT8 *Buffer, 129 IN UINTN NumberOfBytes 130 ); 131 132 /** 133 Polls a debug device to see if there is any data waiting to be read. 134 135 Polls a debug device to see if there is any data waiting to be read. 136 If there is data waiting to be read from the debug device, then TRUE is returned. 137 If there is no data waiting to be read from the debug device, then FALSE is returned. 138 139 @param Handle Debug port handle. 140 141 @retval TRUE Data is waiting to be read from the debug device. 142 @retval FALSE There is no data waiting to be read from the serial device. 143 144 **/ 145 BOOLEAN 146 EFIAPI 147 DebugPortPollBuffer ( 148 IN DEBUG_PORT_HANDLE Handle 149 ); 150 151 #endif 152 153