]>
Commit | Line | Data |
---|---|---|
f5752cb2 | 1 | /** @file\r |
2 | Serial I/O Port library functions with no library constructor/destructor\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
16 | #include <Base.h>\r | |
17 | \r | |
18 | #include <Library/IoLib.h>\r | |
19 | #include <Library/SerialPortLib.h>\r | |
20 | \r | |
21 | //---------------------------------------------\r | |
22 | // UART Register Offsets\r | |
23 | //---------------------------------------------\r | |
24 | #define BAUD_LOW_OFFSET 0x00\r | |
25 | #define BAUD_HIGH_OFFSET 0x01\r | |
26 | #define IER_OFFSET 0x01\r | |
27 | #define LCR_SHADOW_OFFSET 0x01\r | |
28 | #define FCR_SHADOW_OFFSET 0x02\r | |
29 | #define IR_CONTROL_OFFSET 0x02\r | |
30 | #define FCR_OFFSET 0x02\r | |
31 | #define EIR_OFFSET 0x02\r | |
32 | #define BSR_OFFSET 0x03\r | |
33 | #define LCR_OFFSET 0x03\r | |
34 | #define MCR_OFFSET 0x04\r | |
35 | #define LSR_OFFSET 0x05\r | |
36 | #define MSR_OFFSET 0x06\r | |
37 | \r | |
38 | //---------------------------------------------\r | |
39 | // UART Register Bit Defines\r | |
40 | //---------------------------------------------\r | |
41 | #define LSR_TXRDY 0x20\r | |
42 | #define LSR_RXDA 0x01\r | |
43 | #define DLAB 0x01\r | |
44 | \r | |
45 | UINT16 gComBase = 0x3f8;\r | |
46 | UINTN gBps = 115200;\r | |
47 | UINT8 gData = 8;\r | |
48 | UINT8 gStop = 1;\r | |
49 | UINT8 gParity = 0;\r | |
50 | UINT8 gBreakSet = 0;\r | |
51 | /*\r | |
52 | \r | |
53 | Programmed hardware of Serial port.\r | |
54 | \r | |
55 | @return Always return EFI_UNSUPPORTED.\r | |
56 | \r | |
57 | **/\r | |
58 | RETURN_STATUS\r | |
59 | EFIAPI\r | |
60 | SerialPortInitialize (\r | |
61 | VOID\r | |
62 | )\r | |
63 | {\r | |
64 | UINTN Divisor;\r | |
65 | UINT8 OutputData;\r | |
66 | UINT8 Data;\r | |
67 | \r | |
68 | //\r | |
69 | // Map 5..8 to 0..3\r | |
70 | //\r | |
71 | Data = (UINT8) (gData - (UINT8)5);\r | |
72 | \r | |
73 | //\r | |
74 | // Calculate divisor for baud generator\r | |
75 | //\r | |
76 | Divisor = 115200 / gBps; \r | |
77 | \r | |
78 | //\r | |
79 | // Set communications format\r | |
80 | //\r | |
81 | OutputData = (UINT8)((DLAB << 7) | ((gBreakSet << 6) | ((gParity << 3) | ((gStop << 2) | Data))));\r | |
82 | IoWrite8 (gComBase + LCR_OFFSET, OutputData);\r | |
83 | \r | |
84 | //\r | |
85 | // Configure baud rate\r | |
86 | //\r | |
87 | IoWrite8 (gComBase + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8));\r | |
88 | IoWrite8 (gComBase + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff));\r | |
89 | \r | |
90 | //\r | |
91 | // Switch back to bank 0\r | |
92 | //\r | |
93 | OutputData = (UINT8)((~DLAB<<7)|((gBreakSet<<6)|((gParity<<3)|((gStop<<2)| Data))));\r | |
94 | IoWrite8 (gComBase + LCR_OFFSET, OutputData);\r | |
95 | \r | |
96 | return RETURN_SUCCESS;\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | Write data to serial device.\r | |
101 | \r | |
102 | @param Buffer Point of data buffer which need to be writed.\r | |
103 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
104 | \r | |
105 | @retval 0 Write data failed.\r | |
106 | @retval !0 Actual number of bytes writed to serial device.\r | |
107 | \r | |
108 | **/\r | |
109 | UINTN\r | |
110 | EFIAPI\r | |
111 | SerialPortWrite (\r | |
112 | IN UINT8 *Buffer,\r | |
113 | IN UINTN NumberOfBytes\r | |
114 | )\r | |
115 | {\r | |
116 | UINTN Result;\r | |
117 | UINT8 Data;\r | |
118 | \r | |
119 | if (NULL == Buffer) {\r | |
120 | return 0;\r | |
121 | }\r | |
122 | \r | |
123 | Result = NumberOfBytes;\r | |
124 | \r | |
125 | while (NumberOfBytes--) {\r | |
126 | //\r | |
127 | // Wait for the serail port to be ready.\r | |
128 | //\r | |
129 | do {\r | |
130 | Data = IoRead8 (gComBase + LSR_OFFSET);\r | |
131 | } while ((Data & LSR_TXRDY) == 0);\r | |
132 | \r | |
133 | IoWrite8 (gComBase, *Buffer++);\r | |
134 | }\r | |
135 | \r | |
136 | return Result;\r | |
137 | \r | |
138 | }\r | |
139 | \r | |
140 | \r | |
141 | /**\r | |
142 | Read data from serial device and save the datas in buffer.\r | |
143 | \r | |
144 | @param Buffer Point of data buffer which need to be writed.\r | |
145 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
146 | \r | |
147 | @retval 0 Read data failed.\r | |
148 | @retval !0 Aactual number of bytes read from serial device.\r | |
149 | \r | |
150 | **/\r | |
151 | UINTN\r | |
152 | EFIAPI\r | |
153 | SerialPortRead (\r | |
154 | OUT UINT8 *Buffer,\r | |
155 | IN UINTN NumberOfBytes\r | |
156 | )\r | |
157 | {\r | |
158 | return 0;\r | |
159 | }\r | |
160 | \r |