OpenCores
URL https://opencores.org/ocsvn/video_stream_scaler/video_stream_scaler/trunk

Subversion Repositories video_stream_scaler

[/] [video_stream_scaler/] [trunk/] [sim/] [rtl_sim/] [scaler_tb.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tesla500
/*-----------------------------------------------------------------------------
2
 
3
                                                                Video Stream Scaler testbench
4
 
5
                                                        Author: David Kronstein
6
 
7
 
8
 
9
Copyright 2011, David Kronstein, and individual contributors as indicated
10
by the @authors tag.
11
 
12
This is free software; you can redistribute it and/or modify it
13
under the terms of the GNU Lesser General Public License as
14
published by the Free Software Foundation; either version 2.1 of
15
the License, or (at your option) any later version.
16
 
17
This software is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
Lesser General Public License for more details.
21
 
22
You should have received a copy of the GNU Lesser General Public
23
License along with this software; if not, write to the Free
24
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25
02110-1301 USA, or see the FSF site: http://www.fsf.org.
26
 
27
-------------------------------------------------------------------------------
28
 
29
Testbench for streamScaler V1.0.0
30
 
31
*/
32
 
33
`default_nettype none
34
 
35
//Input files. Raw data format, no header. 8 bits per pixel, 3 color channels.
36
`define INPUT640x512                    "src/input640x512RGB.raw"
37
`define INPUT1280x1024                  "src/input1280x1024RGB.raw"
38
`define INPUT1280x1024_21EXTRA  "src/input640x512_21extraRGB.raw"       //21 extra pixels at the start to be discarded
39
 
40
module scalerTestbench;
41
parameter BUFFER_SIZE = 4;
42
 
43
wire [7-1:0] done;
44
 
45
//640x512 to 1280x1024
46
        scalerTest #(
47
        .INPUT_X_RES ( 640-1 ),
48
        .INPUT_Y_RES ( 512-1 ),
49
        .OUTPUT_X_RES ( 1280-1 ),   //Output resolution - 1
50
        .OUTPUT_Y_RES ( 1024-1 ),   //Output resolution - 1
51
        //.X_SCALE ( X_SCALE ),
52
        //.Y_SCALE ( Y_SCALE ),
53
 
54
        .DATA_WIDTH ( 8 ),
55
        .DISCARD_CNT_WIDTH ( 8 ),
56
        .INPUT_X_RES_WIDTH ( 11 ),
57
        .INPUT_Y_RES_WIDTH ( 11 ),
58
        .OUTPUT_X_RES_WIDTH ( 11 ),
59
        .OUTPUT_Y_RES_WIDTH ( 11 ),
60
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
61
        ) st_640x512to1280x1024 (
62
        .inputFilename( `INPUT640x512 ),
63
        .outputFilename( "out/output640x512to1280x1024.raw" ),
64
 
65
        //Control
66
        .inputDiscardCnt( 0 ),           //Number of input pixels to discard before processing data. Used for clipping
67
        .leftOffset( 0 ),
68
        .topFracOffset( 0 ),
69
        .nearestNeighbor( 0 ),
70
        .done ( done[0] )
71
        );
72
 
73
 
74
//640x512 to 640x512
75
        scalerTest #(
76
        .INPUT_X_RES ( 640-1 ),
77
        .INPUT_Y_RES ( 512-1 ),
78
        .OUTPUT_X_RES ( 640-1 ),   //Output resolution - 1
79
        .OUTPUT_Y_RES ( 512-1 ),   //Output resolution - 1
80
        .X_SCALE ( 32'h4000 ),
81
        .Y_SCALE ( 32'h4000 ),
82
 
83
        .DATA_WIDTH ( 8 ),
84
        .DISCARD_CNT_WIDTH ( 8 ),
85
        .INPUT_X_RES_WIDTH ( 11 ),
86
        .INPUT_Y_RES_WIDTH ( 11 ),
87
        .OUTPUT_X_RES_WIDTH ( 11 ),
88
        .OUTPUT_Y_RES_WIDTH ( 11 ),
89
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
90
        ) st_640x512to640x512 (
91
        .inputFilename( `INPUT640x512 ),
92
        .outputFilename( "out/output640x512to640x512.raw" ),
93
 
94
        //Control
95
        .inputDiscardCnt( 0 ),           //Number of input pixels to discard before processing data. Used for clipping
96
        .leftOffset( 0 ),
97
        .topFracOffset( 0 ),
98
        .nearestNeighbor( 0 ),
99
        .done ( done[1] )
100
        );
101
 
102
 
103
//1280x1024 to 960x768
104
        scalerTest #(
105
        .INPUT_X_RES ( 1280-1 ),
