ai_sounds.c
8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <rcp.h>
#include "diag.h"
#include <dbg_comm.h>
extern char Name[];
extern int NameValid;
int
ai_sounds (TEST_REF *test_ref)
{
int NumFailures = 0;
int i;
int MoreData, FirstTime, AudioFull;
int AudioReadPtr;
int CurrentLength,AudioBusy;
int *pwbuf;
int *prbuf;
unsigned int numbytes;
unsigned int rdbuf;
#define SampleSize 4
#define AI_STATUS_AUDIO_BUSY 0x40000000
#define AI_STATUS_DMA_BUSY 0x08000000
/* RCP1 has limit of 32k-1 bytes Length specification */
/* or 8k-1 32 bit samples */
/* Length is specified in bytes with 64 bit resoultion */
/* RCP2 has increased limit */
/* Need to check version and adjust */
#define MaxBufferLength (200000L)
unsigned char wbuf[MaxBufferLength*SampleSize];
unsigned char rbuf[MaxBufferLength*SampleSize];
int BufferLength;
FILE *aud_fp;
FILE *fopen();
unsigned char aud_file[80];
unsigned char fullpath[256];
/* determine audio sample file name and open it */
/* note this is local to current working directory */
if (NameValid) {
strcat (aud_file,&(Name[0]));
strcat (aud_file,".bin");
errlog(DEBUG,"Command line selected sample file is %s",aud_file);
NameValid = 0;
}
else { /* default sample file */
errlog (DEBUG,"Reading Samples from default file elec_piano.bin");
strcpy (aud_file,"elec_piano.bin");
}
if (! dgFindFile(fullpath, "/PR/diags/ai/data", aud_file)){
if (! dgFindFile(fullpath, "/usr/diags/data",aud_file)){
errlog(ERR_SEVERE,"Failed to find file %s",aud_file);
}
}
if((aud_fp = fopen(fullpath,"r")) == NULL){
errlog(ERR_SEVERE,"Unable to open input file %s",aud_file);
return (1);
}
/* Initialize Rdram */
errlog(DEBUG,"Initializing Rdram");
/* Init VI to get video clock signal into AI */
/* if (dgWriteWord(VI_STATUS_REG, 0) ) return (1); */
/* ready to start loading and dma */
pwbuf = (int *)wbuf;
prbuf = (int *)rbuf;
MoreData = 1;
FirstTime = 1;
AudioReadPtr = dgRdramFree ;
errlog(DEBUG,"Audio Buffer will be loaded at address %x",AudioReadPtr);
/* Main Loop */
while (MoreData) {
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
AudioFull = (rdbuf & AI_STATUS_FIFO_FULL) ;
if (FirstTime & AudioFull) {
errlog(ERR_SEVERE,"AI Status is initially full, should be 0 on reset");
}
if ( !AudioFull) {
/* may want to read earlier */
BufferLength = fread (pwbuf, SampleSize , MaxBufferLength, aud_fp);
errlog(DEBUG,"Read 0x%x L/R Audio Samples ",BufferLength);
/* did we get the whole file read in */
/* currently disabled, only load up to MaxBufferLength */
/* so always set MoreData = 0 */
if (BufferLength == MaxBufferLength) MoreData = 0;
if (BufferLength < MaxBufferLength) MoreData = 0;
if (BufferLength == 0) MoreData = 0;
if (BufferLength != 0) {
/* load/verify the buffer to rdram */
#define MEMLOAD
#ifdef WORDLOAD
for (i = 0; i < BufferLength ; i ++) {
if (dgWriteWord ((AudioReadPtr+(i*4)),*(pwbuf+i))) return (1);
errlog(DEBUG,"address %x Data %x",(AudioReadPtr+(i*4)),*(pwbuf+i));
if (dgReadWord ((AudioReadPtr+(i*4)),&rdbuf)) return (1);
if (rdbuf != *(pwbuf+i)) {
errlog ( ERR_SEVERE,
"Rdram buffer load failed - actual = %08x, expected = %08x",
rdbuf, *(pwbuf+i));
}
}
#endif
#ifdef MEMLOAD
/* load /verify whole buffer */
numbytes = BufferLength * 4 ;
if (dgWriteMem (dgRdramFree, numbytes, ((char *)pwbuf)) ) return (1);
if (dgReadMem (dgRdramFree, numbytes, ((char *)prbuf)) ) return (1);
for (i = 0; i < BufferLength; i++){
if (*(pwbuf+i) != *(prbuf+i) ) {
errlog(ERR_SEVERE,
"Rdram load failed - index %x actual = %08x, expected = %08x",
i,*(prbuf+i), *(pwbuf+i));
}
}
#endif
/* kick off the dma */
if (FirstTime) {
FirstTime = 0;
/* Initialize audio here, to stop output until ready */
/* Program Audio for 44.1k rate
* To get ~44.1 KHz for audio (based on Rambus clock of 243.37 MHz
* and video clock of 48.67 MHz), AI dac rate = 1103 (0x44f) and
* AI bit rate = 15 (0xf)
*/
errlog(DEBUG,"Initializing Audio Frequency");
if ( dgWriteWord(AI_DACRATE_REG, 0x44f) ) return (1);
if ( dgWriteWord(AI_BITRATE_REG, 0xf) ) return (1);
if ( dgWriteWord(AI_CONTROL_REG, AI_CONTROL_DMA_ON) ) return (1);
}
errlog(DEBUG,"Starting DMA: DMA Address %x, DMA Byte Length %x",
AudioReadPtr,(BufferLength*4));
errlog(INFO,"Listen for an Audio Sample ....");
dgWait("To Hear the Audio Sample ...");
if (1) {
long int i, curLen, mySize, curPtr;
i = 0;
curLen = 4 * BufferLength;
mySize = 4 * 4096L;
curPtr = AudioReadPtr;
while (curLen > 0) {
if ( dgWriteWord(AI_DRAM_ADDR_REG, curPtr) ) return(1);
if (curLen > mySize) {
if ( dgWriteWord(AI_LEN_REG, mySize) ) return (1);
} else {
if ( dgWriteWord(AI_LEN_REG, curLen) ) return (1);
}
errlog(DEBUG,"Starting DMA @ Address %08x , len left=%d\n",
curPtr, curLen);
i++;
curLen -= mySize;
curPtr += mySize;
do {
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
AudioFull = (rdbuf & AI_STATUS_FIFO_FULL) ;
} while(AudioFull);
}
}
return(0);
/* end of rhn added */
AudioReadPtr += BufferLength*4 ;
} /* BufferLength 0 */
} /* !AudioFull */
else { /* Full */
/* spin on Audio Full */
while (AudioFull){
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
AudioFull = (rdbuf & AI_STATUS_FIFO_FULL) ;
errlog
(DEBUG,"Spinning on Full = %x Audio Busy = %x DMA Busy = %x DAC CTR = %x",
(rdbuf & AI_STATUS_FIFO_FULL), (rdbuf & AI_STATUS_AUDIO_BUSY),
(rdbuf & AI_STATUS_DMA_BUSY), (rdbuf & 0xfff7) );
}
}
} /* MoreData */
/* wait for audio output to finish */
errlog (DEBUG," Loaded Last of Audio Data to Rdram");
CurrentLength = 0x7fffffff; /* bogus number */
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
AudioBusy = rdbuf & AI_STATUS_AUDIO_BUSY;
while (AudioBusy) {
if (dgReadWord(AI_LEN_REG, &rdbuf)) return (1);
if (CurrentLength != rdbuf) {
CurrentLength = rdbuf;
errlog (DEBUG,"Current Length is %x",CurrentLength);
AudioBusy = 1;
}
else {
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
AudioBusy = rdbuf & AI_STATUS_AUDIO_BUSY;
}
}
/* should wait a while here for simulation to run the data out the dac */
/* for simulation purposes only */
/*
while (1) AudioStatus();
*/
fclose (aud_fp);
return(NumFailures);
}
int
AudioStatus ()
{
int Full, Busy , DmaBusy, DmaRequest, DmaEnable;
int Dfifo2Loaded, DataAvail, WordSelect, AbusWord2;
int DacCnt0, DacCntValue;
unsigned int rdbuf;
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
Full = ((rdbuf >> 31) & 1);
Busy = ((rdbuf >> 30) & 1);
DmaBusy = ((rdbuf >> 27) & 1);
DmaRequest = ((rdbuf >> 26) & 1);
DmaEnable = ((rdbuf >> 25) & 1);
Dfifo2Loaded = ((rdbuf >> 23) & 1);
DataAvail = ((rdbuf >> 22) & 1);
WordSelect = ((rdbuf >> 21) & 1);
AbusWord2 = ((rdbuf >> 19) & 1);
DacCnt0 = ((rdbuf >> 16) & 1);
DacCntValue = ((rdbuf >> 1) & 0x7fff);
errlog(INFO,
"Full: %d Busy: %d Dfifo2Loaded: %d DataAvail: %d",
Full,Busy,Dfifo2Loaded,DataAvail);
errlog(INFO,
"DmaEnable: %d DmaBusy: %d DmaRequest %d",
DmaEnable,DmaBusy,DmaRequest);
errlog(INFO,
"WordSelect: %d AbusWord2: %d DacCntValue: %xx DacCnt0 %d",
WordSelect, AbusWord2, DacCntValue, DacCnt0);
if (dgReadWord(AI_LEN_REG, &rdbuf)) return (1);
errlog(INFO,"Current Length is %x",rdbuf);
return (0);
}