ReactOS  0.4.15-dev-321-g2d9b385
midiuart.c
Go to the documentation of this file.
1 /*
2  ReactOS Sound System
3  MIDI UART support
4 
5  Author:
6  Andrew Greenwood (silverblade@reactos.org)
7 
8  History:
9  26 May 2008 - Created
10 
11  Notes:
12  Functions documented in midiuart.h
13 */
14 
15 #include <ntddk.h>
16 #include "midiuart.h"
17 
18 BOOLEAN
20  IN PUCHAR UartBasePort,
21  IN UCHAR StatusFlags,
23 {
24  ULONG RemainingTime = Timeout;
25 
26  while ( RemainingTime -- )
27  {
28  if ( READ_MIDIUART_STATUS(UartBasePort) & StatusFlags )
29  {
30  return TRUE;
31  }
32  }
33 
34  return FALSE;
35 }
36 
37 BOOLEAN
39  IN PUCHAR UartBasePort,
40  IN UCHAR Data,
42 {
43  if ( ! WaitForMidiUartCTS(UartBasePort, Timeout) )
44  {
45  return FALSE;
46  }
47 
48  WRITE_MIDIUART_DATA(UartBasePort, Data);
49 
50  return TRUE;
51 }
52 
53 BOOLEAN
55  IN PUCHAR UartBasePort,
56  IN PUCHAR Data,
59 {
61 
62  for ( DataIndex = 0; DataIndex < DataLength; ++ DataIndex )
63  {
64  if ( ! WriteMidiUartByte(UartBasePort, Data[DataIndex], Timeout) )
65  {
66  /* We failed - don't try writing any more */
67  return FALSE;
68  }
69  }
70 
71  return TRUE;
72 }
73 
74 BOOLEAN
76  IN PUCHAR UartBasePort,
77  OUT UCHAR* Data,
79 {
80  if ( ! Data )
81  {
82  return FALSE;
83  }
84 
85  if ( ! WaitForMidiUartDTR(UartBasePort, Timeout) )
86  {
87  return FALSE;
88  }
89 
90  *Data = READ_MIDIUART_DATA(UartBasePort);
91 
92  return TRUE;
93 }
#define WaitForMidiUartCTS(UartBasePort, Timeout)
Definition: midiuart.h:53
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
#define WRITE_MIDIUART_DATA(bp, x)
Definition: midiuart.h:25
#define WaitForMidiUartDTR(UartBasePort, Timeout)
Definition: midiuart.h:57
#define READ_MIDIUART_STATUS(bp)
Definition: midiuart.h:28
unsigned char BOOLEAN
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOLEAN ReadMidiUartByte(IN PUCHAR UartBasePort, OUT UCHAR *Data, IN ULONG Timeout)
Definition: midiuart.c:75
static ULONG Timeout
Definition: ping.c:61
_Must_inspect_result_ _In_ USHORT DataIndex
Definition: hidpi.h:346
#define READ_MIDIUART_DATA(bp)
Definition: midiuart.h:26
BOOLEAN WaitForMidiUartStatus(IN PUCHAR UartBasePort, IN UCHAR StatusFlags, IN ULONG Timeout)
Definition: midiuart.c:19
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN WriteMidiUartMulti(IN PUCHAR UartBasePort, IN PUCHAR Data, IN ULONG DataLength, IN ULONG Timeout)
Definition: midiuart.c:54
BOOLEAN WriteMidiUartByte(IN PUCHAR UartBasePort, IN UCHAR Data, IN ULONG Timeout)
Definition: midiuart.c:38
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333