reactos/lib/drivers/sound/uartmidi/midiuart.c
Amine Khaldi c424146e2c Create a branch for cmake bringup.
svn path=/branches/cmake-bringup/; revision=48236
2010-07-24 18:52:44 +00:00

93 lines
1.5 KiB
C

/*
ReactOS Sound System
MIDI UART support
Author:
Andrew Greenwood (silverblade@reactos.org)
History:
26 May 2008 - Created
Notes:
Functions documented in midiuart.h
*/
#include <ntddk.h>
#include "midiuart.h"
BOOLEAN
WaitForMidiUartStatus(
IN PUCHAR UartBasePort,
IN UCHAR StatusFlags,
IN ULONG Timeout)
{
ULONG RemainingTime = Timeout;
while ( RemainingTime -- )
{
if ( READ_MIDIUART_STATUS(UartBasePort) & StatusFlags )
{
return TRUE;
}
}
return FALSE;
}
BOOLEAN
WriteMidiUartByte(
IN PUCHAR UartBasePort,
IN UCHAR Data,
IN ULONG Timeout)
{
if ( ! WaitForMidiUartCTS(UartBasePort, Timeout) )
{
return FALSE;
}
WRITE_MIDIUART_DATA(UartBasePort, Data);
return TRUE;
}
BOOLEAN
WriteMidiUartMulti(
IN PUCHAR UartBasePort,
IN PUCHAR Data,
IN ULONG DataLength,
IN ULONG Timeout)
{
ULONG DataIndex;
for ( DataIndex = 0; DataIndex < DataLength; ++ DataIndex )
{
if ( ! WriteMidiUartByte(UartBasePort, Data[DataIndex], Timeout) )
{
/* We failed - don't try writing any more */
return FALSE;
}
}
return TRUE;
}
BOOLEAN
ReadMidiUartByte(
IN PUCHAR UartBasePort,
OUT UCHAR* Data,
IN ULONG Timeout)
{
if ( ! Data )
{
return FALSE;
}
if ( ! WaitForMidiUartDTR(UartBasePort, Timeout) )
{
return FALSE;
}
*Data = READ_MIDIUART_DATA(UartBasePort);
return TRUE;
}