]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
ArmPlatformPkg: Minor code changes (comments, misspellings, coding stylei, line endings)
[mirror_edk2.git] / ArmPlatformPkg / ArmRealViewEbPkg / Library / GdbSerialLib / GdbSerialLib.c
CommitLineData
a6caee65 1/** @file\r
2 Basic serial IO abstaction for GDB\r
3\r
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
5 \r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Uefi.h>\r
17#include <Library/GdbSerialLib.h>\r
18#include <Library/PcdLib.h>\r
19#include <Library/IoLib.h>\r
20#include <Drivers/PL011Uart.h>\r
21\r
22RETURN_STATUS\r
23EFIAPI\r
24GdbSerialLibConstructor (\r
25 VOID\r
26 )\r
27{\r
28 return GdbSerialInit (115200, 0, 8, 1);\r
29}\r
30\r
31RETURN_STATUS\r
32EFIAPI\r
33GdbSerialInit (\r
34 IN UINT64 BaudRate, \r
35 IN UINT8 Parity, \r
36 IN UINT8 DataBits, \r
37 IN UINT8 StopBits \r
38 )\r
39{\r
40 if ((Parity != 0) || (DataBits != 8) || (StopBits != 1)) {\r
41 return RETURN_UNSUPPORTED;\r
42 }\r
43\r
44 if (BaudRate != 115200) {\r
45 // Could add support for different Baud rates....\r
46 return RETURN_UNSUPPORTED;\r
47 }\r
48 \r
1d5d0ae9 49 UINT32 Base = PcdGet32 (PcdGdbUartBase);\r
50 \r
51 // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ\r
52 MmioWrite32 (Base + UARTIBRD, UART_115200_IDIV);\r
53 MmioWrite32 (Base + UARTFBRD, UART_115200_FDIV);\r
54\r
55 // no parity, 1 stop, no fifo, 8 data bits\r
56 MmioWrite32 (Base + UARTLCR_H, 0x60);\r
57\r
58 // clear any pending errors\r
59 MmioWrite32 (Base + UARTECR, 0);\r
60\r
61 // enable tx, rx, and uart overall\r
62 MmioWrite32 (Base + UARTCR, 0x301);\r
63\r
64 return RETURN_SUCCESS;\r
a6caee65 65}\r
66\r
67BOOLEAN\r
68EFIAPI\r
69GdbIsCharAvailable (\r
70 VOID\r
71 ) \r
72{\r
1d5d0ae9 73 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
74\r
75 if ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0) {\r
76 return TRUE;\r
77 } else {\r
78 return FALSE;\r
79 }\r
a6caee65 80}\r
81\r
82CHAR8\r
83EFIAPI\r
84GdbGetChar (\r
85 VOID\r
86 )\r
87{\r
1d5d0ae9 88 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
89 UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r
90 \r
91 while ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0);\r
92 return MmioRead8 (DR);\r
a6caee65 93}\r
94\r
95VOID\r
96EFIAPI\r
97GdbPutChar (\r
98 IN CHAR8 Char\r
99 )\r
100{\r
1d5d0ae9 101 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
102 UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r
103\r
104 while ((MmioRead32 (FR) & UART_TX_EMPTY_FLAG_MASK) != 0);\r
105 MmioWrite8 (DR, Char);\r
a6caee65 106 return;\r
107}\r
108\r
109VOID\r
110GdbPutString (\r
111 IN CHAR8 *String\r
112 )\r
113{\r
114 while (*String != '\0') {\r
115 GdbPutChar (*String);\r
116 String++;\r
117 }\r
118}\r