Code formatting only
[reactos.git] / reactos / boot / freeldr / freeldr / comm / rs232.c
1 /*
2 * FreeLoader
3 * Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
4 * Copyright (C) 2001 Eric Kohl
5 * Copyright (C) 2001 Emanuele Aliberti
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #ifndef _M_ARM
23
24 #include <freeldr.h>
25 #include <cportlib/cportlib.h>
26
27 /* MACROS *******************************************************************/
28
29 #if DBG
30
31 #define DEFAULT_BAUD_RATE 19200
32
33
34 /* STATIC VARIABLES *********************************************************/
35
36 static ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
37
38 /* The COM port must only be initialized once! */
39 static CPPORT Rs232ComPort;
40 static BOOLEAN PortInitialized = FALSE;
41
42
43 /* FUNCTIONS *********************************************************/
44
45 BOOLEAN Rs232PortInitialize(IN ULONG ComPort,
46 IN ULONG BaudRate)
47 {
48 NTSTATUS Status;
49 PUCHAR Address;
50
51 if (PortInitialized == FALSE)
52 {
53 if (BaudRate == 0)
54 {
55 BaudRate = DEFAULT_BAUD_RATE;
56 }
57
58 if (ComPort == 0)
59 {
60 if (CpDoesPortExist(UlongToPtr(BaseArray[2])))
61 {
62 Address = UlongToPtr(BaseArray[2]);
63 }
64 else if (CpDoesPortExist(UlongToPtr(BaseArray[1])))
65 {
66 Address = UlongToPtr(BaseArray[1]);
67 }
68 else
69 {
70 return FALSE;
71 }
72 }
73 else if (ComPort <= 4) // 4 == MAX_COM_PORTS
74 {
75 if (CpDoesPortExist(UlongToPtr(BaseArray[ComPort])))
76 {
77 Address = UlongToPtr(BaseArray[ComPort]);
78 }
79 else
80 {
81 return FALSE;
82 }
83 }
84 else
85 {
86 return FALSE;
87 }
88
89 Status = CpInitialize(&Rs232ComPort, Address, BaudRate);
90 if (!NT_SUCCESS(Status)) return FALSE;
91
92 PortInitialized = TRUE;
93 }
94
95 return TRUE;
96 }
97
98 BOOLEAN Rs232PortGetByte(PUCHAR ByteReceived)
99 {
100 if (PortInitialized == FALSE)
101 return FALSE;
102
103 return (CpGetByte(&Rs232ComPort, ByteReceived, TRUE, FALSE) == CP_GET_SUCCESS);
104 }
105
106 /*
107 BOOLEAN Rs232PortPollByte(PUCHAR ByteReceived)
108 {
109 if (PortInitialized == FALSE)
110 return FALSE;
111
112 return (CpGetByte(&Rs232ComPort, ByteReceived, FALSE) == CP_GET_SUCCESS);
113 }
114 */
115
116 VOID Rs232PortPutByte(UCHAR ByteToSend)
117 {
118 if (PortInitialized == FALSE)
119 return;
120
121 CpPutByte(&Rs232ComPort, ByteToSend);
122 }
123
124 #endif /* DBG */
125
126 BOOLEAN Rs232PortInUse(PUCHAR Base)
127 {
128 #if DBG
129 return ( (PortInitialized && (Rs232ComPort.Address == Base)) ? TRUE : FALSE );
130 #else
131 return FALSE;
132 #endif
133 }
134
135 #endif /* not _M_ARM */