2 Serial I/O Port library functions with no library constructor/destructor
4 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/SemihostLib.h>
19 #include <Library/SerialPortLib.h>
24 Programmed hardware of Serial port.
26 @return Always return EFI_UNSUPPORTED.
31 SerialPortInitialize (
35 if (SemihostConnectionSupported ()) {
36 return RETURN_SUCCESS
;
38 return RETURN_UNSUPPORTED
;
43 Write data to serial device.
45 @param Buffer Point of data buffer which need to be writed.
46 @param NumberOfBytes Number of output bytes which are cached in Buffer.
48 @retval 0 Write data failed.
49 @retval !0 Actual number of bytes writed to serial device.
53 #define PRINT_BUFFER_SIZE 512
54 #define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)
60 IN UINTN NumberOfBytes
63 UINT8 PrintBuffer
[PRINT_BUFFER_SIZE
];
64 UINTN SourceIndex
= 0;
65 UINTN DestinationIndex
= 0;
66 UINT8 CurrentCharacter
;
68 while (SourceIndex
< NumberOfBytes
)
70 CurrentCharacter
= Buffer
[SourceIndex
++];
72 switch (CurrentCharacter
)
78 PrintBuffer
[DestinationIndex
++] = ' ';
82 PrintBuffer
[DestinationIndex
++] = CurrentCharacter
;
86 if (DestinationIndex
> PRINT_BUFFER_THRESHOLD
)
88 PrintBuffer
[DestinationIndex
] = '\0';
89 SemihostWriteString ((CHAR8
*) PrintBuffer
);
95 if (DestinationIndex
> 0)
97 PrintBuffer
[DestinationIndex
] = '\0';
98 SemihostWriteString ((CHAR8
*) PrintBuffer
);
106 Read data from serial device and save the datas in buffer.
108 @param Buffer Point of data buffer which need to be writed.
109 @param NumberOfBytes Number of output bytes which are cached in Buffer.
111 @retval 0 Read data failed.
112 @retval !0 Aactual number of bytes read from serial device.
119 IN UINTN NumberOfBytes
122 *Buffer
= SemihostReadCharacter ();
129 Check to see if any data is avaiable to be read from the debug device.
131 @retval TRUE At least one byte of data is avaiable to be read
132 @retval FALS No data is avaiable to be read
141 // Since SemiHosting read character is blocking always say we have a char ready?
142 return SemihostConnectionSupported ();