RGB Resampler IP核的测试

时间:2023-12-28 16:54:23

关于RGB Resampler IP核的测试

1.RGB Resampler功能描述

将输入的RGB数据流转换成其它格式的RGB数据流。

RGB Resampler IP核的测试

RGB Resampler IP核的测试

2.功能验证

设置源图像像素数据为:3X4格式。

RGB Resampler IP核的测试

设置RGB Resampler参数如下图所示,将24-bit RGB格式转换为40-bit RGBA格式。

RGB Resampler IP核的测试

顶层文件的编写:

 module top(
clk_clk,
reset_reset_n,
video_rgb_resampler_avalon_rgb_source_ready,
video_rgb_resampler_avalon_rgb_source_startofpacket,
video_rgb_resampler_avalon_rgb_source_endofpacket,
video_rgb_resampler_avalon_rgb_source_valid,
video_rgb_resampler_avalon_rgb_source_data,
); input clk_clk;
input reset_reset_n;
input video_rgb_resampler_avalon_rgb_source_ready;
output video_rgb_resampler_avalon_rgb_source_startofpacket;
output video_rgb_resampler_avalon_rgb_source_endofpacket;
output video_rgb_resampler_avalon_rgb_source_valid;
output [:]video_rgb_resampler_avalon_rgb_source_data; RGB_format u1 (
.clk_clk (clk_clk),
.reset_reset_n (reset_reset_n),
.video_rgb_resampler_avalon_rgb_source_ready (video_rgb_resampler_avalon_rgb_source_ready),
.video_rgb_resampler_avalon_rgb_source_startofpacket (video_rgb_resampler_avalon_rgb_source_startofpacket),
.video_rgb_resampler_avalon_rgb_source_endofpacket (video_rgb_resampler_avalon_rgb_source_endofpacket),
.video_rgb_resampler_avalon_rgb_source_valid (video_rgb_resampler_avalon_rgb_source_valid),
.video_rgb_resampler_avalon_rgb_source_data (video_rgb_resampler_avalon_rgb_source_data)
); endmodule 

Testbench的编写:

initial
begin
reset_reset_n = ; #; reset_reset_n = ;
clk_clk = ; forever # clk_clk = ~clk_clk;
end always@(posedge clk_clk or negedge reset_reset_n)
if(!reset_reset_n)
video_rgb_resampler_avalon_rgb_source_ready = 'b0;
else
video_rgb_resampler_avalon_rgb_source_ready = 'b1;

ModelSIM仿真波形:

RGB Resampler IP核的测试

波形分析: 输出source_data为40-bit,在start---end之间输出12个数据。

3.将224X224 24-bit RGB图像转换为40-bit RGBA 图像

参数配置:

RGB Resampler IP核的测试

modelsim仿真并导出modelsim中生成的图像像素数据:

RGB Resampler IP核的测试

integer w_file;
initial w_file = $fopen("video_rgb_resampler_avalon_rgb_source_data.txt");
always@(posedge clk_clk)
$fdisplay(w_file, "%d", video_rgb_resampler_avalon_rgb_source_data); 

RGB Resampler IP核的测试

40-bit RGBA数据格式:

RGB Resampler IP核的测试

在Matlab中进行数据处理:

fd = fopen('video_rgb_resampler_avalon_rgb_source_data.txt');
A =uint64(fscanf(fd,'%f'));
fclose(fd);
B = uint64(zeros(224,224)); A1 = uint64(zeros(50176,1));
A2 = uint64(zeros(50176,1));
A3 = uint64(zeros(224,224)); R1 = uint64(zeros(50176,1));
R2 = uint64(zeros(50176,1));
R3 = uint64(zeros(224,224)); G1 = uint64(zeros(50176,1));
G2 = uint64(zeros(50176,1));
G3 = uint64(zeros(224,224)); B1 = uint64(zeros(50176,1));
B2 = uint64(zeros(224,224)); for j = 1:224
for i = 1:224
B(j,i) = A((j-1)*224+i);
end
end % A---1111 1111 11 --- 0000 0000 00 --- 0000 0000 00 --- 0000 0000 00
% R---0000 0000 00 --- 1111 1111 11 --- 0000 0000 00 --- 0000 0000 00
% G---0000 0000 00 --- 0000 0000 00 --- 1111 1111 11 --- 0000 0000 00
% B---0000 0000 00 --- 0000 0000 00 --- 0000 0000 00 --- 1111 1111 11 a = uint64(bin2dec('1111111111000000000000000000000000000000'));
r = uint64(bin2dec('0000000000111111111100000000000000000000'));
g = uint64(bin2dec('0000000000000000000011111111110000000000'));
b = uint64(bin2dec('0000000000000000000000000000001111111111')); %---A
for i = 1:50176
A1(i) = bitand(A(i),a);
end for i = 1:50176
A2(i) = bitshift(A1(i),-30);
end for j = 1:224
for i = 1:224
A3(j,i) = A2((j-1)*224+i);
end
end %---R
for i = 1:50176
R1(i) = bitand(A(i),r);
end for i = 1:50176
R2(i) = bitshift(R1(i),-20);
end for j = 1:224
for i = 1:224
R3(j,i) = R2((j-1)*224+i);
end
end %---G
for i = 1:50176
G1(i) = bitand(A(i),g);
end for i = 1:50176
G2(i) = bitshift(G1(i),-10);
end for j = 1:224
for i = 1:224
G3(j,i) = G2((j-1)*224+i);
end
end %---B
for i = 1:50176
B1(i) = bitand(A(i),b);
end for j = 1:224
for i = 1:224
B2(j,i) = B1((j-1)*224+i);
end
end

需要注意的问题:

源文件中的数据值比较大,如果以十进制的方式读入数据,会出现如下问题:

RGB Resampler IP核的测试

RGB Resampler IP核的测试

如果以16进制的形式读入,则不会出现此问题:

RGB Resampler IP核的测试

RGB Resampler IP核的测试