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

Subversion Repositories bilinear_demosaic

[/] [bilinear_demosaic/] [trunk/] [sim/] [rtl_sim/] [demosaic_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 bilinearDemosaic V1.0.0
30
 
31
*/
32
 
33
`default_nettype none
34
 
35
module scalerTestbench;
36
parameter BUFFER_SIZE = 4;
37
 
38
wire [2:0] done;
39
 
40
//Input throttling (data source slower than data sink)
41
        demosaicTest #(
42
        .X_RES ( 640-1 ),
43
        .Y_RES ( 512-1 ),
44
 
45
        .DATA_WIDTH ( 8 ),
46
        .X_RES_WIDTH ( 11 ),
47
        .Y_RES_WIDTH ( 11 ),
48
        .BUFFER_SIZE ( BUFFER_SIZE ),                           //Number of RAMs in RFIFO
49
        .DIN_VALID_PERIOD ( 1000 ),
50
        .DIN_VALID_ON( 800 ),
51
        .DOUT_VALID_PERIOD( 1000 ),
52
        .DOUT_VALID_ON( 1000 )
53
        ) dt_640x512_it (
54
        .inputFilename( "src/input640x512RGBBlur.raw" ),
55
        .outputFilename( "dst/outputIT.raw" ),
56
 
57
        //Control
58
        .done ( done[0] )
59
        );
60
 
61
 
62
//No throttling (full speed)
63
        demosaicTest #(
64
        .X_RES ( 640-1 ),
65
        .Y_RES ( 512-1 ),
66
 
67
        .DATA_WIDTH ( 8 ),
68
        .X_RES_WIDTH ( 11 ),
69
        .Y_RES_WIDTH ( 11 ),
70
        .BUFFER_SIZE ( BUFFER_SIZE ),                           //Number of RAMs in RFIFO
71
        .DIN_VALID_PERIOD ( 1000 ),
72
        .DIN_VALID_ON( 1000 ),
73
        .DOUT_VALID_PERIOD( 1000 ),
74
        .DOUT_VALID_ON( 1000 )
75
        ) dt_640x512_fs (
76
        .inputFilename( "src/input640x512RGBBlur.raw" ),
77
        .outputFilename( "dst/outputFS.raw" ),
78
 
79
        //Control
80
        .done ( done[1] )
81
        );
82
 
83
//output throttling (data sink slower than data source, as in typical readout for a live display with blanking periods)
84
        demosaicTest #(
85
        .X_RES ( 640-1 ),
86
        .Y_RES ( 512-1 ),
87
 
88
        .DATA_WIDTH ( 8 ),
89
        .X_RES_WIDTH ( 11 ),
90
        .Y_RES_WIDTH ( 11 ),
91
        .BUFFER_SIZE ( BUFFER_SIZE ),                           //Number of RAMs in RFIFO
92
        .DIN_VALID_PERIOD ( 1000 ),
93
        .DIN_VALID_ON( 1000 ),
94
        .DOUT_VALID_PERIOD( 1000 ),
95
        .DOUT_VALID_ON( 800 )
96
        ) dt_640x512_ot (
97
        .inputFilename( "src/input640x512RGBBlur.raw" ),
98
        .outputFilename( "dst/outputOT.raw" ),
99
 
100
        //Control
101
        .done ( done[2] )
102
        );
103
 
104
        initial
105
        begin
106
          #10
107
          while(done != 3'b111)
108
           #10
109
           ;
110
                $stop;
111
        end
112
endmodule
113
 
114
 
115
module demosaicTest #(
116
parameter X_RES = 640-1,
117
parameter Y_RES = 512-1,
118
 
119
parameter DATA_WIDTH = 8,
120
parameter X_RES_WIDTH = 11,
121
parameter Y_RES_WIDTH = 11,
122
 
123
parameter BUFFER_SIZE = 5,                              //Number of RAMs in RFIFO
124
 
125
parameter DIN_VALID_PERIOD = 1000,
126
parameter DIN_VALID_ON = 1000,
127
parameter DOUT_VALID_PERIOD = 1000,
128
parameter DOUT_VALID_ON = 1000
129
 
130
)(
131
input wire [50*8:0] inputFilename, outputFilename,
132
 
133
//Control
134
 
135
output reg done
136
);
137
 
138
reg                                             clk;
139
reg                                             rst;
140
 
141
reg [DATA_WIDTH-1:0]     dIn;
142
reg                                             dInValid;
143
wire                                    nextDin;
144
reg                                             start;
145
 
146
wire [DATA_WIDTH-1:0]    rOut;
147
wire [DATA_WIDTH-1:0]    gOut;
148
wire [DATA_WIDTH-1:0]    bOut;
149
wire                                    dOutValid;
150
reg                                             nextDout;
151
 
152
reg [X_RES_WIDTH-1:0]    xCount;
153
reg [Y_RES_WIDTH-1:0]    yCount;
154
 
155
integer r, rfile, wfile;
156
 
157
initial // Clock generator
158
  begin
159
    #10 //Delay to allow filename to get here
160
    clk = 0;
161
    #5 forever #5 clk = !clk;
162
  end
163
 
164
initial // Reset
165
  begin
166
        done = 0;
167
    #10 //Delay to allow filename to get here
168
    rst = 0;
169
    #5 rst = 1;
170
    #4 rst = 0;
171
   // #50000 $stop;
172
  end
173
 
174
reg eof;
175
reg [24-1:0] readMem [0:0];
176
integer readCount;
177
 
178
wire [1:0] quadSelect = {yCount[0], xCount[0]};
179
initial // Input file read, generates dIn data
180
begin
181
  #10 //Delay to allow filename to get here
182
        rfile = $fopen(inputFilename, "rb");
183
 
184
        dIn = 0;
185
        dInValid = 0;
186
        start = 0;
187
        xCount = 0;
188
        yCount = 0;
189
        readCount = 0;
190
 
191
        #41
192
        start = 1;
193
 
194
        #10
195
        start = 0;
196
 
197
        #20
198
        r = $fread(readMem, rfile);
199
        dIn =   quadSelect == 2'b00 ? readMem[0][23:16] :                //RG    [23:16] is first data (R)
200
                        quadSelect == 2'b01 ? readMem[0][15:8] : //GB
201
                        quadSelect == 2'b10 ? readMem[0][15:8] :
202
                                                                  readMem[0][7:0];
203
        xCount = xCount + 1;
204
 
205
        dInValid = 1;
206
 
207
        while(! $feof(rfile))
208
        begin
209
                #10
210
                if(nextDin)
211
                begin
212
                        if(dInValid)
213
                        begin
214
                                r = $fread(readMem, rfile);
215
 
216
 
217
                                dIn =   quadSelect == 2'b00 ? readMem[0][23:16] :                //RG    [23:16] is first data (R)
218
                                                quadSelect == 2'b01 ? readMem[0][15:8] : //GB
219
                                                quadSelect == 2'b10 ? readMem[0][15:8] :
220
                                                                                          readMem[0][7:0];
221
 
222
                                if(xCount == X_RES)
223
                                begin
224
                                        xCount = 0;
225
                                        yCount = yCount + 1;
226
                                end
227
                                else
228
                                        xCount = xCount + 1;
229
                        end
230
 
231
                        readCount = readCount + 1;      //pulse dInValid to simulate a slow data source
232
                        if(readCount == DIN_VALID_PERIOD)
233
                        begin
234
                                readCount = 0;
235
                                dInValid = 1;
236
                        end
237
                        else if(readCount == DIN_VALID_ON)
238
                        begin
239
                                dInValid = 0;
240
                        end
241
 
242
 
243
                end
244
        end
245
 
246
  $fclose(rfile);
247
end
248
 
249
//Generate nextDout request signal
250
initial
251
begin
252
  #10 //Delay to match filename arrival delay
253
        nextDout = 0;
254
        #140001
255
        forever
256
        begin
257
                //This can be used to slow down the read to simulate live read-out. This basically inserts H blank periods.
258
                #(10*(DOUT_VALID_PERIOD - DOUT_VALID_ON))
259
                nextDout = 1;
260
                #(10*(DOUT_VALID_ON))
261
                nextDout = 0;
262
 
263
        end
264
end
265
 
266
//Read dOut and write to file
267
integer dOutCount;
268
initial
269
begin
270
  #10 //Delay to allow filename to get here
271
        wfile = $fopen(outputFilename, "wb");
272
        nextDout = 0;
273
        dOutCount = 0;
274
        #1
275
        while(dOutCount < ((X_RES+1) * (Y_RES+1)))
276
        begin
277
                #10
278
                if(dOutValid == 1)
279
                begin
280
                        $fwrite(wfile, "%c", rOut[7:0]);
281
                        $fwrite(wfile, "%c", gOut[7:0]);
282
                        $fwrite(wfile, "%c", bOut[7:0]);
283
                        dOutCount = dOutCount + 1;
284
                end
285
        end
286
        $fclose(wfile);
287
        done = 1;
288
end
289
 
290
bilinearDemosaic #(
291
.DATA_WIDTH( DATA_WIDTH ),
292
.X_RES_WIDTH( X_RES_WIDTH ),
293
.Y_RES_WIDTH( Y_RES_WIDTH ),
294
.BUFFER_SIZE( BUFFER_SIZE )                             //Number of RAMs in RFIFO
295
) demosaic_inst (
296
.clk( clk ),
297
.rst( rst ),
298
 
299
.dIn( dIn ),
300
.dInValid( dInValid ),
301
.nextDin( nextDin ),
302
.start( start ),
303
 
304
.rOut( rOut ),
305
.gOut( gOut ),
306
.bOut( bOut ),
307
.dOutValid( dOutValid ),
308
.nextDout( nextDout ),
309
 
310
.bayerPattern( 0 ),
311
.xRes( X_RES ),                         //Input data number of pixels per line
312
.yRes( Y_RES )
313
 
314
);
315
endmodule

powered by: WebSVN 2.1.0

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