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

Subversion Repositories cavlc

[/] [cavlc/] [trunk/] [bench/] [cavlc_tb.v] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 qiubin
//2011-8-12  initial version
2
 
3
`include "defines.v"
4
 
5
module cavlc_tb;
6
 
7
//------------------------------------------------
8
// task : read inputs(nC, rbsp, max_coff_num)
9
//------------------------------------------------
10
reg     [0:1023]    rbsp_data;
11
reg     [7:0]  ch;
12
integer fp_r, fp_w;
13
integer rbsp_length;
14
integer rbsp_offset;
15
integer i;
16
reg     signed  [5:0]   nC_t;
17
reg     [4:0]   max_coeff_num_t;
18
task read_test_data;
19
//format
20
//AA BB CCC DDD.......
21
//AA:   nC
22
//BB:   max_coeff_num
23
//CCC:  length of D
24
//DD... rbsp bits 
25
    begin
26
        //nC_t
27
        ch  = $fgetc(fp_r);
28
        if (ch == 8'h2d)
29
        begin
30
            nC_t = -1;
31
            ch = $fgetc(fp_r);
32
            ch = $fgetc(fp_r);
33
        end
34
        else
35
        begin
36
            nC_t = ch - 8'h30;
37
            ch  = $fgetc(fp_r);
38
            if (ch != 8'h20)
39
            begin
40
                nC_t = nC_t * 10 + ch -8'h30;
41
            end
42
            ch = $fgetc(fp_r);
43
        end
44
 
45
        //max_coeff_num
46
        ch  = $fgetc(fp_r);
47
        max_coeff_num_t =  ch -8'h30;
48
 
49
        ch  = $fgetc(fp_r);
50
        if (ch != 8'h20)
51
        begin
52
            max_coeff_num_t = max_coeff_num_t * 10 + ch -8'h30;
53
        end
54
 
55
        ch  = $fgetc(fp_r);
56
 
57
        //rbsp_length
58
        ch  = $fgetc(fp_r);
59
        rbsp_length = ch -8'h30;
60
 
61
        ch  = $fgetc(fp_r);
62
        if (ch != 8'h20)
63
        begin
64
            rbsp_length = rbsp_length * 10 + ch -8'h30;
65
        end
66
 
67
        ch  = $fgetc(fp_r);
68
        if (ch != 8'h20)
69
        begin
70
            rbsp_length = rbsp_length * 10 + ch -8'h30;
71
        end
72
 
73
        ch  = $fgetc(fp_r);
74
 
75
        //rbsp
76
        rbsp_data = 0;
77
        for(i = 0; i < rbsp_length; i = i+1)
78
        begin
79
            ch  = $fgetc(fp_r);
80
            if (ch == 8'h30)
81
                rbsp_data[i] = 1'b0;
82
            else if (ch == 8'h31)
83
                rbsp_data[i] = 1'b1;
84
            else
85
                $display("rbsp error!\n");
86
        end
87
        ch  = $fgetc(fp_r);
88
    end
89
endtask
90
 
91
//-----------------------------------------------------------------------------
92
// dut
93
//-----------------------------------------------------------------------------
94
reg     clk;
95
reg             rst_n;
96
reg     ena;
97
reg     start;
98
reg     [0:15]  rbsp;
99
reg     signed  [5:0]   nC;
100
reg     [4:0]   max_coeff_num;
101
 
102
wire signed [8:0]   coeff_0;
103
wire signed [8:0]   coeff_1;
104
wire signed [8:0]   coeff_2;
105
wire signed [8:0]   coeff_3;
106
wire signed [8:0]   coeff_4;
107
wire signed [8:0]   coeff_5;
108
wire signed [8:0]   coeff_6;
109
wire signed [8:0]   coeff_7;
110
wire signed [8:0]   coeff_8;
111
wire signed [8:0]   coeff_9;
112
wire signed [8:0]   coeff_10;
113
wire signed [8:0]   coeff_11;
114
wire signed [8:0]   coeff_12;
115
wire signed [8:0]   coeff_13;
116
wire signed [8:0]   coeff_14;
117
wire signed [8:0]   coeff_15;
118
 
119
wire    [4:0]   TotalCoeff;
120
wire    [4:0]   len_comb;
121
wire    idle;
122
wire    valid;
123
 
124
cavlc_top dut(
125
    clk,
126
    rst_n,
127
    ena,
128
    start,
129
    rbsp,
130
    nC,
131
    max_coeff_num,
132
 
133
    coeff_0,
134
    coeff_1,
135
    coeff_2,
136
    coeff_3,
137
    coeff_4,
138
    coeff_5,
139
    coeff_6,
140
    coeff_7,
141
    coeff_8,
142
    coeff_9,
143
    coeff_10,
144
    coeff_11,
145
    coeff_12,
146
    coeff_13,
147
    coeff_14,
148
    coeff_15,
149
    TotalCoeff,
150
    len_comb,
151
    idle,
152
    valid
153
);
154
 
155
parameter
156
        Tp = 3,
157
        TestBlockNum = 1000;    //number of cavlc blocks to test
158
 
159
//-----------------------------------------------------------------------------
160
// clock and reset
161
//-----------------------------------------------------------------------------
162
initial
163
begin
164
        clk = 0;
165
        rst_n = 1;
166
        # 10 rst_n = 0;
167
        repeat(2) @(posedge clk);
168
        rst_n = #5 1;
169
end
170
 
171
initial
172
forever #10 clk = ~clk;
173
 
174
//-----------------------------------------------------------------------------
175
// generate module enable signal
176
//-----------------------------------------------------------------------------
177
always @(posedge clk or negedge rst_n)
178
if (!rst_n)
179
    ena  <= #Tp 0;
180
else
181
    ena  <= #Tp 1; // always 1, or use {$random} % 2;
182
 
183
//-----------------------------------------------------------------------------
184
// generate start signal
185
//-----------------------------------------------------------------------------
186
initial
187
begin
188
   start = 0;
189
   @(negedge rst_n);
190
   @(posedge rst_n);
191
   forever
192
   begin
193
      @(posedge clk);
194
      start = 1;
195
      @(posedge clk);
196
      start = #Tp 0;   //start must be high for one cycle
197
      @(posedge valid);
198
   end
199
end
200
 
201
//-----------------------------------------------------------------------------
202
// generate rbsp data and deal with forward_len
203
//-----------------------------------------------------------------------------
204
always @(*) rbsp <= # Tp rbsp_data[rbsp_offset +: 16];
205
 
206
always @(posedge clk or negedge rst_n)
207
if (!rst_n)
208
    rbsp_offset <=  0;
209
else if (!idle && ena)
210
    rbsp_offset <=  rbsp_offset + len_comb;
211
else if(ena)
212
    rbsp_offset <=  0;
213
 
214
 
215
//-----------------------------------------------------------------------------
216
// generate inputs(nC, max_coff_num) from 'in.txt' and display output to 'out.txt'
217
//-----------------------------------------------------------------------------
218
integer blk_num;
219
initial
220
begin
221
    fp_r = $fopen("in.txt", "r");
222
    fp_w = $fopen("out.txt", "w");
223
    if (fp_r == 0 || fp_w == 0)
224
    begin
225
        $display(" >> can not open 'in.txt' or 'out.txt'");
226
        $finish;
227
    end
228
    blk_num = 0;
229
    while(blk_num < TestBlockNum)
230
    begin
231
        if ($feof(fp_r) == 1)
232
        begin
233
                $fclose(fp_r);
234
                $fclose(fp_w);
235
                $display(" >> end of file @ %d", $time);
236
                $finish;
237
        end
238
        read_test_data;
239
        nC =  nC_t;
240
        max_coeff_num =  max_coeff_num_t;
241
        @(posedge valid);
242
        blk_num = blk_num + 1;
243
        @(posedge clk);
244
        $fdisplay(fp_w, "blk_num:%-5dnC:%-5dTotalCoeff:%-5d", blk_num, nC, TotalCoeff);
245
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_0, coeff_1, coeff_2, coeff_3);
246
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_4, coeff_5, coeff_6, coeff_7);
247
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_8, coeff_9, coeff_10, coeff_11);
248
        $fdisplay(fp_w, "%5d%5d%5d%5d\n", coeff_12, coeff_13, coeff_14, coeff_15);
249
    end
250
   $fclose(fp_r);
251
   $fclose(fp_w);
252
   $display(" >> done @ %d", $time);
253
   $display(" >> tested cavlc blocks : %d", blk_num);
254
   $finish;
255
end
256
 
257
 
258
endmodule

powered by: WebSVN 2.1.0

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