add find_seq_1.v and pipline_adder.v

This commit is contained in:
yunlongLi 2024-10-31 21:05:56 +08:00
parent 2ee46782df
commit b2ad5ac5c2
2 changed files with 198 additions and 0 deletions

128
common/find_sequ_1.v Normal file
View File

@ -0,0 +1,128 @@
//=======================================
//--Author : colonel
//--Date 1028
//--Module : find_sequ_1
//--Function: to find the index of 1 when input din
//=======================================
module find_sequ_1#(
//==========================< 参数 >=========================
parameter DATA_WIDTH = 8,
parameter INDEX_LEN = $clog2(DATA_WIDTH)
)(
//==========================< 端口 >=========================
input wire clk,
input wire rst_n,
input wire din_vld,
input wire [DATA_WIDTH -1:0] din,
output wire done,
output wire idx_vld,
output wire [INDEX_LEN -1:0] inx,
input wire idx_rdy
);
//==========================< 参数 >=========================
localparam IDLE = 2'b00;
localparam SERACHING = 2'b01;
localparam FOUND = 2'b10;
//==========================< 信号 >=========================
reg [INDEX_LEN -1:0] curr_index;
reg [INDEX_LEN -1:0] found_index;
reg found_flag;
//==========================< FSM-0 >=========================
reg [2 -1:0] sta_cur;
reg [2 -1:0] sta_nxt;
//=========================================================
//-- FSM-1: State transition
//=========================================================
always @(negedge clk or negedge rst_n) begin
if (!rst_n) begin
sta_cur <= IDLE;
end else begin
sta_cur <= sta_nxt;
end
end
//=========================================================
//-- FSM-2: State Jump Condition
//=========================================================
always @(*) begin
case (sta_cur)
IDLE: begin
if(!din_vld) begin
sta_nxt = IDLE;
end else begin
sta_nxt = SERACHING;
end
end
SERACHING: begin
if (din[curr_index]==1'b1) begin
sta_nxt = FOUND;
end else begin
sta_nxt = SERACHING;
end
end
FOUND: begin
if(din_vld) begin
sta_nxt <= SERACHING;
end else begin
sta_nxt <= IDLE;
end
end
default: ;
endcase
end
//=========================================================
//-- FSM-3: State Action
//=========================================================
//=========================================================
//-- FSM-3: State Action
//-- curr_index
//=========================================================
// always @(posedge clk or negedge rst_n) begin
// if (!rst_n) begin
// curr_index <= 0;
// end else begin
// case (sta_cur)
// IDLE: begin
// curr_index <= 0;
// end
// SERACHING: begin
// if(din[curr_index] == 1'b0) begin
// curr_index <= curr_index + 1;
// end
// end
// FOUND: begin
// curr_index <= curr_index;
// end
// default: begin
// curr_index <= 0;
// end
// endcase
// end
// end
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
curr_index <= 0;
end else begin
if(sta_cur==SERACHING) begin
curr_index <= curr_index + 1;
end else begin
curr_index <= curr_index;
end
end
end
assign done = (sta_cur==FOUND) && idx_rdy;
assign idx_vld = (sta_cur==FOUND);
assign inx = curr_index;
endmodule

70
common/pipline_adder.v Normal file
View File

@ -0,0 +1,70 @@
//=======================================
//--Author : colonel
//--Date 1029
//--Module : pipline_adder
//--Function: to meet the adder pipline of three input
//=======================================
module pipline_adder (
//==========================< 端口 >=========================
input wire clk,
input wire a_in,
input wire b_in,
input wire c_in,
input wire vld_in,
output reg vld_out,
output reg[1:0] sum_out
);
//==========================< 信号 >=========================
//--S1 Stage
reg vld_s1;
reg a_s1,b_s1,c_s1;
wire [1:0] a_b_sum_s1;
//--S2 Stage
reg vld_s2;
reg c_s2;
reg a_b_sum_s2;
wire [1:0] sum_s2;
//=========================================================
//-- S1 Stage
//=========================================================
always @(posedge clk) begin
if(vld_in) begin
a_s1 <= a_in;
b_s1 <= b_in;
c_s2 <= c_in;
vld_s1 <= vld_in;
end else begin
vld_s1 <= 1'b0;
end
end
assign a_b_sum_s1 = {1'b0,a_s1} + {1'b0,b_s1};
//=========================================================
//-- S2 Stage
//=========================================================
always @(posedge clk) begin
if (vld_s1) begin
a_b_sum_s2 <= a_b_sum_s1;
c_s2 <= c_s1;
vld_s2 <= vld_s1;
end
end
assign sum_s2 = a_b_sum_s2 + c_s2;
//=========================================================
//-- sum_out
//=========================================================
always @(posedge clk) begin
if(vld_s2) begin
vld_out <= vld_s2;
sum_out <= sum_s2;
end
end
endmodule