ISP/rtl/BayerProcess/Windows.sv

140 lines
5.1 KiB
Systemverilog
Raw Permalink Normal View History

2024-10-22 20:31:51 +08:00
module Windows #(
2024-11-03 20:38:29 +08:00
parameter DATA_WIDTH = 16,
parameter WINDOWS_WIDTH = 3,
parameter WINDOWS_ANCHOR_X = 1,//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>WINDOWS_WIDTH-1
parameter WINDOWS_ANCHOR_Y = 1 //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>WINDOWS_WIDTH-1
)(
// <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
2024-10-22 20:31:51 +08:00
input wire clk,
input wire reset,
2024-11-03 20:38:29 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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 [7:0] in_user,
output reg [DATA_WIDTH - 1:0] out_data [WINDOWS_WIDTH*WINDOWS_WIDTH], // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
output wire [7:0] out_user,
// <20><>Ч<EFBFBD>ź<EFBFBD>
input wire in_valid, // <20><>һģ<D2BB><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
output wire out_valid, // <20><>ǰģ<C7B0><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
// ׼<><D7BC><EFBFBD>ź<EFBFBD> Windowsģ<73><C4A3><EFBFBD>޷<EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD>ź<EFBFBD>
2024-10-22 20:31:51 +08:00
input wire in_ready,
output wire out_ready
);
2024-11-03 20:38:29 +08:00
assign out_ready = 1'b1;
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
reg [DATA_WIDTH - 1:0] regx_in_data[WINDOWS_WIDTH-1];
wire [DATA_WIDTH - 1:0] regx_out_data[WINDOWS_WIDTH-1];
reg [7:0] regx_in_user[WINDOWS_WIDTH-1];
wire [7:0] regx_out_user[WINDOWS_WIDTH-1];
reg [WINDOWS_WIDTH - 2:0] regx_in_valid;
wire [WINDOWS_WIDTH - 2:0] regx_out_valid;
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
reg [DATA_WIDTH - 1:0] data_out_shift[WINDOWS_WIDTH-1][2*(WINDOWS_WIDTH-1)];
reg [7:0] user_out_shift[WINDOWS_WIDTH-1][2*(WINDOWS_WIDTH-1)];
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
reg [7:0] out_user_windows[WINDOWS_WIDTH*WINDOWS_WIDTH];
assign out_user = out_user_windows[(WINDOWS_WIDTH*WINDOWS_ANCHOR_Y) + WINDOWS_ANCHOR_X];
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
/* outdata[x]:
2024-10-22 20:31:51 +08:00
SHIFT_REG1 -> 0 3 6 . .
SHIFT_REG0 -> 1 4 7 . .
in_data -> 2 5 8 . .
. . .
. . .
*/
2024-11-03 20:38:29 +08:00
reg out_valid_output;
reg firstframedone;
always @(posedge clk) begin
if(reset) firstframedone <= 0;
else if(out_user == 1'b1) firstframedone <= 1;
else firstframedone <= firstframedone;
end
always @(posedge clk) begin
if(reset) out_valid_output <= 0;
else out_valid_output <= regx_out_valid[WINDOWS_WIDTH-2];
end
assign out_valid = out_valid_output & (firstframedone || out_user);
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
integer i,j;
always @(posedge clk) begin
if(reset)begin
for(i=0;i<WINDOWS_WIDTH*WINDOWS_WIDTH;i=i+1) out_data[i] <= 0;
for(i=0;i<WINDOWS_WIDTH*WINDOWS_WIDTH;i=i+1) out_user_windows[i] <= 0;
end else if(regx_out_valid[WINDOWS_WIDTH-2])begin
for(i=0;i<WINDOWS_WIDTH;i=i+1) begin
for(j=0;j<WINDOWS_WIDTH;j=j+1) begin
if(i==WINDOWS_WIDTH-1) begin
if(j==0) out_data[(WINDOWS_WIDTH*i)+j] <= regx_out_data[WINDOWS_WIDTH-2];
else out_data[(WINDOWS_WIDTH*i)+j] <= data_out_shift[j-1][2*j-1];
end
else out_data[(WINDOWS_WIDTH*i)+j] <= out_data[(WINDOWS_WIDTH*(i+1))+j];
end
end
for(i=0;i<WINDOWS_WIDTH;i=i+1) begin
for(j=0;j<WINDOWS_WIDTH;j=j+1) begin
if(i==WINDOWS_WIDTH-1) begin
if(j==0) out_user_windows[(WINDOWS_WIDTH*i)+j] <= regx_out_user[WINDOWS_WIDTH-2];
else out_user_windows[(WINDOWS_WIDTH*i)+j] <= user_out_shift[j-1][2*j-1];
end
else out_user_windows[(WINDOWS_WIDTH*i)+j] <= out_user_windows[(WINDOWS_WIDTH*(i+1))+j];
end
2024-10-22 20:31:51 +08:00
end
end else begin
2024-11-03 20:38:29 +08:00
for(i=0;i<WINDOWS_WIDTH*WINDOWS_WIDTH-1;i=i+1) out_data[i] <= out_data[i];
for(i=0;i<WINDOWS_WIDTH*WINDOWS_WIDTH-1;i=i+1) out_user_windows[i] <= out_user_windows[i];
2024-10-22 20:31:51 +08:00
end
2024-11-03 20:38:29 +08:00
end
always @(posedge clk) begin
if(reset) for(i=0;i<WINDOWS_WIDTH-1;i=i+1) for(j=0;j<WINDOWS_WIDTH-1;j=j+1) begin
data_out_shift[i][j] <= 0;
user_out_shift[i][j] <= 0;
end else for(i=0;i<WINDOWS_WIDTH-1;i=i+1) begin
for(j=0;j<2*(WINDOWS_WIDTH-1);j=j+1) begin
if(i==WINDOWS_WIDTH-2 && j==0) data_out_shift[i][j] <= in_data;
else if(j==0) data_out_shift[i][j] <= regx_out_data[(WINDOWS_WIDTH-2-i)-1];
else data_out_shift[i][j] <= data_out_shift[i][j-1];
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
if(i==WINDOWS_WIDTH-2 && j==0) user_out_shift[i][j] <= in_user;
else if(j==0) user_out_shift[i][j] <= regx_out_user[(WINDOWS_WIDTH-2-i)-1];
else user_out_shift[i][j] <= user_out_shift[i][j-1];
2024-10-22 20:31:51 +08:00
end
2024-11-03 20:38:29 +08:00
end
end
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
always @(*) begin
for(i=0;i<WINDOWS_WIDTH-1;i=i+1)begin
if(i == 0) regx_in_data[i] = in_data;
else regx_in_data[i] = regx_out_data[i-1];
end
for(i=0;i<WINDOWS_WIDTH-1;i=i+1)begin
if(i == 0) regx_in_user[i] = in_user;
else regx_in_user[i] = regx_out_user[i-1];
2024-10-22 20:31:51 +08:00
end
2024-11-03 20:38:29 +08:00
for(i=0;i<WINDOWS_WIDTH-1;i=i+1)begin
if(i == 0) regx_in_valid[i] = in_valid;
else regx_in_valid[i] = regx_out_valid[i-1];
2024-10-22 20:31:51 +08:00
end
2024-11-03 20:38:29 +08:00
end
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
generate
genvar o;
for(o = 0; o < WINDOWS_WIDTH - 1; o = o + 1'b1) begin:shift_register
SHIFT_REGISTER #(
.DATA_WIDTH(DATA_WIDTH),
.IFOUTIMME(1'b1)
)shift_registerx(
2024-10-22 20:31:51 +08:00
.clk (clk),
.reset (reset),
.in_data (regx_in_data[o]),
2024-11-03 20:38:29 +08:00
.in_user (regx_in_user[o]),
2024-10-22 20:31:51 +08:00
.out_data (regx_out_data[o]),
2024-11-03 20:38:29 +08:00
.out_user (regx_out_user[o]),
2024-10-22 20:31:51 +08:00
.in_valid (regx_in_valid[o]),
.out_valid(regx_out_valid[o])
2024-11-03 20:38:29 +08:00
);
end
endgenerate
2024-10-22 20:31:51 +08:00
2024-11-03 20:38:29 +08:00
endmodule