2024-10-22 20:31:51 +08:00
|
|
|
|
/* TODO 1. ISP寄存器配置模式,如配置是否启用什么什么矫正,矫正系数多少。能读能写。选好通信协议,要不要用AXI?
|
|
|
|
|
2. 白平衡,GAMMA矫正。白平衡做RAW白平衡吗?
|
|
|
|
|
3. 寄存器中应该有一个寄存器标识ISP运行状态。比如裁切模块,直接修改寄存器值数据就乱了。
|
|
|
|
|
4. 缩放模块。如何处理模块进出数据量不匹配?
|
|
|
|
|
5. 旋转模块。这怎么做?
|
|
|
|
|
6. ISP不应该只有一条线,比如存进SDRAM后,读出来时也可以做处理。
|
|
|
|
|
*/
|
2024-10-03 17:06:40 +08:00
|
|
|
|
module isp_Pipeline #(
|
2024-11-03 20:38:29 +08:00
|
|
|
|
`ifdef DEBUG
|
|
|
|
|
parameter reg [15:0] DATA_WIDTH = 16,
|
|
|
|
|
parameter reg [15:0] IN_WIDTH = 120,
|
|
|
|
|
parameter reg [15:0] IN_HEIGHT = 120,
|
|
|
|
|
parameter reg [15:0] OUT_WIDTH = 100,
|
|
|
|
|
parameter reg [15:0] OUT_HEIGHT = 100,
|
|
|
|
|
`else
|
2024-10-22 20:31:51 +08:00
|
|
|
|
parameter reg [15:0] DATA_WIDTH = 12,
|
2024-10-03 15:13:24 +08:00
|
|
|
|
parameter reg [15:0] IN_WIDTH = 1936,
|
|
|
|
|
parameter reg [15:0] IN_HEIGHT = 1088,
|
|
|
|
|
parameter reg [15:0] OUT_WIDTH = 1920,
|
|
|
|
|
parameter reg [15:0] OUT_HEIGHT = 1080,
|
2024-11-03 20:38:29 +08:00
|
|
|
|
`endif
|
|
|
|
|
parameter OFFSET_X = 7,
|
|
|
|
|
parameter OFFSET_Y = 3,
|
2024-10-03 15:13:24 +08:00
|
|
|
|
parameter reg [ 4:0] COLOR_DEPTH = 8, // Can't Change!!!
|
2024-11-03 20:38:29 +08:00
|
|
|
|
parameter reg [ 1:0] RAW_TYPE = 0 // 0:grbg 1:rggb 2:bggr 3:gbrg
|
2024-10-03 15:13:24 +08:00
|
|
|
|
) (
|
|
|
|
|
// 基本信号
|
2024-11-03 20:38:29 +08:00
|
|
|
|
input wire camera_clk,
|
|
|
|
|
input wire isp_clk,
|
2024-10-03 15:13:24 +08:00
|
|
|
|
input wire reset,
|
|
|
|
|
|
2024-11-03 20:38:29 +08:00
|
|
|
|
input wire in_valid,
|
2024-10-22 20:31:51 +08:00
|
|
|
|
input wire [DATA_WIDTH-1:0] in_data, // 数据输入线
|
2024-11-03 20:38:29 +08:00
|
|
|
|
input wire in_fsync, // 帧同步,在两帧间隔间拉高,标志着一帧的结束和新帧的开始
|
|
|
|
|
input wire in_hsync, // 行同步,在一行内持续拉高,一行结束后拉低。
|
2024-10-03 15:13:24 +08:00
|
|
|
|
|
|
|
|
|
output wire out_valid,
|
2024-11-03 20:38:29 +08:00
|
|
|
|
output wire [3 * COLOR_DEPTH - 1:0] out_data, // 数据输出线
|
|
|
|
|
output wire [7:0] out_user, //自定义数据线. [0]是hstart标志位, [1]是fstart标志位
|
2024-10-03 15:13:24 +08:00
|
|
|
|
|
2024-11-03 20:38:29 +08:00
|
|
|
|
// 准备信号 暂时没用
|
2024-10-03 15:13:24 +08:00
|
|
|
|
input wire in_ready,
|
|
|
|
|
output wire out_ready,
|
|
|
|
|
|
|
|
|
|
// 颜色校正,低八位为小数位,高八位为整数位
|
|
|
|
|
input wire [15:0] gain_red,
|
|
|
|
|
input wire [15:0] gain_green,
|
|
|
|
|
input wire [15:0] gain_blue,
|
2024-11-03 20:38:29 +08:00
|
|
|
|
input wire blender_enable, // 是否启用颜色校正
|
|
|
|
|
|
|
|
|
|
output wire fifo_isp_adapter_h_pixel_correct,
|
|
|
|
|
output wire fifo_isp_adapter_v_pixel_correct
|
2024-10-03 15:13:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
wire [DATA_WIDTH-1:0] DPC_data;
|
2024-11-03 20:38:29 +08:00
|
|
|
|
wire [DATA_WIDTH-1:0] adapter_data;
|
|
|
|
|
wire [7:0] Windows_DPC_user, DPC_user, Windows_Demosaic_user, adapter_user, Demosaic_user, Blender_user, Crop_user;
|
2024-10-22 20:31:51 +08:00
|
|
|
|
wire [DATA_WIDTH-1:0] Demosaic_data[3];
|
|
|
|
|
wire [DATA_WIDTH-1:0] Windows_DPC_data[5*5];
|
|
|
|
|
wire [DATA_WIDTH-1:0] Windows_Demosaic_data[3*3];
|
2024-10-03 15:13:24 +08:00
|
|
|
|
wire [COLOR_DEPTH - 1 : 0] Blender_data[3];
|
|
|
|
|
wire [COLOR_DEPTH - 1 : 0] Crop_data[3];
|
2024-11-03 20:38:29 +08:00
|
|
|
|
wire adapter_valid, Windows_DPC_valid, DPC_valid, Windows_Demosaic_valid, Demosaic_valid, Blender_valid, Crop_valid;
|
2024-10-22 20:31:51 +08:00
|
|
|
|
wire Windows_DPC_ready, DPC_ready, Windows_Demosaic_ready, Demosaic_ready, Blender_ready, Crop_ready;
|
2024-10-03 15:13:24 +08:00
|
|
|
|
assign out_valid = Crop_valid;
|
2024-10-22 20:31:51 +08:00
|
|
|
|
assign out_ready = Windows_DPC_ready;
|
2024-11-03 20:38:29 +08:00
|
|
|
|
assign out_data = {Crop_data[2], Crop_data[1], Crop_data[0]};
|
|
|
|
|
assign out_user = Crop_user;
|
|
|
|
|
|
|
|
|
|
fifo_isp_adapter #(
|
|
|
|
|
.DATA_WIDTH(DATA_WIDTH)
|
|
|
|
|
) fifo_isp_adapter_u (
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.camera_clk(camera_clk),
|
|
|
|
|
.in_valid(in_valid),
|
|
|
|
|
.in_data(in_data),
|
|
|
|
|
.in_fsync(in_fsync),
|
|
|
|
|
.in_hsync(in_hsync),
|
|
|
|
|
|
|
|
|
|
.isp_clk (isp_clk),
|
|
|
|
|
.out_valid(adapter_valid),
|
|
|
|
|
.out_data (adapter_data),
|
|
|
|
|
.out_user (adapter_user)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
frame_size_detect u_frame_size_detect (
|
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset (reset),
|
|
|
|
|
.in_valid (adapter_valid),
|
|
|
|
|
.hstart (adapter_user[0]),
|
|
|
|
|
.fstart (adapter_user[1]),
|
|
|
|
|
.h_pixel (IN_WIDTH),
|
|
|
|
|
.v_pixel (IN_HEIGHT),
|
|
|
|
|
.h_pixel_correct(fifo_isp_adapter_h_pixel_correct),
|
|
|
|
|
.v_pixel_correct(fifo_isp_adapter_v_pixel_correct)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// wire [7:0] wr_data, wr_addr;
|
|
|
|
|
// wire wr_enable;
|
|
|
|
|
// wire [8*16-1:0] isp_vector;
|
|
|
|
|
// isp_register_ctrl isp_register_ctrl(
|
|
|
|
|
// .clk (isp_clk),
|
|
|
|
|
// .reset (reset),
|
|
|
|
|
|
|
|
|
|
// .wr_data (wr_data),
|
|
|
|
|
// .wr_enable(wr_enable),
|
|
|
|
|
// .wr_addr (wr_addr),
|
|
|
|
|
|
|
|
|
|
// .vector (isp_vector)
|
|
|
|
|
// )
|
2024-10-03 15:13:24 +08:00
|
|
|
|
|
|
|
|
|
Windows #(
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.DATA_WIDTH (DATA_WIDTH),
|
|
|
|
|
.WINDOWS_WIDTH (5),
|
|
|
|
|
.WINDOWS_ANCHOR_X(2),
|
|
|
|
|
.WINDOWS_ANCHOR_Y(2)
|
|
|
|
|
) Windows_DPC_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(adapter_valid),
|
|
|
|
|
.in_data (adapter_data),
|
|
|
|
|
.in_user (adapter_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.out_valid(Windows_DPC_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (Windows_DPC_data),
|
|
|
|
|
.out_user (Windows_DPC_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.in_ready (DPC_ready),
|
|
|
|
|
.out_ready(Windows_DPC_ready)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
DPC #(
|
2024-10-25 23:12:57 +08:00
|
|
|
|
.RAW_TYPE (3),
|
|
|
|
|
.DATA_WIDTH (DATA_WIDTH),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.THRESHOLD (50),
|
2024-10-25 23:12:57 +08:00
|
|
|
|
.MODULE_ENABLE(1),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.LABLE_ENABLE (0)
|
2024-10-22 20:31:51 +08:00
|
|
|
|
) DPC_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(Windows_DPC_valid),
|
|
|
|
|
.in_data (Windows_DPC_data),
|
|
|
|
|
.in_user (Windows_DPC_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.out_valid(DPC_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (DPC_data),
|
|
|
|
|
.out_user (DPC_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.in_ready (Windows_Demosaic_ready),
|
|
|
|
|
.out_ready(DPC_ready)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Windows #(
|
|
|
|
|
.DATA_WIDTH (DATA_WIDTH),
|
|
|
|
|
.WINDOWS_WIDTH (3),
|
|
|
|
|
.WINDOWS_ANCHOR_X(1),
|
|
|
|
|
.WINDOWS_ANCHOR_Y(1)
|
|
|
|
|
) Windows_Demosaic_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(DPC_valid),
|
|
|
|
|
.in_data (DPC_data),
|
|
|
|
|
.in_user (DPC_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.out_valid(Windows_Demosaic_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (Windows_Demosaic_data),
|
|
|
|
|
.out_user (Windows_Demosaic_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.in_ready (Demosaic_ready),
|
|
|
|
|
.out_ready(Windows_Demosaic_ready)
|
2024-10-03 15:13:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2024-11-03 20:38:29 +08:00
|
|
|
|
// Windows #(
|
|
|
|
|
// .DATA_WIDTH (DATA_WIDTH),
|
|
|
|
|
// .WINDOWS_WIDTH (3 ),
|
|
|
|
|
// .WINDOWS_ANCHOR_X(1 ),
|
|
|
|
|
// .WINDOWS_ANCHOR_Y(1 )
|
|
|
|
|
// )Windows_Demosaic_inst(
|
|
|
|
|
// .clk (isp_clk ),
|
|
|
|
|
// .reset (reset ),
|
|
|
|
|
|
|
|
|
|
// .in_valid (adapter_valid ),
|
|
|
|
|
// .in_data (adapter_data ),
|
|
|
|
|
// .in_user (adapter_user ),
|
|
|
|
|
|
|
|
|
|
// .out_valid (Windows_Demosaic_valid ),
|
|
|
|
|
// .out_data (Windows_Demosaic_data ),
|
|
|
|
|
// .out_user (Windows_Demosaic_user ),
|
|
|
|
|
|
|
|
|
|
// .in_ready (Demosaic_ready ),
|
|
|
|
|
// .out_ready (Windows_Demosaic_ready )
|
|
|
|
|
// );
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
|
2024-10-03 17:06:40 +08:00
|
|
|
|
Demosaic_Pipeline #(
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.DATA_WIDTH (DATA_WIDTH),
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.WINDOW_LENGTH(3),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.RAW_TYPE (0)
|
2024-10-22 20:31:51 +08:00
|
|
|
|
) Demosaic_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(Windows_Demosaic_valid),
|
|
|
|
|
.in_data (Windows_Demosaic_data),
|
|
|
|
|
.in_user (Windows_Demosaic_user),
|
|
|
|
|
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.out_valid(Demosaic_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (Demosaic_data),
|
|
|
|
|
.out_user (Demosaic_user),
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.in_ready (Blender_ready),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_ready(Demosaic_ready)
|
2024-10-03 15:13:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2024-10-03 17:06:40 +08:00
|
|
|
|
ColorBlender_Pipeline #(
|
2024-10-22 20:31:51 +08:00
|
|
|
|
.DATA_WIDTH(DATA_WIDTH), // 输入图像的色深
|
|
|
|
|
.OUT_DEPTH (COLOR_DEPTH) // 输出图像的色深
|
2024-10-03 15:13:24 +08:00
|
|
|
|
) ColorBlender_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(Demosaic_valid),
|
|
|
|
|
.in_data (Demosaic_data),
|
|
|
|
|
.in_user (Demosaic_user),
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.out_valid(Blender_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (Blender_data),
|
|
|
|
|
.out_user (Blender_user),
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.in_ready (Crop_ready),
|
|
|
|
|
.out_ready(Blender_ready),
|
|
|
|
|
|
|
|
|
|
.gain_red (gain_red),
|
|
|
|
|
.gain_green(gain_green),
|
|
|
|
|
.gain_blue (gain_blue),
|
|
|
|
|
.enable (blender_enable)
|
|
|
|
|
);
|
|
|
|
|
|
2024-11-03 20:38:29 +08:00
|
|
|
|
// wire [COLOR_DEPTH-1:0] adapter_data3[3];
|
|
|
|
|
// assign adapter_data3[0] = {adapter_data};
|
|
|
|
|
// assign adapter_data3[1] = {adapter_data};
|
|
|
|
|
// assign adapter_data3[2] = {adapter_data};
|
|
|
|
|
|
|
|
|
|
// Crop #(
|
|
|
|
|
// .IN_WIDTH (IN_WIDTH ),
|
|
|
|
|
// .IN_HEIGHT (IN_HEIGHT ),
|
|
|
|
|
// .OFFSET_X (OFFSET_X ),
|
|
|
|
|
// .OFFSET_Y (OFFSET_Y ),
|
|
|
|
|
// .OUT_WIDTH (OUT_WIDTH ),
|
|
|
|
|
// .OUT_HEIGHT (OUT_HEIGHT ),
|
|
|
|
|
// .COLOR_DEPTH(COLOR_DEPTH)
|
|
|
|
|
// ) Crop_inst(
|
|
|
|
|
// .clk (isp_clk ),
|
|
|
|
|
// .reset (reset ),
|
|
|
|
|
|
|
|
|
|
// .in_valid (adapter_valid ),
|
|
|
|
|
// .in_data (adapter_data3 ),
|
|
|
|
|
// .in_user (adapter_user ),
|
|
|
|
|
|
|
|
|
|
// .out_valid (Crop_valid ),
|
|
|
|
|
// .out_data (Crop_data ),
|
|
|
|
|
// .out_user (Crop_user ),
|
|
|
|
|
|
|
|
|
|
// .in_ready (in_ready ),
|
|
|
|
|
// .out_ready (Crop_ready )
|
|
|
|
|
// );
|
|
|
|
|
|
2024-10-03 17:06:40 +08:00
|
|
|
|
Crop_Pipeline #(
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.IN_WIDTH (IN_WIDTH ),
|
|
|
|
|
.IN_HEIGHT (IN_HEIGHT ),
|
|
|
|
|
.OFFSET_X (OFFSET_X ),
|
|
|
|
|
.OFFSET_Y (OFFSET_Y ),
|
|
|
|
|
.OUT_WIDTH (OUT_WIDTH ),
|
|
|
|
|
.OUT_HEIGHT (OUT_HEIGHT ),
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.COLOR_DEPTH(COLOR_DEPTH)
|
|
|
|
|
) Crop_inst (
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.clk (isp_clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_valid(Blender_valid),
|
|
|
|
|
.in_data (Blender_data),
|
|
|
|
|
.in_user (Blender_user),
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.out_valid(Crop_valid),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_data (Crop_data),
|
|
|
|
|
.out_user (Crop_user),
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
.in_ready (in_ready),
|
2024-11-03 20:38:29 +08:00
|
|
|
|
.out_ready(Crop_ready)
|
2024-10-03 15:13:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// reg [15:0] data_out_temp[8192];
|
|
|
|
|
// reg [31:0] now;
|
|
|
|
|
// reg [2:0] cnt_www;
|
|
|
|
|
// reg flag_ifdataerror;
|
|
|
|
|
|
|
|
|
|
// initial cnt_www = 0;
|
|
|
|
|
// always @(posedge reset) begin
|
|
|
|
|
// cnt_www <= cnt_www + 1;
|
|
|
|
|
// end
|
|
|
|
|
|
|
|
|
|
// integer i;
|
|
|
|
|
// always @(posedge clk) begin
|
|
|
|
|
// if(reset) begin
|
|
|
|
|
// flag_ifdataerror <= 0;
|
|
|
|
|
// if(cnt_www==1) for(i=0;i<8192;i=i+1) data_out_temp[i] <= 0;
|
|
|
|
|
// now <= 0;
|
|
|
|
|
// end else if(Crop_valid && in_ready)begin
|
|
|
|
|
// now <= now + 1;
|
|
|
|
|
// if(cnt_www==1)begin
|
|
|
|
|
// if(now<8192) data_out_temp[now] <= Crop_data[0];
|
|
|
|
|
// end else if(cnt_www==2)begin
|
|
|
|
|
// flag_ifdataerror <= (data_out_temp[now] != Crop_data[0]);
|
|
|
|
|
// end else flag_ifdataerror <= flag_ifdataerror;
|
|
|
|
|
// end
|
|
|
|
|
// end
|
|
|
|
|
|
2024-11-03 20:38:29 +08:00
|
|
|
|
GSR GSR (.GSRI(1'b1));
|
|
|
|
|
|
2024-10-03 15:13:24 +08:00
|
|
|
|
endmodule
|