]>
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>
19 Programmed hardware of Serial port.
21 @return Always return EFI_UNSUPPORTED.
26 SerialPortInitialize (
30 if (SemihostConnectionSupported ()) {
31 return RETURN_SUCCESS
;
33 return RETURN_UNSUPPORTED
;
38 Write data to serial device.
40 @param Buffer Point of data buffer which need to be writed.
41 @param NumberOfBytes Number of output bytes which are cached in Buffer.
43 @retval 0 Write data failed.
44 @retval !0 Actual number of bytes writed to serial device.
48 #define PRINT_BUFFER_SIZE 512
49 #define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)
55 IN UINTN NumberOfBytes
58 UINT8 PrintBuffer
[PRINT_BUFFER_SIZE
];
60 UINTN DestinationIndex
;
61 UINT8 CurrentCharacter
;
66 while (SourceIndex
< NumberOfBytes
)
68 CurrentCharacter
= Buffer
[SourceIndex
++];
70 switch (CurrentCharacter
)
76 PrintBuffer
[DestinationIndex
++] = ' ';
80 PrintBuffer
[DestinationIndex
++] = CurrentCharacter
;
84 if (DestinationIndex
> PRINT_BUFFER_THRESHOLD
)
86 PrintBuffer
[DestinationIndex
] = '\0';
87 SemihostWriteString ((CHAR8
*) PrintBuffer
);
93 if (DestinationIndex
> 0)
95 PrintBuffer
[DestinationIndex
] = '\0';
96 SemihostWriteString ((CHAR8
*) PrintBuffer
);
104 Read data from serial device and save the datas in buffer.
106 @param Buffer Point of data buffer which need to be writed.
107 @param NumberOfBytes Number of output bytes which are cached in Buffer.
109 @retval 0 Read data failed.
110 @retval !0 Actual number of bytes read from serial device.
117 IN UINTN NumberOfBytes
120 *Buffer
= SemihostReadCharacter ();
127 Check to see if any data is available to be read from the debug device.
129 @retval TRUE At least one byte of data is available to be read
130 @retval FALSE No data is available to be read
139 // Since SemiHosting read character is blocking always say we have a char ready?
140 return SemihostConnectionSupported ();