ReactOS 0.4.16-dev-2491-g3dc6630
rs232.c
Go to the documentation of this file.
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/* INCLUDES *******************************************************************/
25
26#include <freeldr.h>
27
28#if DBG
29
30#include <cportlib/cportlib.h>
31#include <cportlib/uartinfo.h>
32
33/* STATIC VARIABLES ***********************************************************/
34
35/* The COM port must only be initialized once! */
36static PUCHAR Rs232ComPort = NULL;
37static CPPORT Rs232ComPortInfo;
38
39/* FUNCTIONS ******************************************************************/
40
43 _In_ PUCHAR PortAddress,
44 _In_ ULONG BaudRate)
45{
47
48 /* Check whether it's the first time we initialize a COM port.
49 * If not, check whether the specified one was already initialized. */
50 if (Rs232ComPort && (Rs232ComPort == PortAddress))
51 return TRUE;
52
53 if (BaudRate == 0)
54 BaudRate = DEFAULT_BAUD_RATE;
55
56 if (!PortAddress)
57 {
58 /*
59 * Enumerate COM ports from the last to the first one, and stop
60 * when we find a valid port. If we reach the first list element
61 * (the undefined COM port), no valid port was found.
62 */
63 ULONG ComPort;
64 for (ComPort = MAX_COM_PORTS; ComPort > 0; ComPort--)
65 {
66 PortAddress = UlongToPtr(BaseArray[ComPort]);
67 if (CpDoesPortExist(PortAddress))
68 break;
69 }
70 if (ComPort == 0 || PortAddress == NULL)
71 return FALSE;
72 }
73 else
74 {
75 if (!CpDoesPortExist(PortAddress))
76 return FALSE;
77 }
78
79 Status = CpInitialize(&Rs232ComPortInfo, PortAddress, BaudRate);
80 if (!NT_SUCCESS(Status))
81 return FALSE;
82
83 Rs232ComPort = Rs232ComPortInfo.Address;
84 return TRUE;
85}
86
87BOOLEAN Rs232PortGetByte(PUCHAR ByteReceived)
88{
89 if (!Rs232ComPort) return FALSE;
90 return (CpGetByte(&Rs232ComPortInfo, ByteReceived, TRUE, FALSE) == CP_GET_SUCCESS);
91}
92
93/*
94BOOLEAN Rs232PortPollByte(PUCHAR ByteReceived)
95{
96 if (!Rs232ComPort) return FALSE;
97 return (CpGetByte(&Rs232ComPortInfo, ByteReceived, FALSE, FALSE) == CP_GET_SUCCESS);
98}
99*/
100
101VOID Rs232PortPutByte(UCHAR ByteToSend)
102{
103 if (!Rs232ComPort) return;
104 CpPutByte(&Rs232ComPortInfo, ByteToSend);
105}
106
107#endif /* DBG */
108
110{
111#if DBG
112 return (Rs232ComPort && (Rs232ComPortInfo.Address == Base));
113#else
114 return FALSE;
115#endif
116}
117
118#endif /* !_M_ARM */
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN Rs232PortInitialize(_In_ PUCHAR PortAddress, _In_ ULONG BaudRate)
Definition: debug.c:15
VOID Rs232PortPutByte(UCHAR ByteToSend)
Definition: debug.c:23
USHORT NTAPI CpGetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte, _In_ BOOLEAN Wait, _In_ BOOLEAN Poll)
Definition: cport.c:82
#define CP_GET_SUCCESS
Definition: cportlib.h:17
VOID NTAPI CpPutByte(_Inout_ PCPPORT Port, _In_ UCHAR Byte)
Definition: cport.c:93
NTSTATUS NTAPI CpInitialize(_Inout_ PCPPORT Port, _In_ PUCHAR Address, _In_ ULONG BaudRate)
Definition: cport.c:59
BOOLEAN NTAPI CpDoesPortExist(_In_ PUCHAR Address)
Definition: cport.c:33
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define UlongToPtr(u)
Definition: config.h:106
BOOLEAN Rs232PortInUse(PUCHAR Base)
Definition: rs232.c:109
Status
Definition: gdiplustypes.h:25
#define MAX_COM_PORTS
Definition: machpc.c:29
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2486
#define _In_
Definition: no_sal2.h:158
PUCHAR Address
Definition: cportlib.h:28
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define DEFAULT_BAUD_RATE
Definition: uartinfo.h:24
unsigned char UCHAR
Definition: xmlstorage.h:181