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

Subversion Repositories bilinear_demosaic

[/] [bilinear_demosaic/] [trunk/] [sim/] [rtl_sim/] [demosaic_tb.v.bak] - 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 done;
44
 
45
 
46
        initial
47
        begin
48
          #10
49
          while(done != 1'b1)
50
           #10
51
           ;
52
                $stop;
53
        end
54
 
55
//640x512 to 1280x1024
56
        demosaicTest #(
57
        .X_RES ( 640-1 ),
58
        .Y_RES ( 512-1 ),
59
 
60
        .DATA_WIDTH ( 8 ),
61
        .X_RES_WIDTH ( 11 ),
62
        .Y_RES_WIDTH ( 11 ),
63
        .BUFFER_SIZE ( BUFFER_SIZE )                            //Number of RAMs in RAM ring buffer
64
        ) dt_640x512 (
65
        .inputFilename( "src/input640x512RGBBlur.raw" ),
66
        .outputFilename( "out/output640x512.raw" ),
67
 
68
        //Control
69
        .done ( done )
70
        );
71
 
72
 
73
 
74
 
75
 
76
 
77
 
78
endmodule
79
 
80
module demosaicTest #(
81
parameter X_RES = 640-1,
82
parameter Y_RES = 512-1,
83
 
84
parameter DATA_WIDTH = 8,
85
parameter X_RES_WIDTH = 11,
86
parameter Y_RES_WIDTH = 11,
87
 
88
parameter BUFFER_SIZE = 5                               //Number of RAMs in RAM ring buffer
89
)(
90
input wire [50*8:0] inputFilename, outputFilename,
91
 
92
//Control
93
 
94
output reg done
95
 
96
);
97
 
98
 
99
reg clk;
100
reg rst;
101
 
102
 
103
reg [DATA_WIDTH-1:0] dIn;
104
reg             dInValid;
105
wire    nextDin;
106
reg             start;
107
 
108
wire [DATA_WIDTH-1:0] rOut;
109
wire [DATA_WIDTH-1:0] gOut;
110
wire [DATA_WIDTH-1:0] bOut;
111
wire    dOutValid;
112
reg             nextDout;
113
 
114
reg [X_RES_WIDTH-1:0] xCount;
115
reg [Y_RES_WIDTH-1:0] yCount;
116
 
117
integer r, rfile, wfile;
118
 
119
initial // Clock generator
120
  begin
121
    #10 //Delay to allow filename to get here
122
    clk = 0;
123
    #5 forever #5 clk = !clk;
124
  end
125
 
126
initial // Reset
127
  begin
128
        done = 0;
129
    #10 //Delay to allow filename to get here
130
    rst = 0;
131
    #5 rst = 1;
132
    #4 rst = 0;
133
   // #50000 $stop;
134
  end
135
 
136
reg eof;
137
reg [24-1:0] readMem [0:0];
138
 
139
wire [1:0] quadSelect = {yCount[0], xCount[0]};
140
initial // Input file read, generates dIn data
141
begin
142
  #10 //Delay to allow filename to get here
143
        rfile = $fopen("src/input640x512RGBBlur.raw"/*inputFilename*/, "rb");
144
 
145
        dIn = 0;
146
        dInValid = 0;
147
        start = 0;
148
        xCount = 0;
149
        yCount = 0;
150
 
151
        #41
152
        start = 1;
153
 
154
        #10
155
        start = 0;
156
 
157
        #20
158
        r = $fread(readMem, rfile);
159
        dIn =   quadSelect == 2'b00 ? readMem[0][23:16] :               //RG    [23:16] is first data (R)
160
                        quadSelect == 2'b01 ? readMem[0][15:8] :        //GB
161
                        quadSelect == 2'b10 ? readMem[0][15:8] :
162
                                                                  readMem[0][7:0];
163
        xCount = xCount + 1;
164
 
165
        while(! $feof(rfile))
166
        begin
167
                dInValid = 1;
168
 
169
                #10
170
                if(nextDin)
171
                begin
172
                        r = $fread(readMem, rfile);
173
 
174
 
175
                        dIn =   quadSelect == 2'b00 ? readMem[0][23:16] :               //RG    [23:16] is first data (R)
176
                                        quadSelect == 2'b01 ? readMem[0][15:8] :        //GB
177
                                        quadSelect == 2'b10 ? readMem[0][15:8] :
178
                                                                                  readMem[0][7:0];
179
 
180
                        if(xCount == X_RES)
181
                        begin
182
                                xCount = 0;
183
                                yCount = yCount + 1;
184
                        end
185
                        else
186
                                xCount = xCount + 1;
187
 
188
                end
189
        end
190
 
191
  $fclose(rfile);
192
end
193
 
194
//Generate nextDout request signal
195
initial
196
begin
197
  #10 //Delay to match filename arrival delay
198
        nextDout = 0;
199
        #140001
200
        forever
201
        begin
202
                //This can be used to slow down the read to simulate live read-out. This basically inserts H blank periods.
203
                #(10*(X_RES+1)*4)
204
                nextDout = 1;
205
                #(10*(X_RES+1))
206
                nextDout = 1;
207
 
208
        end
209
end
210
 
211
//Read dOut and write to file
212
integer dOutCount;
213
initial
214
begin
215
  #10 //Delay to allow filename to get here
216
        wfile = $fopen("dst/output.raw", "wb");
217
        nextDout = 0;
218
        dOutCount = 0;
219
        #1
220
        while(dOutCount < ((X_RES+1) * (Y_RES+1)))
221
        begin
222
                #10
223
                if(dOutValid == 1)
224
                begin
225
                        $fwrite(wfile, "%c", rOut[7:0]);
226
                        $fwrite(wfile, "%c", gOut[7:0]);
227
                        $fwrite(wfile, "%c", bOut[7:0]);
228
                        dOutCount = dOutCount + 1;
229
                end
230
        end
231
        $fclose(wfile);
232
        done = 1;
233
end
234
 
235
bilinearDemosaic #(
236
.DATA_WIDTH( DATA_WIDTH ),
237
.X_RES_WIDTH( X_RES_WIDTH ),
238
.Y_RES_WIDTH( Y_RES_WIDTH ),
239
.BUFFER_SIZE( BUFFER_SIZE )                             //Number of RAMs in RAM ring buffer
240
) demosaic_inst (
241
.clk( clk ),
242
.rst( rst ),
243
 
244
.dIn( dIn ),
245
.dInValid( dInValid ),
246
.nextDin( nextDin ),
247
.start( start ),
248
 
249
.rOut( rOut ),
250
.gOut( gOut ),
251
.bOut( bOut ),
252
.dOutValid( dOutValid ),
253
.nextDout( nextDout ),
254
 
255
.xRes( X_RES ),                         //Input data number of pixels per line
256
.yRes( Y_RES )
257
 
258
);
259
 
260
 
261
 
262
endmodule

powered by: WebSVN 2.1.0

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