ISP/Merge/chanels_to_RGB.v

75 lines
2.1 KiB
Coq
Raw Normal View History

2024-05-11 21:53:35 +08:00
`timescale 1ns/1ps
// 三通道图像合成一个RGB图像
module chanels_to_RGB #(
parameter IN_DEPTH = 12, // 输入图像的色深
parameter OUT_DEPTH = 8 // 输出图像的色深
) (
input clk,
input reset,
input in_en,
2024-05-15 16:43:41 +08:00
input [15:0] data_in [2:0], // 0:R 1:G 2:B
2024-05-11 21:53:35 +08:00
// 输出相关
2024-05-13 11:29:03 +08:00
input data_que, // 数据请求
2024-05-13 16:52:13 +08:00
output out_en,
output [3 * OUT_DEPTH - 1:0] data_out
2024-05-11 21:53:35 +08:00
);
reg [31:0] data_cal [2:0]; // 用于保存运算结果防止溢出
reg fifo_en;
2024-05-13 16:52:13 +08:00
reg [3 * OUT_DEPTH - 1:0] fifo_in; // 输入fifo中缓存
2024-05-11 21:53:35 +08:00
wire fifo_empty;
// wire fifo_alempty;
always @(posedge clk or posedge reset) begin
if (reset) begin
// 初始化
2024-05-13 16:52:13 +08:00
data_cal[0] <= 0;
data_cal[1] <= 0;
data_cal[2] <= 0;
fifo_en <= 0;
fifo_in <= 0;
2024-05-11 21:53:35 +08:00
end
else begin
if (in_en) begin
data_cal[0] <= data_in[0] * OUT_DEPTH / IN_DEPTH;
data_cal[1] <= data_in[1] * OUT_DEPTH / IN_DEPTH;
data_cal[2] <= data_in[2] * OUT_DEPTH / IN_DEPTH;
fifo_in <= {data_cal[0][OUT_DEPTH - 1:0], data_cal[1][OUT_DEPTH - 1:0],data_cal[2][OUT_DEPTH - 1:0]};
// data_out <= {data_cal[0][OUT_DEPTH - 1:0], data_cal[1][OUT_DEPTH - 1:0],data_cal[2][OUT_DEPTH - 1:0]};
end
fifo_en <= in_en;
end
end
// 存在数据请求且FIFO不为空时才发送数据
2024-05-13 11:29:03 +08:00
assign out_en = (data_que && !fifo_empty) ? 1 : 0;
2024-05-11 21:53:35 +08:00
async_fifo #(
.DSIZE(3 * OUT_DEPTH),
2024-05-15 21:54:11 +08:00
.ASIZE(4),
.FALLTHROUGH("False")
2024-05-11 21:53:35 +08:00
) RGB_FIFO (
.wclk(clk),
.rclk(clk),
.wrst_n(reset),
.rrst_n(reset),
.winc(fifo_en),
.wdata(fifo_in),
/* verilator lint_off PINCONNECTEMPTY */
2024-05-13 16:52:13 +08:00
.wfull(),
/* verilator lint_off PINCONNECTEMPTY */
2024-05-13 16:52:13 +08:00
.awfull(),
2024-05-11 21:53:35 +08:00
/* verilator lint_off PINCONNECTEMPTY */
2024-05-13 16:52:13 +08:00
.arempty(),
2024-05-11 21:53:35 +08:00
.rempty(fifo_empty),
.rdata(data_out),
.rinc(out_en)
);
2024-05-13 11:29:03 +08:00
endmodule