ReactOS
0.4.16-dev-197-g92996da
portio.c
Go to the documentation of this file.
1
/*
2
*
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
8
* UPDATE HISTORY:
9
* Sept 26, 2003: Created
10
*/
11
12
#include <ntddk.h>
13
#include "
mpu401.h
"
14
15
16
BOOLEAN
WaitToSend
(
ULONG
BasePort)
17
{
18
int
TimeOut;
19
20
DbgPrint
(
"WaitToSend "
);
21
22
// Check if it's OK to send
23
for
(TimeOut =
MPU401_TIMEOUT
;
24
!
MPU401_READY_TO_SEND
(BasePort) && TimeOut > 0;
25
TimeOut --);
26
27
// If a time-out occurs, we report failure
28
if
(! TimeOut)
29
{
30
DbgPrint
(
"FAILED\n"
);
31
return
FALSE
;
32
}
33
34
DbgPrint
(
"SUCCEEDED\n"
);
35
36
return
TRUE
;
37
}
38
39
40
BOOLEAN
WaitToReceive
(
ULONG
BasePort)
41
{
42
int
TimeOut;
43
44
DbgPrint
(
"WaitToSend "
);
45
46
// Check if it's OK to receive
47
for
(TimeOut =
MPU401_TIMEOUT
;
48
!
MPU401_READY_TO_RECEIVE
(BasePort) && TimeOut > 0;
49
TimeOut --);
50
51
// If a time-out occurs, we report failure
52
if
(! TimeOut)
53
{
54
DbgPrint
(
"FAILED\n"
);
55
return
FALSE
;
56
}
57
58
DbgPrint
(
"SUCCEEDED\n"
);
59
60
return
TRUE
;
61
}
62
63
64
BOOLEAN
InitUARTMode
(
ULONG
BasePort)
65
{
66
ULONG
TimeOut;
67
UCHAR
Status
= 0;
68
69
DbgPrint
(
"InitUARTMode() called\n"
);
70
71
// Check if it's OK to send
72
if
(!
WaitToSend
(BasePort))
73
return
FALSE
;
74
75
DbgPrint
(
"Resetting MPU401\n"
);
76
77
// Send an MPU reset:
78
MPU401_WRITE_COMMAND
(BasePort, 0xff);
79
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))
84
{
85
// Check to make sure the reset was acknowledged:
86
for
(TimeOut =
MPU401_TIMEOUT
;
87
(
Status
= (
MPU401_READ_DATA
(BasePort) & 0xfe) && TimeOut > 0);
88
TimeOut --);
89
}
90
91
DbgPrint
(
"Entering UART mode\n"
);
92
// Now we kick the MPU401 into UART ("dumb") mode
93
MPU401_WRITE_COMMAND
(BasePort, 0x3f);
94
95
return
TRUE
;
96
}
BOOLEAN
unsigned char BOOLEAN
Definition:
ProcessorBind.h:185
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
WaitToReceive
BOOLEAN WaitToReceive(ULONG BasePort)
Definition:
portio.c:40
WaitToSend
BOOLEAN WaitToSend(ULONG BasePort)
Definition:
portio.c:16
InitUARTMode
BOOLEAN InitUARTMode(ULONG BasePort)
Definition:
portio.c:64
Status
Status
Definition:
gdiplustypes.h:25
DbgPrint
#define DbgPrint
Definition:
hal.h:12
mpu401.h
MPU401_WRITE_COMMAND
#define MPU401_WRITE_COMMAND(bp, x)
Definition:
mpu401.h:55
MPU401_TIMEOUT
#define MPU401_TIMEOUT
Definition:
mpu401.h:31
MPU401_READY_TO_SEND
#define MPU401_READY_TO_SEND(bp)
Definition:
mpu401.h:61
MPU401_READY_TO_RECEIVE
#define MPU401_READY_TO_RECEIVE(bp)
Definition:
mpu401.h:64
MPU401_READ_DATA
#define MPU401_READ_DATA(bp)
Definition:
mpu401.h:54
ULONG
uint32_t ULONG
Definition:
typedefs.h:59
UCHAR
unsigned char UCHAR
Definition:
xmlstorage.h:181
drivers
multimedia
audio
mpu401_nt4
portio.c
Generated on Wed Oct 30 2024 06:05:56 for ReactOS by
1.9.6