add sync_multi_bits

This commit is contained in:
yunlongLi 2024-11-01 17:24:43 +08:00
parent b119e80af8
commit 761891162a
3 changed files with 226 additions and 1 deletions

View File

@ -4,7 +4,6 @@
//--Module : sync_1bit_from_slow_2_fast
//--Function: sync 1bit from slow clk to fast clk
//==========================================================
module sync_1bit_from_slow_2_fast(
//==========================< 端口 >=========================
input wire slow_clk,

222
common/sync_multi_bits.v Normal file
View File

@ -0,0 +1,222 @@
//==========================================================
//--Author : colonel
//--Date : 11-01
//--Module : sync_multi_bits_slow_2_fast
//--Function: sync multi bits from slow_clk to fast_clk using MUX
//-- Only considering the yaWenTai;
//==========================================================
module sync_multi_bits_slow_2_fast (
//==========================< 端口 >=========================
input wire slow_clk,
input wire rst_n,
input wire din_en,
input wire [32 -1:0] din,
input wire fast_clk,
output wire dout_en,
output wire [32 -1:0] dout
);
//==========================< 信号 >=========================
reg din_en_r1;
reg din_en_r2;
reg din_en_r3;
//=========================================================
//-- din_en_r1/r2/r3: sync din_en to fast_clk
//=========================================================
always @(posedge fast_clk or negedge rst_n) begin
if (!rst_n) begin
din_en_r1 <= 1'b0;
din_en_r2 <= 1'b0;
din_en_r3 <= 1'b0;
end else begin
din_en_r1 <= din_en;
din_en_r2 <= din_en_r1;
din_en_r3 <= din_en_r2;
end
end
wire din_en_pos = din_en_r2 && !din_en_r3;
//==========================< 信号 >=========================
reg [32 -1:0] dout_r;
reg dout_en_r;
//=========================================================
//-- dout_r, dout_en_r
//=========================================================
always @(posedge fast_clk or negedge rst_n) begin
if (!rst_n) begin
dout_r <= 'b0;
end else if(din_en_pos) begin
dout_r <= din;
end else begin
dout_r <= dout_r;
end
end
always @(posedge fast_clk or negedge rst_n) begin
if (!rst_n) begin
dout_en_r <= 'b0;
end else begin
dout_en_r <= din_en_pos;
end
end
//=========================================================
//-- dout,dout_en
//=========================================================
assign dout_en = dout_en_r;
assign dout = dout_r;
endmodule
//==========================================================
//--Author : colonel
//--Date : 11-01
//--Module : sync_multi_bits_fast_2_slow
//--Function: sync multi bits from slow_clk to fast_clk using MUX
//-- Only considering the yaWenTai;
//==========================================================
module sync_multi_bits_fast_2_slow(
//==========================< 端口 >=========================
input wire t_clk,
input wire rst_n,
input wire t_din_en,
input wire [32 -1:0] t_din,
output wire o_t_ready,
input wire r_clk,
output wire r_dout_en,
output wire [32 -1:0] r_dout
);
//==========================< 端口 >=========================
reg t_req;
reg r_req_sync1;
reg r_req_sync2;
reg r_ack;
//=========================================================
//-- t_req, r_req_sync1/2
//=========================================================
always @(posedge t_clk or negedge rst_n) begin
if (!rst_n) begin
t_req <= 1'b0;
end else begin
if(t_din_en) begin
t_req <= 1'b1;
end else if (t_ack_sync2) begin
t_req <= 1'b0;
end else begin
t_req <= t_req;
end
end
end
always @(posedge r_clk or negedge rst_n) begin
if (!rst_n) begin
r_req_sync1 <= 1'b0;
r_req_sync2 <= 1'b0;
end else begin
r_req_sync1 <= t_req;
r_req_sync2 <= r_req_sync1;
end
end
always @(posedge r_clk or negedge rst_n) begin
if (!rst_n) begin
r_ack <= 1'b0;
end else begin
r_ack <= r_req_sync2;
end
end
//==========================< 端口 >=========================
reg r_dout_en_r;
reg r_dout_r;
wire r_req_sync_2_pos = r_req_sync2 & !r_ack;
//=========================================================
//-- r_dout_en_r,r_dout_r
//=========================================================
always @(posedge r_clk or negedge rst_n) begin
if (!rst_n) begin
r_dout_en_r <= 1'b0;
end else begin
if (r_req_sync_2_pos) begin
r_dout_en_r <= 1'b1;
end else begin
r_dout_en_r <= 1'b0;
end
end
end
always @(posedge r_clk or negedge rst_n) begin
if (!rst_n) begin
r_dout_r <= 'b0;
end else begin
if (r_req_sync2) begin
r_dout <= t_din;
end else begin
r_dout <= r_dout;
end
end
end
//=========================================================
//-- r_dout_en,r_dout
//=========================================================
assign r_dout_en= r_dout_en_r;
assign r_dout = r_dout_r;
//==========================< 端口 >=========================
reg t_ack_sync1;
reg t_ack_sync2;
//=========================================================
//-- t_ack_sync1/2
//=========================================================
always @(posedge t_clk or negedge rst_n) begin
if (!rst_n) begin
t_ack_sync1 <= 1'b0;
t_ack_sync2 <= 1'b0;
end else begin
t_ack_sync1 <= r_ack;
t_ack_sync2 <= t_ack_sync1;
end
end
//==========================< 端口 >=========================
reg o_t_ready_r;
wire t_ack_sync2_neg = t_ack_sync2 & ~t_ack_sync1;
//=========================================================
//-- o_t_ready_r
//=========================================================
always @(posedge t_clk or negedge rst_n) begin
if (!rst_n) begin
o_t_ready_r <= 1'b1;
end else begin
if (t_req) begin
o_t_ready_r <= 1'b0;
end else if (t_ack_sync2_neg) begin
o_t_ready_r <= 1'b1;
end else begin
o_t_ready_r <= o_t_ready_r;
end
end
end
assign o_t_ready = o_t_ready_r;
endmodule
//==========================================================
//--Author : colonel
//--Date : 11-01
//--Module : sync_multi_bits_slow_2_fast
//--Function: sync multi bits from slow_clk to fast_clk using MUX
//-- Only considering the yaWenTai;
//==========================================================

View File

@ -4,5 +4,9 @@ This is a computer course design from HIT;
[Ref]
[Strong Reference]
1. https://github.com/tomatoyuan/Single-Cycle-Processor
[Weak Reference]
1. https://foxsen.github.io/archbase/
2. https://bookdown.org/loongson/_book3/