]>
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>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/SemihostLib.h>
13 #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 writed.
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 writed 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
];
58 UINTN SourceIndex
= 0;
59 UINTN DestinationIndex
= 0;
60 UINT8 CurrentCharacter
;
62 while (SourceIndex
< NumberOfBytes
)
64 CurrentCharacter
= Buffer
[SourceIndex
++];
66 switch (CurrentCharacter
)
72 PrintBuffer
[DestinationIndex
++] = ' ';
76 PrintBuffer
[DestinationIndex
++] = CurrentCharacter
;
80 if (DestinationIndex
> PRINT_BUFFER_THRESHOLD
)
82 PrintBuffer
[DestinationIndex
] = '\0';
83 SemihostWriteString ((CHAR8
*) PrintBuffer
);
89 if (DestinationIndex
> 0)
91 PrintBuffer
[DestinationIndex
] = '\0';
92 SemihostWriteString ((CHAR8
*) PrintBuffer
);
100 Read data from serial device and save the datas in buffer.
102 @param Buffer Point of data buffer which need to be writed.
103 @param NumberOfBytes Number of output bytes which are cached in Buffer.
105 @retval 0 Read data failed.
106 @retval !0 Aactual number of bytes read from serial device.
113 IN UINTN NumberOfBytes
116 *Buffer
= SemihostReadCharacter ();
123 Check to see if any data is avaiable to be read from the debug device.
125 @retval TRUE At least one byte of data is avaiable to be read
126 @retval FALSE No data is avaiable to be read
135 // Since SemiHosting read character is blocking always say we have a char ready?
136 return SemihostConnectionSupported ();