106
        .INPUT_Y_RES ( 1024-1 ),
107
        .OUTPUT_X_RES ( 960-1 ),   //Output resolution - 1
108
        .OUTPUT_Y_RES ( 768-1 ),   //Output resolution - 1
109
        //.X_SCALE ( X_SCALE ),
110
        //.Y_SCALE ( Y_SCALE ),
111
 
112
        .DATA_WIDTH ( 8 ),
113
        .DISCARD_CNT_WIDTH ( 8 ),
114
        .INPUT_X_RES_WIDTH ( 11 ),
115
        .INPUT_Y_RES_WIDTH ( 11 ),
116
        .OUTPUT_X_RES_WIDTH ( 11 ),
117
        .OUTPUT_Y_RES_WIDTH ( 11 ),
118
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
119
        ) st_1280x1024to960x768 (
120
        .inputFilename( `INPUT1280x1024 ),
121
        .outputFilename( "out/output1280x1024to960x768.raw" ),
122
 
123
        //Control
124
        .inputDiscardCnt( 0 ),           //Number of input pixels to discard before processing data. Used for clipping
125
        .leftOffset( 0 ),
126
        .topFracOffset( 0 ),
127
        .nearestNeighbor( 0 ),
128
        .done ( done[2] )
129
        );
130
 
131
 
132
//1280x1024 to 640x512
133
        scalerTest #(
134
        .INPUT_X_RES ( 1280-1 ),
135
        .INPUT_Y_RES ( 1024-1 ),
136
        .OUTPUT_X_RES ( 640-1 ),   //Output resolution - 1
137
        .OUTPUT_Y_RES ( 512-1 ),   //Output resolution - 1
138
        .X_SCALE ( 32'h4000*2 ),
139
        .Y_SCALE ( 32'h4000*2 ),
140
 
141
        .DATA_WIDTH ( 8 ),
142
        .DISCARD_CNT_WIDTH ( 8 ),
143
        .INPUT_X_RES_WIDTH ( 11 ),
144
        .INPUT_Y_RES_WIDTH ( 11 ),
145
        .OUTPUT_X_RES_WIDTH ( 11 ),
146
        .OUTPUT_Y_RES_WIDTH ( 11 ),
147
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
148
        ) st_1280x1024to640x512 (
149
        .inputFilename( `INPUT1280x1024 ),
150
        .outputFilename( "out/output1280x1024to640x512.raw" ),
151
 
152
        //Control
153
        .inputDiscardCnt( 0 ),           //Number of input pixels to discard before processing data. Used for clipping
154
        .leftOffset( 25'h1FFF ),
155
        .topFracOffset( 25'h1FFF ),
156
        .nearestNeighbor( 0 ),
157
        .done ( done[3] )
158
        );
159
 
160
//1280x1024 to 480x384
161
 
162
        scalerTest #(
163
        .INPUT_X_RES ( 1280-1 ),
164
        .INPUT_Y_RES ( 1024-1 ),
165
        .OUTPUT_X_RES ( 480-1 ),   //Output resolution - 1
166
        .OUTPUT_Y_RES ( 384-1 ),   //Output resolution - 1
167
        //.X_SCALE ( 32'h4000*2 ),
168
        //.Y_SCALE ( 32'h4000*2 ),
169
 
170
        .DATA_WIDTH ( 8 ),
171
        .DISCARD_CNT_WIDTH ( 8 ),
172
        .INPUT_X_RES_WIDTH ( 11 ),
173
        .INPUT_Y_RES_WIDTH ( 11 ),
174
        .OUTPUT_X_RES_WIDTH ( 11 ),
175
        .OUTPUT_Y_RES_WIDTH ( 11 ),
176
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
177
        ) st_1280x1024to480x384 (
178
        .inputFilename( `INPUT1280x1024 ),
179
        .outputFilename( "out/output1280x1024to480x384.raw" ),
180
 
181
        //Control
182
        .inputDiscardCnt( 0 ),           //Number of input pixels to discard before processing data. Used for clipping
183
        .leftOffset( 0 ),
184
        .topFracOffset( 0 ),
185
        .nearestNeighbor( 0 ),
186
        .done ( done[4] )
187
                );
188
 
189
//640x512 to 1280x1024, discarding 21
190
 
191
        scalerTest #(
192
        .INPUT_X_RES ( 640-1 ),
193
        .INPUT_Y_RES ( 512-1 ),
194
        .OUTPUT_X_RES ( 1280-1 ),   //Output resolution - 1
195
        .OUTPUT_Y_RES ( 1024-1 ),   //Output resolution - 1
196
        //.X_SCALE ( 32'h4000*2 ),
197
        //.Y_SCALE ( 32'h4000*2 ),
198
 
199
        .DATA_WIDTH ( 8 ),
200
        .DISCARD_CNT_WIDTH ( 8 ),
201
        .INPUT_X_RES_WIDTH ( 11 ),
202
        .INPUT_Y_RES_WIDTH ( 11 ),
203
        .OUTPUT_X_RES_WIDTH ( 11 ),
204
        .OUTPUT_Y_RES_WIDTH ( 11 ),
205
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
206
        ) st_640x512to1280x1024_21extra (
207
        .inputFilename( `INPUT1280x1024_21EXTRA ),
208
        .outputFilename( "out/output640x512to1280x1024_21extra.raw" ),
209
 
210
        //Control
211
        .inputDiscardCnt( 21 ),         //Number of input pixels to discard before processing data. Used for clipping
212
        .leftOffset( 0 ),
213
        .topFracOffset( 0 ),
214
        .nearestNeighbor( 0 ),
215
        .done ( done[5] )
216
                );
217
 
218
//640x512 to 1280x1024, discarding 21
219
 
220
        scalerTest #(
221
        .INPUT_X_RES ( 640-1 ),
222
        .INPUT_Y_RES ( 40-1 ),
223
        .OUTPUT_X_RES ( 640-1 ),   //Output resolution - 1
224
        .OUTPUT_Y_RES ( 512-1 ),   //Output resolution - 1
225
        .X_SCALE ( 32'h4000 * (50-1) / (640-1)-1 ),
226
        .Y_SCALE ( 32'h4000 * (40-1) / (512-1)-1 ),
227
 
228
        .DATA_WIDTH ( 8 ),
229
        .DISCARD_CNT_WIDTH ( 14 ),
230
        .INPUT_X_RES_WIDTH ( 11 ),
231
        .INPUT_Y_RES_WIDTH ( 11 ),
232
        .OUTPUT_X_RES_WIDTH ( 11 ),
233
        .OUTPUT_Y_RES_WIDTH ( 11 ),
234
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
235
        ) st_50x40to640x512clipped (
236
        .inputFilename( `INPUT640x512 ),
237
        .outputFilename( "out/output50x40to640x512clipped.raw" ),
238
 
239
        //Control
240
        .inputDiscardCnt( 640*3 ),              //Number of input pixels to discard before processing data. Used for clipping
241
        .leftOffset( {11'd249, 14'b0} ),
242
        .topFracOffset( 0 ),
243
        .nearestNeighbor( 0 ),
244
        .done ( done[6] )
245
                );
246
 
247
        initial
248
        begin
249
          #10
250
          while(done != 7'b1111111)
251
           #10
252
           ;
253
                $stop;
254
        end
255
 
256
 
257
 
258
 
259
endmodule
260
 
261
module scalerTest #(
262
parameter INPUT_X_RES = 120-1,
263
parameter INPUT_Y_RES = 90-1,
264
parameter OUTPUT_X_RES = 1280-1,   //Output resolution - 1
265
parameter OUTPUT_Y_RES = 960-1,   //Output resolution - 1
266
parameter X_SCALE = 32'h4000 * (INPUT_X_RES) / (OUTPUT_X_RES)-1,
267
parameter Y_SCALE = 32'h4000 * (INPUT_Y_RES) / (OUTPUT_Y_RES)-1,
268
 
269
parameter DATA_WIDTH = 8,
270
parameter CHANNELS = 3,
271
parameter DISCARD_CNT_WIDTH = 8,
272
parameter INPUT_X_RES_WIDTH = 11,
273
parameter INPUT_Y_RES_WIDTH = 11,
274
parameter OUTPUT_X_RES_WIDTH = 11,
275
parameter OUTPUT_Y_RES_WIDTH = 11,
276
parameter BUFFER_SIZE = 6                               //Number of RAMs in RAM ring buffer
277
)(
278
input wire [50*8:0] inputFilename, outputFilename,
279
 
280
//Control
281
input wire [DISCARD_CNT_WIDTH-1:0]       inputDiscardCnt,                //Number of input pixels to discard before processing data. Used for clipping
282
input wire [INPUT_X_RES_WIDTH+14-1:0] leftOffset,
283
input wire [14-1:0]      topFracOffset,
284
input wire nearestNeighbor,
285
 
286
output reg done
287
 
288
);
289
 
290
 
291
reg clk;
292
reg rst;
293
 
294
 
295
reg [DATA_WIDTH*CHANNELS-1:0] dIn;
296
reg             dInValid;
297
wire    nextDin;
298
reg             start;
299
 
300
wire [DATA_WIDTH*CHANNELS-1:0] dOut;
301
wire    dOutValid;
302
reg             nextDout;
303
 
304
integer r, rfile, wfile;
305
 
306
initial // Clock generator
307
  begin
308
    #10 //Delay to allow filename to get here
309
    clk = 0;
310
    #5 forever #5 clk = !clk;
311
  end
312
 
313
initial // Reset
314
  begin
315
        done = 0;
316
    #10 //Delay to allow filename to get here
317
    rst = 0;
318
    #5 rst = 1;
319
    #4 rst = 0;
320
   // #50000 $stop;
321
  end
322
 
323
reg eof;
324
reg [DATA_WIDTH*CHANNELS-1:0] readMem [0:0];
325
initial // Input file read, generates dIn data
326
begin
327
  #10 //Delay to allow filename to get here
328
        rfile = $fopen(inputFilename, "rb");
329
 
330
        dIn = 0;
331
        dInValid = 0;
332
        start = 0;
333
 
334
        #41
335
        start = 1;
336
 
337
        #10
338
        start = 0;
339
 
340
        #20
341
        r = $fread(readMem, rfile);
342
        dIn = readMem[0];
343
 
344
        while(! $feof(rfile))
345
        begin
346
                dInValid = 1;
347
 
348
                #10
349
                if(nextDin)
350
                begin
351
                        r = $fread(readMem, rfile);
352
                        dIn = readMem[0];
353
                end
354
        end
355
 
356
  $fclose(rfile);
357
end
358
 
359
//Generate nextDout request signal
360
initial
361
begin
362
  #10 //Delay to match filename arrival delay
363
        nextDout = 0;
364
        #140001
365
        forever
366
        begin
367
                //This can be used to slow down the read to simulate live read-out. This basically inserts H blank periods.
368
                #(10*(OUTPUT_X_RES+1)*4)
369
                nextDout = 0;
370
                #(10*(OUTPUT_X_RES+1))
371
                nextDout = 1;
372
 
373
        end
374
end
375
 
376
//Read dOut and write to file
377
integer dOutCount;
378
initial
379
begin
380
  #10 //Delay to allow filename to get here
381
        wfile = $fopen(outputFilename, "wb");
382
        nextDout = 0;
383
        dOutCount = 0;
384
        #1
385
        while(dOutCount < (OUTPUT_X_RES+1) * (OUTPUT_Y_RES+1))
386
        begin
387
                #10
388
                if(dOutValid == 1)
389
                begin
390
                        $fwrite(wfile, "%c", dOut[23:16]);
391
                        $fwrite(wfile, "%c", dOut[15:8]);
392
                        $fwrite(wfile, "%c", dOut[7:0]);
393
                        dOutCount = dOutCount + 1;
394
                end
395
        end
396
        $fclose(wfile);
397
        done = 1;
398
end
399
 
400
streamScaler #(
401
.DATA_WIDTH( DATA_WIDTH ),
402
.CHANNELS( CHANNELS ),
403
.DISCARD_CNT_WIDTH( DISCARD_CNT_WIDTH ),
404
.INPUT_X_RES_WIDTH( INPUT_X_RES_WIDTH ),
405
.INPUT_Y_RES_WIDTH( INPUT_Y_RES_WIDTH ),
406
.OUTPUT_X_RES_WIDTH( OUTPUT_X_RES_WIDTH ),
407
.OUTPUT_Y_RES_WIDTH( OUTPUT_Y_RES_WIDTH ),
408
.BUFFER_SIZE( BUFFER_SIZE )                             //Number of RAMs in RAM ring buffer
409
) scaler_inst (
410
.clk( clk ),
411
.rst( rst ),
412
 
413
.dIn( dIn ),
414
.dInValid( dInValid ),
415
.nextDin( nextDin ),
416
.start( start ),
417
 
418
.dOut( dOut ),
419
.dOutValid( dOutValid ),
420
.nextDout( nextDout ),
421
 
422
//Control
423
.inputDiscardCnt( inputDiscardCnt ),            //Number of input pixels to discard before processing data. Used for clipping
424
.inputXRes( INPUT_X_RES ),                              //Input data number of pixels per line
425
.inputYRes( INPUT_Y_RES ),
426
 
427
.outputXRes( OUTPUT_X_RES ),                            //Resolution of output data
428
.outputYRes( OUTPUT_Y_RES ),
429
.xScale( X_SCALE ),                                     //Scaling factors. Input resolution scaled by 1/xScale. Format Q4.14
430
.yScale( Y_SCALE ),                                     //Scaling factors. Input resolution scaled by 1/yScale. Format Q4.14
431
 
432
.leftOffset( leftOffset ),
433
.topFracOffset( topFracOffset ),
434
.nearestNeighbor( nearestNeighbor )
435
);
436
 
437
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.