]>
git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Library/SemiHostingSerialPortLib/SerialPortLib.c
2 Serial I/O Port library functions with no library constructor/destructor
5 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/DebugLib.h>
19 #include <Library/SemihostLib.h>
20 #include <Library/SerialPortLib.h>
25 Programmed hardware of Serial port.
27 @return Always return EFI_UNSUPPORTED.
32 SerialPortInitialize (
36 if (SemihostConnectionSupported ()) {
37 return RETURN_SUCCESS
;
39 return RETURN_UNSUPPORTED
;
44 Write data to serial device.
46 @param Buffer Point of data buffer which need to be writed.
47 @param NumberOfBytes Number of output bytes which are cached in Buffer.
49 @retval 0 Write data failed.
50 @retval !0 Actual number of bytes writed to serial device.
54 #define PRINT_BUFFER_SIZE 512
55 #define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)
61 IN UINTN NumberOfBytes
64 UINT8 PrintBuffer
[PRINT_BUFFER_SIZE
];
65 UINTN SourceIndex
= 0;
66 UINTN DestinationIndex
= 0;
67 UINT8 CurrentCharacter
;
69 while (SourceIndex
< NumberOfBytes
)
71 CurrentCharacter
= Buffer
[SourceIndex
++];
73 switch (CurrentCharacter
)
79 PrintBuffer
[DestinationIndex
++] = ' ';
83 PrintBuffer
[DestinationIndex
++] = CurrentCharacter
;
87 if (DestinationIndex
> PRINT_BUFFER_THRESHOLD
)
89 PrintBuffer
[DestinationIndex
] = '\0';
90 SemihostWriteString ((CHAR8
*) PrintBuffer
);
96 if (DestinationIndex
> 0)
98 PrintBuffer
[DestinationIndex
] = '\0';
99 SemihostWriteString ((CHAR8
*) PrintBuffer
);
107 Read data from serial device and save the datas in buffer.
109 @param Buffer Point of data buffer which need to be writed.
110 @param NumberOfBytes Number of output bytes which are cached in Buffer.
112 @retval 0 Read data failed.
113 @retval !0 Aactual number of bytes read from serial device.
120 IN UINTN NumberOfBytes
123 *Buffer
= SemihostReadCharacter ();
130 Check to see if any data is avaiable to be read from the debug device.
132 @retval TRUE At least one byte of data is avaiable to be read
133 @retval FALS No data is avaiable to be read
142 // Since SemiHosting read character is blocking always say we have a char ready?
143 return SemihostConnectionSupported ();