ai_pintests.c
3.62 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
#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>
int
ai_pintests (TEST_REF *test_ref)
{
int NumFailures = 0;
int DmaInProcess;
int i;
int reg_value ;
unsigned int bit_rate_clear;
unsigned int bit_rate_set;
int *pwbuf;
int *prbuf;
unsigned int numbytes;
unsigned int rdbuf;
#define NumSamples 4
unsigned char wbuf[NumSamples*4];
unsigned char rbuf[NumSamples*4];
pwbuf = (int *)wbuf;
prbuf = (int *)rbuf;
/* Initialize Rdram */
errlog(DEBUG,"Initializing Rdram");
/* send 4 samples out to the DAC
* each sample is 2 16 bit l/r channel pairs
*/
/* rdram image for audio buffer
* 63 48:47 32:31 16:15 00
* L0 R0 L1 R1
* Sample 0 : Sample 1
*/
*pwbuf = 0x8ef08000;
*(pwbuf+1) = 0x8ef18001;
*(pwbuf+2) = 0x8ef28002;
*(pwbuf+3) = 0x8ef38003;
numbytes = NumSamples * 4;
for (i = 0; i < NumSamples ; i ++) {
if (dgWriteWord ((dgRdramFree+(i*4)),*(pwbuf+i))) return (1);
if (dgReadWord ((dgRdramFree+(i*4)),&rdbuf)) return (1);
errlog (DEBUG,"rdram data is %08x",rdbuf);
if (rdbuf != *(pwbuf+i)) {
errlog ( ERR_SEVERE,
"Rdram buffer load failed - actual = %08x, expected = %08x",
rdbuf, *(pwbuf+i));
}
}
/*
if (dgWriteMem (dgRdramFree, numbytes, ((char *)pwbuf)) ) return (1);
if (dgReadMem (dgRdramFree, numbytes, ((char *)prbuf)) ) return (1);
for (i = 0; i < NumSamples; i++){
errlog(DEBUG,"MemDatat is %08x",*(pwbuf+i));
if (*(pwbuf+i) != *(prbuf+i) ) {
errlog(ERR_SEVERE,
"Rdram buffer load failed - actual = %08x, expected = %08x",
*(prbuf+i), *(pwbuf+i));
}
}
*/
/* Init VI to get video clock signal into AI */
if (dgWriteWord(VI_STATUS_REG, 0) ) return (1);
/* need read status word and compare */
/* 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)
*/
if ( dgWriteWord(AI_DACRATE_REG, 0x44f) ) return (1);
if ( dgWriteWord(AI_BITRATE_REG, 0xf) ) return (1);
/* ensure ai status word indicates dma not full */
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
if (rdbuf & AI_STATUS_FIFO_FULL)
errlog (ERR_SEVERE,"AI Status is full, should be 0 on reset");
if (dgWriteWord(AI_DRAM_ADDR_REG,dgRdramFree) ) return(1);
if (dgWriteWord(AI_LEN_REG,(NumSamples*2)) ) return (1);
/* try the double buffer */
/* not sure double bufferd is needed.
if (dgWriteWord(AI_DRAM_ADDR_REG,dgRdramFree) ) return(1);
if (dgWriteWord(AI_LEN_REG,(NumSamples*2)) ) return (1);
*/
/* turn on dma */
errlog(DEBUG,"Starting Audio DMA Now");
if ( dgWriteWord(AI_CONTROL_REG, AI_CONTROL_DMA_ON) ) return (1);
/* monitor audio length till its 0 */
DmaInProcess = 1;
while (DmaInProcess){
if (dgReadWord(AI_LEN_REG,&rdbuf)) return (1);
if (rdbuf != 0) {
errlog(DEBUG,"Length is now %08x",rdbuf);
DmaInProcess = 1;
}
else {
errlog(INFO,"Audio DMA Complete");
DmaInProcess = 0;
}
}
/* kill some time */
for (i = 0; i < 512; i++){
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
errlog(DEBUG,"AI DAC Counter is %08x",((rdbuf & 0xff) >> 1));
}
return(NumFailures);
}