3 * Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
4 * Copyright (C) 2001 Eric Kohl
5 * Copyright (C) 2001 Emanuele Aliberti
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.
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.
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.
25 #include <cportlib/cportlib.h>
27 /* MACROS *******************************************************************/
31 #define DEFAULT_BAUD_RATE 19200
34 /* STATIC VARIABLES *********************************************************/
36 static ULONG BaseArray
[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
38 /* The COM port must only be initialized once! */
39 static CPPORT Rs232ComPort
;
40 static BOOLEAN PortInitialized
= FALSE
;
43 /* FUNCTIONS *********************************************************/
45 BOOLEAN
Rs232PortInitialize(IN ULONG ComPort
,
51 if (PortInitialized
== FALSE
)
55 BaudRate
= DEFAULT_BAUD_RATE
;
60 if (CpDoesPortExist(UlongToPtr(BaseArray
[2])))
62 Address
= UlongToPtr(BaseArray
[2]);
64 else if (CpDoesPortExist(UlongToPtr(BaseArray
[1])))
66 Address
= UlongToPtr(BaseArray
[1]);
73 else if (ComPort
<= 4) // 4 == MAX_COM_PORTS
75 if (CpDoesPortExist(UlongToPtr(BaseArray
[ComPort
])))
77 Address
= UlongToPtr(BaseArray
[ComPort
]);
89 Status
= CpInitialize(&Rs232ComPort
, Address
, BaudRate
);
90 if (!NT_SUCCESS(Status
)) return FALSE
;
92 PortInitialized
= TRUE
;
98 BOOLEAN
Rs232PortGetByte(PUCHAR ByteReceived
)
100 if (PortInitialized
== FALSE
)
103 return (CpGetByte(&Rs232ComPort
, ByteReceived
, TRUE
, FALSE
) == CP_GET_SUCCESS
);
107 BOOLEAN Rs232PortPollByte(PUCHAR ByteReceived)
109 if (PortInitialized == FALSE)
112 return (CpGetByte(&Rs232ComPort, ByteReceived, FALSE) == CP_GET_SUCCESS);
116 VOID
Rs232PortPutByte(UCHAR ByteToSend
)
118 if (PortInitialized
== FALSE
)
121 CpPutByte(&Rs232ComPort
, ByteToSend
);
126 BOOLEAN
Rs232PortInUse(PUCHAR Base
)
129 return ( (PortInitialized
&& (Rs232ComPort
.Address
== Base
)) ? TRUE
: FALSE
);
135 #endif /* not _M_ARM */