//2011-8-12 initial version
|
//2011-8-12 initial version
|
|
|
`include "defines.v"
|
`include "defines.v"
|
|
|
module cavlc_tb;
|
module cavlc_tb;
|
|
|
//------------------------------------------------
|
//------------------------------------------------
|
// task : read inputs(nC, rbsp, max_coff_num)
|
// task : read inputs(nC, rbsp, max_coff_num)
|
//------------------------------------------------
|
//------------------------------------------------
|
reg [0:1023] rbsp_data;
|
reg [0:1023] rbsp_data;
|
reg [7:0] ch;
|
reg [7:0] ch;
|
integer fp_r, fp_w;
|
integer fp_r, fp_w;
|
integer rbsp_length;
|
integer rbsp_length;
|
integer rbsp_offset;
|
integer rbsp_offset;
|
integer i;
|
integer i;
|
reg signed [5:0] nC_t;
|
reg signed [5:0] nC_t;
|
reg [4:0] max_coeff_num_t;
|
reg [4:0] max_coeff_num_t;
|
task read_test_data;
|
task read_test_data;
|
//format
|
//format
|
//AA BB CCC DDD.......
|
//AA BB CCC DDD.......
|
//AA: nC
|
//AA: nC
|
//BB: max_coeff_num
|
//BB: max_coeff_num
|
//CCC: length of D
|
//CCC: length of D
|
//DD... rbsp bits
|
//DD... rbsp bits
|
begin
|
begin
|
//nC_t
|
//nC_t
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch == 8'h2d)
|
if (ch == 8'h2d)
|
begin
|
begin
|
nC_t = -1;
|
nC_t = -1;
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
end
|
end
|
else
|
else
|
begin
|
begin
|
nC_t = ch - 8'h30;
|
nC_t = ch - 8'h30;
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch != 8'h20)
|
if (ch != 8'h20)
|
begin
|
begin
|
nC_t = nC_t * 10 + ch -8'h30;
|
nC_t = nC_t * 10 + ch -8'h30;
|
end
|
end
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
end
|
end
|
|
|
//max_coeff_num
|
//max_coeff_num
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
max_coeff_num_t = ch -8'h30;
|
max_coeff_num_t = ch -8'h30;
|
|
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch != 8'h20)
|
if (ch != 8'h20)
|
begin
|
begin
|
max_coeff_num_t = max_coeff_num_t * 10 + ch -8'h30;
|
max_coeff_num_t = max_coeff_num_t * 10 + ch -8'h30;
|
end
|
end
|
|
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
|
|
//rbsp_length
|
//rbsp_length
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
rbsp_length = ch -8'h30;
|
rbsp_length = ch -8'h30;
|
|
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch != 8'h20)
|
if (ch != 8'h20)
|
begin
|
begin
|
rbsp_length = rbsp_length * 10 + ch -8'h30;
|
rbsp_length = rbsp_length * 10 + ch -8'h30;
|
end
|
end
|
|
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch != 8'h20)
|
if (ch != 8'h20)
|
begin
|
begin
|
rbsp_length = rbsp_length * 10 + ch -8'h30;
|
rbsp_length = rbsp_length * 10 + ch -8'h30;
|
end
|
end
|
|
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
|
|
//rbsp
|
//rbsp
|
rbsp_data = 0;
|
rbsp_data = 0;
|
for(i = 0; i < rbsp_length; i = i+1)
|
for(i = 0; i < rbsp_length; i = i+1)
|
begin
|
begin
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
if (ch == 8'h30)
|
if (ch == 8'h30)
|
rbsp_data[i] = 1'b0;
|
rbsp_data[i] = 1'b0;
|
else if (ch == 8'h31)
|
else if (ch == 8'h31)
|
rbsp_data[i] = 1'b1;
|
rbsp_data[i] = 1'b1;
|
else
|
else
|
begin
|
begin
|
$fclose(fp_r);
|
$fclose(fp_r);
|
$fclose(fp_w);
|
$fclose(fp_w);
|
$display(" >> end of file @ %d", $time);
|
$display(" >> end of file @ %d", $time);
|
$display(" >> tested cavlc blocks : %d", blk_num);
|
$display(" >> tested cavlc blocks : %d", blk_num);
|
$finish;
|
$finish;
|
end
|
end
|
end
|
end
|
ch = $fgetc(fp_r);
|
ch = $fgetc(fp_r);
|
end
|
end
|
endtask
|
endtask
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// dut
|
// dut
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
reg clk;
|
reg clk;
|
reg rst_n;
|
reg rst_n;
|
reg ena;
|
reg ena;
|
reg start;
|
reg start;
|
reg [0:15] rbsp;
|
reg [0:15] rbsp;
|
reg signed [5:0] nC;
|
reg signed [5:0] nC;
|
reg [4:0] max_coeff_num;
|
reg [4:0] max_coeff_num;
|
|
|
wire signed [8:0] coeff_0;
|
wire signed [8:0] coeff_0;
|
wire signed [8:0] coeff_1;
|
wire signed [8:0] coeff_1;
|
wire signed [8:0] coeff_2;
|
wire signed [8:0] coeff_2;
|
wire signed [8:0] coeff_3;
|
wire signed [8:0] coeff_3;
|
wire signed [8:0] coeff_4;
|
wire signed [8:0] coeff_4;
|
wire signed [8:0] coeff_5;
|
wire signed [8:0] coeff_5;
|
wire signed [8:0] coeff_6;
|
wire signed [8:0] coeff_6;
|
wire signed [8:0] coeff_7;
|
wire signed [8:0] coeff_7;
|
wire signed [8:0] coeff_8;
|
wire signed [8:0] coeff_8;
|
wire signed [8:0] coeff_9;
|
wire signed [8:0] coeff_9;
|
wire signed [8:0] coeff_10;
|
wire signed [8:0] coeff_10;
|
wire signed [8:0] coeff_11;
|
wire signed [8:0] coeff_11;
|
wire signed [8:0] coeff_12;
|
wire signed [8:0] coeff_12;
|
wire signed [8:0] coeff_13;
|
wire signed [8:0] coeff_13;
|
wire signed [8:0] coeff_14;
|
wire signed [8:0] coeff_14;
|
wire signed [8:0] coeff_15;
|
wire signed [8:0] coeff_15;
|
|
|
wire [4:0] TotalCoeff;
|
wire [4:0] TotalCoeff;
|
wire [4:0] len_comb;
|
wire [4:0] len_comb;
|
wire idle;
|
wire idle;
|
wire valid;
|
wire valid;
|
|
|
cavlc_top dut(
|
cavlc_top dut(
|
clk,
|
clk,
|
rst_n,
|
rst_n,
|
ena,
|
ena,
|
start,
|
start,
|
rbsp,
|
rbsp,
|
nC,
|
nC,
|
max_coeff_num,
|
max_coeff_num,
|
|
|
coeff_0,
|
coeff_0,
|
coeff_1,
|
coeff_1,
|
coeff_2,
|
coeff_2,
|
coeff_3,
|
coeff_3,
|
coeff_4,
|
coeff_4,
|
coeff_5,
|
coeff_5,
|
coeff_6,
|
coeff_6,
|
coeff_7,
|
coeff_7,
|
coeff_8,
|
coeff_8,
|
coeff_9,
|
coeff_9,
|
coeff_10,
|
coeff_10,
|
coeff_11,
|
coeff_11,
|
coeff_12,
|
coeff_12,
|
coeff_13,
|
coeff_13,
|
coeff_14,
|
coeff_14,
|
coeff_15,
|
coeff_15,
|
TotalCoeff,
|
TotalCoeff,
|
len_comb,
|
len_comb,
|
idle,
|
idle,
|
valid
|
valid
|
);
|
);
|
|
|
parameter
|
parameter
|
Tp = 3,
|
Tp = 3,
|
TestBlockNum = 10000; //number of cavlc blocks to test
|
TestBlockNum = 10000; //number of cavlc blocks to test
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// clock and reset
|
// clock and reset
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
initial
|
initial
|
begin
|
begin
|
clk = 0;
|
clk = 0;
|
rst_n = 1;
|
rst_n = 1;
|
# 10 rst_n = 0;
|
# 10 rst_n = 0;
|
repeat(2) @(posedge clk);
|
repeat(2) @(posedge clk);
|
rst_n = #5 1;
|
rst_n = #5 1;
|
end
|
end
|
|
|
initial
|
initial
|
forever #10 clk = ~clk;
|
forever #10 clk = ~clk;
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// generate module enable signal
|
// generate module enable signal
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
always @(posedge clk or negedge rst_n)
|
always @(posedge clk or negedge rst_n)
|
if (!rst_n)
|
if (!rst_n)
|
ena <= #Tp 0;
|
ena <= #Tp 0;
|
else
|
else
|
ena <= #Tp 1; // always 1, or use {$random} % 2;
|
ena <= #Tp 1; // always 1, or use {$random} % 2;
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// generate start signal
|
// generate start signal
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
initial
|
initial
|
begin
|
begin
|
start = 0;
|
start = 0;
|
@(negedge rst_n);
|
@(negedge rst_n);
|
@(posedge rst_n);
|
@(posedge rst_n);
|
forever
|
forever
|
begin
|
begin
|
@(posedge clk);
|
@(posedge clk);
|
start = 1;
|
start = #Tp 1;
|
@(posedge clk);
|
@(posedge clk);
|
start = #Tp 0; //start must be high for one cycle
|
start = #Tp 0; //start must be high for one cycle
|
@(posedge valid);
|
@(posedge valid);
|
end
|
end
|
end
|
end
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// generate rbsp data and deal with forward_len
|
// generate rbsp data and deal with forward_len
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
always @(*) rbsp <= # Tp rbsp_data[rbsp_offset +: 16];
|
always @(*) rbsp <= # Tp rbsp_data[rbsp_offset +: 16];
|
|
|
always @(posedge clk or negedge rst_n)
|
always @(posedge clk or negedge rst_n)
|
if (!rst_n)
|
if (!rst_n)
|
rbsp_offset <= 0;
|
rbsp_offset <= 0;
|
else if (!idle && ena)
|
else if (!idle && ena)
|
rbsp_offset <= rbsp_offset + len_comb;
|
rbsp_offset <= rbsp_offset + len_comb;
|
else if(ena)
|
else if(ena)
|
rbsp_offset <= 0;
|
rbsp_offset <= 0;
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
// generate inputs(nC, max_coff_num) from 'in.txt' and display output to 'out.txt'
|
// generate inputs(nC, max_coff_num) from 'in.txt' and display output to 'out.txt'
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
integer blk_num;
|
integer blk_num;
|
initial
|
initial
|
begin
|
begin
|
fp_r = $fopen("in.txt", "r");
|
fp_r = $fopen("in.txt", "r");
|
fp_w = $fopen("out.txt", "w");
|
fp_w = $fopen("out.txt", "w");
|
if (fp_r == 0 || fp_w == 0)
|
if (fp_r == 0 || fp_w == 0)
|
begin
|
begin
|
$display(" >> can not open 'in.txt' or 'out.txt'");
|
$display(" >> can not open 'in.txt' or 'out.txt'");
|
$finish;
|
$finish;
|
end
|
end
|
blk_num = 0;
|
blk_num = 0;
|
while(blk_num < TestBlockNum)
|
while(blk_num < TestBlockNum)
|
begin
|
begin
|
read_test_data;
|
read_test_data;
|
nC = nC_t;
|
nC = nC_t;
|
max_coeff_num = max_coeff_num_t;
|
max_coeff_num = max_coeff_num_t;
|
@(posedge valid);
|
@(posedge valid);
|
blk_num = blk_num + 1;
|
blk_num = blk_num + 1;
|
@(posedge clk);
|
@(posedge clk);
|
$fdisplay(fp_w, "blk_num:%-5dnC:%-5dTotalCoeff:%-5d", blk_num, nC, TotalCoeff);
|
$fdisplay(fp_w, "blk_num:%-5dnC:%-5dTotalCoeff:%-5d", blk_num, nC, TotalCoeff);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_0, coeff_1, coeff_2, coeff_3);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_0, coeff_1, coeff_2, coeff_3);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_4, coeff_5, coeff_6, coeff_7);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_4, coeff_5, coeff_6, coeff_7);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_8, coeff_9, coeff_10, coeff_11);
|
$fdisplay(fp_w, "%5d%5d%5d%5d", coeff_8, coeff_9, coeff_10, coeff_11);
|
$fdisplay(fp_w, "%5d%5d%5d%5d\n", coeff_12, coeff_13, coeff_14, coeff_15);
|
$fdisplay(fp_w, "%5d%5d%5d%5d\n", coeff_12, coeff_13, coeff_14, coeff_15);
|
end
|
end
|
$fclose(fp_r);
|
$fclose(fp_r);
|
$fclose(fp_w);
|
$fclose(fp_w);
|
$display(" >> done @ %d", $time);
|
$display(" >> done @ %d", $time);
|
$display(" >> tested cavlc blocks : %d", blk_num);
|
$display(" >> tested cavlc blocks : %d", blk_num);
|
$finish;
|
$finish;
|
end
|
end
|
|
|
|
|
endmodule
|
endmodule
|
|
|