inp003.c
5.07 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
317
318
319
320
321
322
323
324
325
326
327
328
/*
* inp002.c: Random test case
*/
#define NUM_RUNS (1000)
#define MAX_DX (5.0)
#define BIAS_L (MAX_DX+2)
#define BIAS_R (BIAS_L+2)
#include <stdio.h>
#include "sigs.h"
char *strcpy (char *s1, const char *s2);
int gen_test_case( void );
void send_params( void );
void send_pixels( int );
void dump_test( void );
int time( int );
int srandom( int );
int random( void );
#define RXX(x,y) ((x)+(random()%((y)-(x)+1)))
#define RX2x(x) (RX(-(x),(x)))
#define RX2(x) (random()&(x))
#define R2(x) (random()&((x)-1))
/*
* Generate test vectors
*/
main(int argc, char **argv)
{
int i;
int n;
int rseed = 0x12345678;
if( argc > 1 )
rseed = time( 0 );
srandom(rseed);
x_major = 0x00;
cycle_type = 0;
left = 1;
print_input_header();
printf("# Seed = %d\n", rseed );
printf("# reset 6 clocks\n");
reset = 0;
for(i = 0; i < 6; i++)
print_input_sigs();
reset = 1;
for(i=0; i<NUM_RUNS; i++) {
cycle_type = R2(2);
left = R2(2);
n = gen_test_case();
send_params();
send_pixels( n );
};
}
/*
Generate Random Spans
*/
double xleft[4],
xright[4];
int xval;
int xmin,
xmax;
void gen_xs( double *, double, double );
int
gen_test_case( void )
{
int i;
int shft;
shft = RXX(-6,1029);
gen_xs( xleft, MAX_DX, shft );
gen_xs( xright, MAX_DX, shft+1 );
xval = 0;
xmin = xleft[0];
xmax = xright[0];
for(i=0; i<4; i++) {
if(xleft[i] < xright[i])
xval |= (1<<i);
if( xleft[i] < xmin )
xmin = xleft[i];
if( xright[i] < xmin )
xmin = xright[i];
if( xleft[i] > xmax )
xmax = xleft[i];
if( xright[i] > xmax )
xmax = xright[i];
if( xleft[i] < 0 )
xleft[i] = 0;
else if( xleft[i] > 1023.9 )
xleft[i] = 1023.9;
if( xright[i] < 0 )
xright[i] = 0;
else if( xright[i] > 1023.9 )
xright[i] = 1023.9;
};
return( BIAS_R+MAX_DX+1 );
}
double frand( void );
#include <values.h>
void
gen_xs( double *xlist, double dx, double bias )
{
int iy;
double cx, cy;
double dxt, dxb;
double x,y;
cx = frand();
cy = frand();
dxt = (2*dx*frand()) - dx;
dxb = (2*dx*frand()) - dx;
for(iy=0; iy<4; iy++) {
y = iy * 0.25;
if( y < cy ) /* Top */
x = (y-cy)*dxt;
else
x = (y-cy)*dxb;
xlist[iy] = x + cx + bias;
};
}
double
frand( void )
{
return( random()/(MAXINT * 1.0) );
}
/*
Send Span Parameters
*/
#define XM(x) (end[i]*8)
#define XH(x) (start[i]*8)
void
send_params( void )
{
int i;
double *start, *end;
dump_test();
if( left ) {
start = xleft;
end = xright;
} else {
start = xright;
end = xleft;
};
for(i=0; i<4; i++) {
printf("# xh%d (%lg)\n", i, end[i]);
ew_cv_data = XH(i);
print_input_sigs();
printf("# xm%d (%lg)\n", i, start[i]);
ew_cv_data = XM(i);
print_input_sigs();
};
printf("# xval, latch xm's, xh's\n");
ew_cv_data = xval;
ew_cv_newspan = 1;
if( left )
x_major = xmin-1;
else
x_major = xmax+1;
print_input_sigs();
ew_cv_newspan = 0;
if( cycle_type )
print_input_sigs();
dv = 1; /* one clock after new span, data should be valid */
}
void
send_pixels( int n )
{
int i;
printf("# Range xmin = %d, xmax = %d\n", xmin, xmax );
if( left )
for(i=xmin-1; i<=xmax+1; i++) {
printf("#pixel x = %d\n", i );
x_major = i;
print_input_sigs();
if( cycle_type )
print_input_sigs();
}
else
for(i=xmax+1; i>=xmin-1; i--) {
printf("#pixel x = %d\n", i );
x_major = i;
print_input_sigs();
if( cycle_type )
print_input_sigs();
}
}
/*
General Support Routines
*/
/*
* Prints header info for input signals, same for all dumps
*/
static void
print_input_header( void )
{
printf("gclk @C 1(8) 0(8)\n");
printf("ew_cv_data[12:0] @I @E 0\n");
printf("x_major[11:0] @I @E 0\n");
printf("cycle_type @I @E 0\n");
printf("ew_cv_newspan @I @E 0\n");
printf("left @I @E 0\n");
printf("reset @I @E 0\n");
printf("dv @I @E 0\n");
printf("\n");
}
/*
* Prints signal values info for input signals, same for all dumps
*/
static void
print_input_sigs( void )
{
printf("0x%.4x 0x%0.3x %d %d %d %d %d\n",
ew_cv_data,
x_major & 0xfff,
cycle_type,
ew_cv_newspan,
left,
reset,
dv);
}
char *top = " %4d ";
char *row[5] = { "* - * - ",
"| * . * ",
"* . * . ",
"| * . * ",
"+ - - - "
};
char *lastc = "+|||+";
double floor (double x);
void
dump_test( void )
{
int i;
int x,y;
char tmp[9];
printf("# ");
for(x=xmin; x<=xmax; x++) {
printf(top,x);
};
printf("\n");
for(y=0; y<4; y++) {
printf("# ");
for(x=xmin; x<=xmax; x++) {
strcpy( tmp, row[y] );
i = floor( 8*(xleft[y] - x) );
if( (i>=0) && (i<8) )
tmp[i] = 'L';
i = floor( 8*(xright[y] - x) );
if( (i>=0) && (i<8) ) {
if( tmp[i] == 'L' )
tmp[i] = 'X';
else
tmp[i] = 'R';
};
printf(tmp);
};
printf("%c\n", lastc[y] );
};
printf("# ");
for(x=xmin; x<=xmax; x++) {
printf(row[4]);
};
printf("%c\n", lastc[4]);
}