isp pipeline pass sim

This commit is contained in:
2024-10-03 17:06:40 +08:00
parent 35e6ab1e85
commit c807c24456
13 changed files with 5924 additions and 556 deletions

View File

@@ -1,7 +1,7 @@
`timescale 1ns / 1ps
// 三通道图像合成一个RGB图像
module ColorBlender #(
module ColorBlender_Pipeline #(
parameter reg [4:0] IN_DEPTH = 12, // 输入图像的色深
parameter reg [4:0] OUT_DEPTH = 8 // 输出图像的色深
) (

View File

@@ -1,5 +1,5 @@
`timescale 1ns / 1ps
module Crop #(
module Crop_Pipeline #(
parameter IN_WIDTH = 512,
parameter IN_HEIGHT = 512,
parameter OFFSET_X = 120,

View File

@@ -4,7 +4,7 @@ module Demosaic2 #(
parameter reg [15:0] IM_HEIGHT = 256, // 图像高度
parameter reg [ 1:0] RAW_TYPE = 3, // 0:grbg 1:rggb 2:bggr 3:gbrg
parameter reg [ 4:0] DATA_SIZE = 16
) (
) (
// 基本信号
input wire clk,
input wire reset,
@@ -22,7 +22,7 @@ module Demosaic2 #(
output reg [DATA_SIZE - 1:0] out_r,
output reg [DATA_SIZE - 1:0] out_g,
output reg [DATA_SIZE - 1:0] out_b
);
);
// 常量,包括状态机
@@ -42,20 +42,29 @@ module Demosaic2 #(
// 三段状态机实现,窗口滑动,颜色计算
// 状态切换
always @(posedge clk) begin
if (reset) state <= READ_DATA;
else state <= nextState;
always @(posedge clk)
begin
if (reset)
state <= READ_DATA;
else
state <= nextState;
end
// 下一状态更新
always @(*) begin
always @(*)
begin
case (state)
// 记录够3x3个数据后进行rgb转换
READ_DATA: nextState = (cnt_data >= 3) ? COLOR_GEN : READ_DATA;
COLOR_GEN: nextState = SEND_DATA;
SEND_DATA: nextState = (in_receive) ? SLIDE_WINDOW : SEND_DATA;
SLIDE_WINDOW: nextState = READ_DATA;
default: nextState = READ_DATA;
READ_DATA:
nextState = (cnt_data >= 3) ? COLOR_GEN : READ_DATA;
COLOR_GEN:
nextState = SEND_DATA;
SEND_DATA:
nextState = (in_receive) ? SLIDE_WINDOW : SEND_DATA;
SLIDE_WINDOW:
nextState = READ_DATA;
default:
nextState = READ_DATA;
endcase
end
@@ -65,8 +74,10 @@ module Demosaic2 #(
assign out_receive = (in_en && state == READ_DATA && !reset) ? 1 : 0;
// 各状态执行的操作
always @(posedge clk) begin
if (reset) begin
always @(posedge clk)
begin
if (reset)
begin
// 外部输出初始化
out_en <= 0;
out_r <= 0;
@@ -78,12 +89,16 @@ module Demosaic2 #(
pos_y <= 0;
cnt_data <= 0;
raw_type <= RAW_TYPE;
end else begin
end
else
begin
// 状态机执行
case (state)
// 读取数据
READ_DATA: begin
if (in_en) begin
READ_DATA:
begin
if (in_en)
begin
data_cache[0 + cnt_data * 3] <= in_data[0];
data_cache[1 + cnt_data * 3] <= in_data[1];
data_cache[2 + cnt_data * 3] <= in_data[2];
@@ -92,80 +107,107 @@ module Demosaic2 #(
end
end
COLOR_GEN: begin
COLOR_GEN:
begin
// 生成rgb图像
// data case 0 case 1 case 2 case 3
// 0 3 6 G R G R G R B G B G B G
// 1 4 7 B G B G B G G R G R G R
// 2 5 8 G R G R G R B G B G B G
case (raw_type)
0: begin // Missing B, R on G
0:
begin // Missing B, R on G
blue <= (data_cache[1] + data_cache[7]) >> 1;
red <= (data_cache[3] + data_cache[5]) >> 1;
green <= data_cache[4];
end
1: begin // Missing G, R on B
1:
begin // Missing G, R on B
green <= (data_cache[1] + data_cache[3] + data_cache[5] + data_cache[7]) >> 2;
red <= (data_cache[0] + data_cache[2] + data_cache[6] + data_cache[8]) >> 2;
blue <= data_cache[4];
end
2: begin // Missing G, B on R
2:
begin // Missing G, B on R
green <= (data_cache[1] + data_cache[3] + data_cache[5] + data_cache[7]) >> 2;
blue <= (data_cache[0] + data_cache[2] + data_cache[6] + data_cache[8]) >> 2;
red <= data_cache[4];
end
3: begin // Missing B, R on G
3:
begin // Missing B, R on G
red <= (data_cache[1] + data_cache[7]) >> 1;
blue <= (data_cache[3] + data_cache[5]) >> 1;
green <= data_cache[4];
end
default: ;
default:
;
endcase
case (raw_type)
0: raw_type <= 1;
1: raw_type <= 0;
2: raw_type <= 3;
3: raw_type <= 2;
0:
raw_type <= 1;
1:
raw_type <= 0;
2:
raw_type <= 3;
3:
raw_type <= 2;
endcase
end
SEND_DATA: begin
if (in_ready && !in_receive) begin
SEND_DATA:
begin
if (in_ready && !in_receive)
begin
out_en <= 1;
out_r <= red;
out_b <= blue;
out_g <= green;
end else out_en <= 0;
pos_x <= pos_x + 1;
end
else
out_en <= 0;
end
SLIDE_WINDOW: begin
SLIDE_WINDOW:
begin
// 记录位置寄存器自增,并处理缓存数据
pos_x <= pos_x + 1;
if (pos_x >= IM_WIDTH - 2 - 1) begin
if (pos_x >= IM_WIDTH - 2)
begin
cnt_data <= 0;
pos_x <= 0;
pos_y <= pos_y + 1;
if (pos_y >= IM_HEIGHT - 2 - 1) begin
if (pos_y >= IM_HEIGHT - 2)
begin
pos_y <= 0;
end
// 换行后切换Bayer格式
if (pos_y % 2 == 1) begin
if (pos_y % 2 == 1)
begin
raw_type <= RAW_TYPE;
end else begin
end
else
begin
case (RAW_TYPE)
0: raw_type <= 2;
1: raw_type <= 3;
2: raw_type <= 0;
3: raw_type <= 1;
default: ;
0:
raw_type <= 2;
1:
raw_type <= 3;
2:
raw_type <= 0;
3:
raw_type <= 1;
default:
;
endcase
end
end else begin
end
else
begin
cnt_data <= 2;
// 窗口右移
@@ -178,7 +220,8 @@ module Demosaic2 #(
end
end
default: ;
default:
;
endcase
end
end

