ISP/Crop/crop.v

85 lines
2.0 KiB
Coq
Raw Normal View History

2024-05-12 22:09:23 +08:00
module crop #(
parameter IN_WIDTH = 1936 - 2,
parameter IN_HEIGHT = 1088 - 2,
parameter OFFSET_X = 8,
parameter OFFSET_Y = 4,
parameter OUT_WIDTH = 640,
2024-05-13 11:29:03 +08:00
parameter OUT_HEIGHT = 480,
parameter COLOR_DEPTH = 8
2024-05-12 22:09:23 +08:00
) (
input clk,
input reset,
input in_en,
2024-05-13 16:52:13 +08:00
output in_que,
2024-05-12 22:09:23 +08:00
input [3 * COLOR_DEPTH - 1:0] data_in,
2024-05-13 16:52:13 +08:00
output out_en,
2024-05-12 22:09:23 +08:00
input out_que,
output reg [3 * COLOR_DEPTH - 1:0] data_out
);
wire fifo_full, fifo_empty;
reg [11:0] cnt_x, cnt_y;
2024-05-13 16:52:13 +08:00
reg fifo_en;
2024-05-12 22:09:23 +08:00
async_fifo #(
.DSIZE(3 * COLOR_DEPTH),
.ASIZE(128)
) fifo_image (
.wclk(clk),
.wrst_n(reset),
.rclk(clk),
.rrst_n(reset),
.winc(fifo_en),
.wdata(data_in),
.wfull(fifo_full),
2024-05-13 16:52:13 +08:00
.awfull(),
2024-05-12 22:09:23 +08:00
.rinc(out_en),
.rdata(data_out),
2024-05-13 16:52:13 +08:00
.rempty(fifo_empty),
.arempty()
2024-05-12 22:09:23 +08:00
);
assign in_que = !fifo_full;
assign out_en = (out_que && !fifo_empty) ? 1 : 0;
always @(posedge clk or posedge reset) begin
if (reset) begin
2024-05-13 16:52:13 +08:00
fifo_en <= 0;
2024-05-12 22:09:23 +08:00
cnt_x <= 0;
cnt_y <= 0;
end
else begin
if (in_en) begin
2024-05-13 10:49:15 +08:00
if (OFFSET_Y <= cnt_y && cnt_y < (OFFSET_Y + OUT_HEIGHT)) begin
if (OFFSET_X <= cnt_x && cnt_x < (OFFSET_X + OUT_WIDTH)) begin
fifo_en <= 1;
end
else begin
fifo_en <= 0;
end
end
else begin
fifo_en <= 0;
end
2024-05-12 22:09:23 +08:00
cnt_x <= cnt_x + 1;
if (cnt_x >= (OFFSET_X + OUT_WIDTH)) begin
cnt_x <= 0;
if (cnt_y >= (OFFSET_Y + OUT_HEIGHT)) begin
cnt_y <= 0;
end
else begin
cnt_y <= cnt_y + 1;
end
end
end
end
end
2024-05-13 11:29:03 +08:00
endmodule