]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/SemiHostingSerialPortLib/SerialPortLib.c
2 Serial I/O Port library functions with no library constructor/destructor
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/DebugLib.h>
13 #include <Library/SemihostLib.h>
14 #include <Library/SerialPortLib.h>
18 Programmed hardware of Serial port.
20 @return Always return EFI_UNSUPPORTED.
25 SerialPortInitialize (
29 if (SemihostConnectionSupported ()) {
30 return RETURN_SUCCESS
;
32 return RETURN_UNSUPPORTED
;
37 Write data to serial device.
39 @param Buffer Point of data buffer which need to be written.
40 @param NumberOfBytes Number of output bytes which are cached in Buffer.
42 @retval 0 Write data failed.
43 @retval !0 Actual number of bytes written to serial device.
47 #define PRINT_BUFFER_SIZE 512
48 #define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)
54 IN UINTN NumberOfBytes
57 UINT8 PrintBuffer
[PRINT_BUFFER_SIZE
];
59 UINTN DestinationIndex
;
60 UINT8 CurrentCharacter
;
65 while (SourceIndex
< NumberOfBytes
) {
66 CurrentCharacter
= Buffer
[SourceIndex
++];
68 switch (CurrentCharacter
) {
73 PrintBuffer
[DestinationIndex
++] = ' ';
77 PrintBuffer
[DestinationIndex
++] = CurrentCharacter
;
81 if (DestinationIndex
> PRINT_BUFFER_THRESHOLD
) {
82 PrintBuffer
[DestinationIndex
] = '\0';
83 SemihostWriteString ((CHAR8
*)PrintBuffer
);
89 if (DestinationIndex
> 0) {
90 PrintBuffer
[DestinationIndex
] = '\0';
91 SemihostWriteString ((CHAR8
*)PrintBuffer
);
98 Read data from serial device and save the datas in buffer.
100 @param Buffer Point of data buffer which need to be written.
101 @param NumberOfBytes Number of output bytes which are cached in Buffer.
103 @retval 0 Read data failed.
104 @retval !0 Actual number of bytes read from serial device.
111 IN UINTN NumberOfBytes
114 *Buffer
= SemihostReadCharacter ();
119 Check to see if any data is available to be read from the debug device.
121 @retval TRUE At least one byte of data is available to be read
122 @retval FALSE No data is available to be read
131 // Since SemiHosting read character is blocking always say we have a char ready?
132 return SemihostConnectionSupported ();