ReactOS 0.4.15-dev-7928-g68a8619
dsp_io.c
Go to the documentation of this file.
1/*
2 ReactOS Sound System
3 Sound Blaster DSP support
4 General I/O
5
6 Author:
7 Andrew Greenwood (silverblade@reactos.org)
8
9 History:
10 2 July 2008 - Created (split from sbdsp.c)
11
12 Notes:
13 Functions documented in sbdsp.h
14*/
15
16#include "precomp.h"
17
20 IN PUCHAR BasePort,
22{
23 ULONG Expiry;
24 BOOLEAN DataAvailable = FALSE;
25
26 /* Should be called from DriverEntry with this IRQL */
28
29 WRITE_SB_DSP_RESET(BasePort, 0x01);
30 SleepMs(50); /* Should be enough */
31 WRITE_SB_DSP_RESET(BasePort, 0x00);
32
33 Expiry = QuerySystemTimeMs() + Timeout;
34
35 /* Wait for data to be available */
36 while ( (QuerySystemTimeMs() < Expiry) || ( Timeout == 0) )
37 {
38 if ( SB_DSP_DATA_AVAILABLE(BasePort) )
39 {
40 DataAvailable = TRUE;
41 break;
42 }
43 }
44
45 if ( ! DataAvailable )
46 {
47 return STATUS_TIMEOUT;
48 }
49
50 /* Data is available - wait for the "DSP ready" code */
51 while ( (QuerySystemTimeMs() < Expiry) || ( Timeout == 0) )
52 {
53 if ( READ_SB_DSP_DATA(BasePort) == SB_DSP_READY )
54 {
55 return STATUS_SUCCESS;
56 }
57 }
58
59 return STATUS_TIMEOUT;
60}
61
64 IN PUCHAR BasePort,
66{
67 ULONG Expiry = QuerySystemTimeMs() + Timeout;
68
69 while ( (QuerySystemTimeMs() < Expiry) || (Timeout == 0) )
70 {
71 if ( SB_DSP_CLEAR_TO_SEND(BasePort) )
72 {
73 return STATUS_SUCCESS;
74 }
75 }
76
77 return STATUS_TIMEOUT;
78}
79
82 IN PUCHAR BasePort,
84{
85 ULONG Expiry = QuerySystemTimeMs() + Timeout;
86
87 while ( (QuerySystemTimeMs() < Expiry) || (Timeout == 0) )
88 {
89 if ( SB_DSP_DATA_AVAILABLE(BasePort) )
90 {
91 return STATUS_SUCCESS;
92 }
93 }
94
95 return STATUS_TIMEOUT;
96}
97
100 IN PUCHAR BasePort,
101 IN UCHAR DataByte,
103{
105
106 Status = SbDspWaitToWrite(BasePort, Timeout);
107
108 if ( Status != STATUS_SUCCESS )
109 {
110 return Status;
111 }
112
113 DbgPrint("SBDSP - Writing %02x\n", DataByte);
114 WRITE_SB_DSP_DATA(BasePort, DataByte);
115
116 return STATUS_SUCCESS;
117}
118
121 IN PUCHAR BasePort,
122 OUT PUCHAR DataByte,
124{
126
127 if ( ! DataByte )
128 {
130 }
131
132 Status = SbDspWaitToRead(BasePort, Timeout);
133
134 if ( Status != STATUS_SUCCESS )
135 {
136 return Status;
137 }
138
139 *DataByte = READ_SB_DSP_DATA(BasePort);
140 DbgPrint("SBDSP - Read %02x\n", *DataByte);
141
142 return STATUS_SUCCESS;
143}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS SbDspReset(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:19
NTSTATUS SbDspWaitToRead(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:81
NTSTATUS SbDspWaitToWrite(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:63
NTSTATUS SbDspWrite(IN PUCHAR BasePort, IN UCHAR DataByte, IN ULONG Timeout)
Definition: dsp_io.c:99
NTSTATUS SbDspRead(IN PUCHAR BasePort, OUT PUCHAR DataByte, IN ULONG Timeout)
Definition: dsp_io.c:120
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
static ULONG Timeout
Definition: ping.c:61
#define SB_DSP_READY
Definition: sndblst.h:19
#define WRITE_SB_DSP_DATA(bp, x)
Definition: sbdsp.h:54
#define SB_DSP_CLEAR_TO_SEND(bp)
Definition: sbdsp.h:58
#define WRITE_SB_DSP_RESET(bp, x)
Definition: sbdsp.h:47
#define SB_DSP_DATA_AVAILABLE(bp)
Definition: sbdsp.h:62
#define READ_SB_DSP_DATA(bp)
Definition: sbdsp.h:53
VOID SleepMs(ULONG Milliseconds)
Definition: time.c:28
ULONG QuerySystemTimeMs()
Definition: time.c:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
unsigned char UCHAR
Definition: xmlstorage.h:181