iotestai.c
5 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
/*************************************************************************
*
* File: iotestai.c
*
* This file contains test routines for the Audio Interface (AI).
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/iotestai.c,v 1.2 2002/05/30 05:52:50 whs Exp $
*
*/
#include <stdio.h>
#include "trace.h"
#include "iomap.h"
#include "iotest.h"
/***********************************************************************
* Init routine for AI
*/
void
AiInit(unsigned int dacRate, unsigned int bitRate)
{
/*
* DAC rate value is: at least 131
* Bit rate value is: at least 1
*/
IO_WRITE(AI_DACRATE_REG, dacRate);
IO_WRITE(AI_BITRATE_REG, bitRate);
IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON);
} /* AiInit */
/***********************************************************************
* Test routines for AI
*/
static int
aiPollStatus(unsigned int statBits)
{
/* Poll AI status register for the statBits set */
int stat;
do {
stat = IO_READ(AI_STATUS_REG);
_TRACE(DSTATUS, fprintf(LogFp, "\tAI Status = 0x%08x\n",
stat));
} while (stat & statBits);
return(0);
} /* aiPollStatus */
int
IoAiDmaCopy(unsigned int dramAddr, int nbytes)
{
/* dramAddr must be 8-byte aligned */
/* nbytes specifies number of multiple of 8 bytes (8, 16, 24,...) */
dramAddr &= 0xFFFFFFF8;
nbytes &= 0xFFFFFFF8;
#ifdef CHECK_STATUS
aiPollStatus(AI_STATUS_FIFO_FULL | PI_STATUS_DMA_BUSY);
#endif
/* Need to write address first and length second */
IO_WRITE(AI_DRAM_ADDR_REG, dramAddr);
IO_WRITE(AI_LEN_REG, (unsigned int)nbytes);
return(0);
} /* IoAiDmaCopy */
int
AiTestInit(int dacRate, int bitRate, int a3, int a4)
{
AiInit(dacRate, bitRate);
return(0);
} /* AiTestInit */
int
AiTestStatus(int testBits, int a2, int a3, int a4)
{
/* Read the AI status reg and compare it against testBits */
aiPollStatus(testBits);
return(0);
} /* AiTestStatus */
int
AiTestReg(int regAddr, int data, int a3, int a4)
{
/* a1 = register address */
/* a2 = test data */
/* Write/Read to/from DRAM address and Cartridge registers */
unsigned int ret;
errorCount = 0;
regAddr &= 0xFFFFFFFC; /* Make sure that it's word-aligned */
_TRACE(DLOG, printf("\tAI Status Reg = 0x%08x\n",
IO_READ(AI_STATUS_REG)));
/* Hw reset the address to be 8-byte aligned
* Also, DMA RAM address is only 24-bit, upper 8 bits are
* also set to 0?
*/
IO_WRITE(regAddr, data);
ret = IO_READ(regAddr);
if (data != ret) {
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* AiTestReg */
int
AiCompareData(int regAddr, int data, int a3, int a4)
{
/* Poll register until content equals to data */
/* a1 = register address */
/* a2 = test data */
unsigned int ret;
do {
ret = IO_READ(regAddr);
} while (ret != data);
return(1);
} /* AiCompareData */
int
AiTestDma(int dramAddr, int nbytes, int a3, int a4)
{
/* CPU issues DMA (write) requests from RDRAM to AI devices */
errorCount = 0;
dramAddr &= 0xFFFFFFF8; /* Make sure it's 8-byte aligned */
nbytes &= 0xFFFFFFF8;
if (IoAiDmaCopy((unsigned int)dramAddr, nbytes) < 0) {
errorCount++;
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* AiTestDma */
int
AiTestDmaPg(int dramAddr, int npages, int a3, int a4)
{
/*
* CPU issues DMA (write) requests between SI devices and
* RDRAM pages
* 2 RDRAMs: 1 RDRAM = 1 MBytes = 2 banks;
* 1 bank = 256 pages; 1 page = 2 KBytes
*/
int i, startPg, nbytes, dir;
unsigned int address;
errorCount = 0;
nbytes = 8;
dir = DIR_TO_RAM;
dramAddr &= 0xFFFFFFF8; /* Make sure addresses are 8B aligned */
startPg = dramAddr / RDRAM_PAGE_SIZE;
i = MAX_RDRAM_PAGES - startPg;
if (npages > i)
npages = i;
for (i=0; i < npages; i++) {
address = (dramAddr + (i*RDRAM_PAGE_SIZE)) & 0xFFFFFFF8;
if (IoAiDmaCopy((unsigned int)address, nbytes) < 0) {
errorCount++;
}
#ifndef CHECK_STATUS
aiPollStatus(AI_STATUS_FIFO_FULL | PI_STATUS_DMA_BUSY);
#endif
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* AiTestDmaPg */
int
AiStartDma(int dramAddr, int nbytes, int a3, int a4)
{
/* CPU issues DMA (write) requests from RDRAM to AI devices */
errorCount = 0;
dramAddr &= 0xFFFFFFF8; /* Make sure it's 8-byte aligned */
nbytes &= 0xFFFFFFF8;
IoAiDmaCopy((unsigned int)dramAddr, nbytes);
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* AiStartDma */
int
AiCompareLength(int regAddr, int data, int a3, int a4)
{
/* Poll Length register until content less than to data */
/* a1 = register address forced to AI_LEN_REG */
/* a2 = test data for compare */
unsigned int ret;
unsigned int stat;
int errorCount;
errorCount = -1;
do {
stat = IO_READ(AI_STATUS_REG);
ret = IO_READ(AI_LEN_REG);
_TRACE(DLOG, printf("\tAI Length Reg = 0x%08x\n", ret));
if (ret <= data) {
errorCount =0;
break;
}
/* will not work if length compared with is small */
} while (stat & AI_STATUS_DMA_BUSY) ;
return(errorCount);
} /* AiCompareLength */