Split custom ReactOS-only non-standard extensions from NTDDSND.H
[reactos.git] / reactos / lib / drivers / sound / uartmidi / midiuart.c
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
19 WaitForMidiUartStatus(
20 IN PUCHAR UartBasePort,
21 IN UCHAR StatusFlags,
22 IN ULONG Timeout)
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
38 WriteMidiUartByte(
39 IN PUCHAR UartBasePort,
40 IN UCHAR Data,
41 IN ULONG Timeout)
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
54 WriteMidiUartMulti(
55 IN PUCHAR UartBasePort,
56 IN PUCHAR Data,
57 IN ULONG DataLength,
58 IN ULONG Timeout)
59 {
60 ULONG DataIndex;
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
75 ReadMidiUartByte(
76 IN PUCHAR UartBasePort,
77 OUT UCHAR* Data,
78 IN ULONG Timeout)
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 }