Skip to content

Commit

Permalink
added SV implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
npatsiatzis committed Aug 18, 2023
1 parent c1ba59c commit 85dcec0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rtl/SystemVerilog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RTL_DIR = $(PWD)

.PHONY:lint
lint:
@verilator --lint-only $(RTL_DIR)/*.sv
@verible-verilog-lint $(RTL_DIR)/*.sv
34 changes: 34 additions & 0 deletions rtl/SystemVerilog/recirculation_mux.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
`default_nettype none

module recirculation_mux
#
(
parameter int G_STAGES = 2,
parameter int G_WIDTH = 4
)

(
input logic i_clk_A,
input logic i_rst_A,
input logic i_pulse_A,
input logic [G_WIDTH - 1 : 0] i_data_A,

input logic i_clk_B,
input logic i_rst_B,
output logic [G_WIDTH - 1 : 0] o_data_B
);

logic w_pulse_B;

toggle_synchronizer #(.G_STAGES(G_STAGES)) sync (.*,.o_pulse_B(w_pulse_B));

always_ff @(posedge i_clk_B) begin : mux_recirculation
if(i_rst_B) begin
o_data_B <= 0;
end else begin
if (w_pulse_B)
o_data_B <= i_data_A;
end
end

endmodule : recirculation_mux
44 changes: 44 additions & 0 deletions rtl/SystemVerilog/toggle_synchronizer.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
`default_nettype none

module toggle_synchronizer
#
(
parameter int G_STAGES = 2
)

(
input logic i_clk_A,
input logic i_rst_A,
input logic i_pulse_A,

input logic i_clk_B,
input logic i_rst_B,
output logic o_pulse_B
);

logic r_pulse_A;
logic [G_STAGES - 1 : 0] r_syncB_pulse_A;
logic r_edge_detect_ff;

always_ff @(posedge i_clk_A) begin : pulse_to_level
if(i_rst_A) begin
r_pulse_A <= 0;
end else begin
if (i_pulse_A)
r_pulse_A <= ~r_pulse_A;
end
end

always_ff @(posedge i_clk_B) begin : sync_domain_B
if(i_rst_B) begin
r_syncB_pulse_A <= '0;
r_edge_detect_ff <= 1'b0;
end else begin
r_syncB_pulse_A <= {r_syncB_pulse_A[G_STAGES - 2 : 0], r_pulse_A};
r_edge_detect_ff <= r_syncB_pulse_A[G_STAGES - 1];
end
end

assign o_pulse_B = r_edge_detect_ff ^ r_syncB_pulse_A[G_STAGES - 1];

endmodule : toggle_synchronizer

0 comments on commit 85dcec0

Please sign in to comment.