TianoCore EDK2 master
Loading...
Searching...
No Matches
SerialPortLib.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <Library/DebugLib.h>
13#include <Library/SemihostLib.h>
15
16/*
17
18 Programmed hardware of Serial port.
19
20 @return Always return EFI_UNSUPPORTED.
21
22**/
23RETURN_STATUS
24EFIAPI
26 VOID
27 )
28{
29 if (SemihostConnectionSupported ()) {
30 return RETURN_SUCCESS;
31 } else {
32 return RETURN_UNSUPPORTED;
33 }
34}
35
47#define PRINT_BUFFER_SIZE 512
48#define PRINT_BUFFER_THRESHOLD (PRINT_BUFFER_SIZE - 4)
49
51EFIAPI
53 IN UINT8 *Buffer,
54 IN UINTN NumberOfBytes
55 )
56{
57 UINT8 PrintBuffer[PRINT_BUFFER_SIZE];
58 UINTN SourceIndex;
59 UINTN DestinationIndex;
60 UINT8 CurrentCharacter;
61
62 SourceIndex = 0;
63 DestinationIndex = 0;
64
65 while (SourceIndex < NumberOfBytes) {
66 CurrentCharacter = Buffer[SourceIndex++];
67
68 switch (CurrentCharacter) {
69 case '\r':
70 continue;
71
72 case '\n':
73 PrintBuffer[DestinationIndex++] = ' ';
74 // fall through
75
76 default:
77 PrintBuffer[DestinationIndex++] = CurrentCharacter;
78 break;
79 }
80
81 if (DestinationIndex > PRINT_BUFFER_THRESHOLD) {
82 PrintBuffer[DestinationIndex] = '\0';
83 SemihostWriteString ((CHAR8 *)PrintBuffer);
84
85 DestinationIndex = 0;
86 }
87 }
88
89 if (DestinationIndex > 0) {
90 PrintBuffer[DestinationIndex] = '\0';
91 SemihostWriteString ((CHAR8 *)PrintBuffer);
92 }
93
94 return NumberOfBytes;
95}
96
107UINTN
108EFIAPI
110 OUT UINT8 *Buffer,
111 IN UINTN NumberOfBytes
112 )
113{
114 *Buffer = SemihostReadCharacter ();
115 return 1;
116}
117
125BOOLEAN
126EFIAPI
128 VOID
129 )
130{
131 // Since SemiHosting read character is blocking always say we have a char ready?
132 return SemihostConnectionSupported ();
133}
UINT64 UINTN
BOOLEAN EFIAPI SerialPortPoll(VOID)
#define PRINT_BUFFER_SIZE
Definition: SerialPortLib.c:47
UINTN EFIAPI SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
Definition: SerialPortLib.c:25
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: SerialPortLib.c:52
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284