9e04b8a445fc246f7c550ad897028639b0298f96
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
13 #include <ddk/ntddk.h>
17 BOOLEAN
WaitToSend(UINT BasePort
)
21 DbgPrint("WaitToSend ");
23 // Check if it's OK to send
24 for (TimeOut
= MPU401_TIMEOUT
;
25 ! MPU401_READY_TO_SEND(BasePort
) && TimeOut
> 0;
28 // If a time-out occurs, we report failure
35 DbgPrint("SUCCEEDED\n");
41 BOOLEAN
WaitToReceive(UINT BasePort
)
45 DbgPrint("WaitToSend ");
47 // Check if it's OK to receive
48 for (TimeOut
= MPU401_TIMEOUT
;
49 ! MPU401_READY_TO_RECEIVE(BasePort
) && TimeOut
> 0;
52 // If a time-out occurs, we report failure
59 DbgPrint("SUCCEEDED\n");
65 BOOLEAN
InitUARTMode(UINT BasePort
)
70 DbgPrint("InitUARTMode() called\n");
72 // Check if it's OK to send
73 if (! WaitToSend(BasePort
))
76 DbgPrint("Resetting MPU401\n");
79 MPU401_WRITE_COMMAND(BasePort
, 0xff);
81 // Check if it's OK to receive (some cards will ignore the above reset
82 // command and so will not issue an ACK, so time out is NOT an error)
83 DbgPrint("Waiting for an ACK\n");
84 if (WaitToReceive(BasePort
))
86 // Check to make sure the reset was acknowledged:
87 for (TimeOut
= MPU401_TIMEOUT
;
88 Status
= (MPU401_READ_DATA(BasePort
) & 0xfe) && TimeOut
> 0;
92 DbgPrint("Entering UART mode\n");
93 // Now we kick the MPU401 into UART ("dumb") mode
94 MPU401_WRITE_COMMAND(BasePort
, 0x3f);