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

Subversion Repositories cavlc

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

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 8 qiubin
            else
85
            begin
86
                        $fclose(fp_r);
87
                        $fclose(fp_w);
88
                        $display(" >> end of file @ %d", $time);
89
                        $display(" >> tested cavlc blocks : %d", blk_num);
90
                        $finish;
91
            end
92 7 qiubin
        end
93
        ch  = $fgetc(fp_r);
94
    end
95
endtask
96
 
97
//-----------------------------------------------------------------------------
98
// dut
99
//-----------------------------------------------------------------------------
100
reg     clk;
101
reg             rst_n;
102
reg     ena;
103
reg     start;
104
reg     [0:15]  rbsp;
105
reg     signed  [5:0]   nC;
106
reg     [4:0]   max_coeff_num;
107
 
108
wire signed [8:0]   coeff_0;
109
wire signed [8:0]   coeff_1;
110
wire signed [8:0]   coeff_2;
111
wire signed [8:0]   coeff_3;
112
wire signed [8:0]   coeff_4;
113
wire signed [8:0]   coeff_5;
114
wire signed [8:0]   coeff_6;
115
wire signed [8:0]   coeff_7;
116
wire signed [8:0]   coeff_8;
117
wire signed [8:0]   coeff_9;
118
wire signed [8:0]   coeff_10;
119
wire signed [8:0]   coeff_11;
120
wire signed [8:0]   coeff_12;
121
wire signed [8:0]   coeff_13;
122
wire signed [8:0]   coeff_14;
123
wire signed [8:0]   coeff_15;
124
 
125
wire    [4:0]   TotalCoeff;
126
wire    [4:0]   len_comb;
127
wire    idle;
128
wire    valid;
129
 
130
cavlc_top dut(
131
    clk,
132
    rst_n,
133
    ena,
134
    start,
135
    rbsp,
136
    nC,
137
    max_coeff_num,
138
 
139
    coeff_0,
140
    coeff_1,
141
    coeff_2,
142
    coeff_3,
143
    coeff_4,
144
    coeff_5,
145
    coeff_6,
146
    coeff_7,
147
    coeff_8,
148
    coeff_9,
149
    coeff_10,
150
    coeff_11,
151
    coeff_12,
152
    coeff_13,
153
    coeff_14,
154
    coeff_15,
155
    TotalCoeff,
156
    len_comb,
157
    idle,
158
    valid
159
);
160
 
161
parameter
162
        Tp = 3,
163 8 qiubin
        TestBlockNum = 10000;   //number of cavlc blocks to test
164 7 qiubin
 
165
//-----------------------------------------------------------------------------
166
// clock and reset
167
//-----------------------------------------------------------------------------
168
initial
169
begin
170
        clk = 0;
171
        rst_n = 1;
172
        # 10 rst_n = 0;
173
        repeat(2) @(posedge clk);
174
        rst_n = #5 1;
175
end
176
 
177
initial
178
forever #10 clk = ~clk;
179
 
180
//-----------------------------------------------------------------------------
181
// generate module enable signal
182
//-----------------------------------------------------------------------------
183
always @(posedge clk or negedge rst_n)
184
if (!rst_n)
185
    ena  <= #Tp 0;
186
else
187
    ena  <= #Tp 1; // always 1, or use {$random} % 2;
188
 
189
//-----------------------------------------------------------------------------
190
// generate start signal
191
//-----------------------------------------------------------------------------
192
initial
193
begin
194
   start = 0;
195
   @(negedge rst_n);
196
   @(posedge rst_n);
197
   forever
198
   begin
199
      @(posedge clk);
200 9 qiubin
      start = #Tp 1;
201 7 qiubin
      @(posedge clk);
202
      start = #Tp 0;   //start must be high for one cycle
203
      @(posedge valid);
204
   end
205
end
206
 
207
//-----------------------------------------------------------------------------
208
// generate rbsp data and deal with forward_len
209
//-----------------------------------------------------------------------------
210
always @(*) rbsp <= # Tp rbsp_data[rbsp_offset +: 16];
211
 
212
always @(posedge clk or negedge rst_n)
213
if (!rst_n)
214
    rbsp_offset <=  0;
215
else if (!idle && ena)
216
    rbsp_offset <=  rbsp_offset + len_comb;
217
else if(ena)
218
    rbsp_offset <=  0;
219
 
220
 
221
//-----------------------------------------------------------------------------
222
// generate inputs(nC, max_coff_num) from 'in.txt' and display output to 'out.txt'
223
//-----------------------------------------------------------------------------
224
integer blk_num;
225
initial
226
begin
227
    fp_r = $fopen("in.txt", "r");
228
    fp_w = $fopen("out.txt", "w");
229
    if (fp_r == 0 || fp_w == 0)
230
    begin
231
        $display(" >> can not open 'in.txt' or 'out.txt'");
232
        $finish;
233
    end
234
    blk_num = 0;
235
    while(blk_num < TestBlockNum)
236
    begin
237
        read_test_data;
238
        nC =  nC_t;
239
        max_coeff_num =  max_coeff_num_t;
240
        @(posedge valid);
241
        blk_num = blk_num + 1;
242
        @(posedge clk);
243
        $fdisplay(fp_w, "blk_num:%-5dnC:%-5dTotalCoeff:%-5d", blk_num, nC, TotalCoeff);
244
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_0, coeff_1, coeff_2, coeff_3);
245
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_4, coeff_5, coeff_6, coeff_7);
246
        $fdisplay(fp_w, "%5d%5d%5d%5d", coeff_8, coeff_9, coeff_10, coeff_11);
247
        $fdisplay(fp_w, "%5d%5d%5d%5d\n", coeff_12, coeff_13, coeff_14, coeff_15);
248
    end
249
   $fclose(fp_r);
250
   $fclose(fp_w);
251
   $display(" >> done @ %d", $time);
252
   $display(" >> tested cavlc blocks : %d", blk_num);
253
   $finish;
254
end
255
 
256
 
257
endmodule

powered by: WebSVN 2.1.0

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