View File

@@ -1,5 +1,5 @@
`timescale 1ns / 1ps
module Demosaic #(
module Demosaic_Pipeline #(
parameter WINDOW_LENGTH = 3,
parameter reg [15:0] TOTAL_WIDTH = 512+3, // 总图像宽度
parameter reg [15:0] TOTAL_HEIGHT = 256+3, // 总图像高度

View File

@@ -1,6 +1,6 @@
`timescale 1ns / 1ps
module isp #(
module isp_Pipeline #(
parameter reg [15:0] IN_WIDTH = 1936,
parameter reg [15:0] IN_HEIGHT = 1088,
parameter OFFSET_X = 7,
@@ -59,7 +59,7 @@ module isp #(
);
Demosaic #(
Demosaic_Pipeline #(
.WINDOW_LENGTH(3),
.TOTAL_WIDTH (IN_WIDTH),
.TOTAL_HEIGHT (IN_HEIGHT),
@@ -78,7 +78,7 @@ module isp #(
.out_fsync(Demosaic2_fsync)
);
ColorBlender #(
ColorBlender_Pipeline #(
.IN_DEPTH(12), // 输入图像的色深
.OUT_DEPTH(COLOR_DEPTH) // 输出图像的色深
) ColorBlender_inst (
@@ -101,7 +101,7 @@ module isp #(
.enable (blender_enable)
);
Crop #(
Crop_Pipeline #(
.IN_WIDTH (IN_WIDTH),
.IN_HEIGHT (IN_HEIGHT),
.OFFSET_X (OFFSET_X),