3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/dd/mpu401/portio.c (see also mpu401.h)
6 * PURPOSE: MPU-401 MIDI port I/O helper
7 * PROGRAMMER: Andrew Greenwood
9 * Sept 26, 2003: Created
16 BOOLEAN
WaitToSend(UINT BasePort
)
20 DbgPrint("WaitToSend ");
22 // Check if it's OK to send
23 for (TimeOut
= MPU401_TIMEOUT
;
24 ! MPU401_READY_TO_SEND(BasePort
) && TimeOut
> 0;
27 // If a time-out occurs, we report failure
34 DbgPrint("SUCCEEDED\n");
40 BOOLEAN
WaitToReceive(UINT BasePort
)
44 DbgPrint("WaitToSend ");
46 // Check if it's OK to receive
47 for (TimeOut
= MPU401_TIMEOUT
;
48 ! MPU401_READY_TO_RECEIVE(BasePort
) && TimeOut
> 0;
51 // If a time-out occurs, we report failure
58 DbgPrint("SUCCEEDED\n");
64 BOOLEAN
InitUARTMode(UINT BasePort
)
69 DbgPrint("InitUARTMode() called\n");
71 // Check if it's OK to send
72 if (! WaitToSend(BasePort
))
75 DbgPrint("Resetting MPU401\n");
78 MPU401_WRITE_COMMAND(BasePort
, 0xff);
80 // Check if it's OK to receive (some cards will ignore the above reset
81 // command and so will not issue an ACK, so time out is NOT an error)
82 DbgPrint("Waiting for an ACK\n");
83 if (WaitToReceive(BasePort
))
85 // Check to make sure the reset was acknowledged:
86 for (TimeOut
= MPU401_TIMEOUT
;
87 (Status
= (MPU401_READ_DATA(BasePort
) & 0xfe) && TimeOut
> 0);
91 DbgPrint("Entering UART mode\n");
92 // Now we kick the MPU401 into UART ("dumb") mode
93 MPU401_WRITE_COMMAND(BasePort
, 0x3f);