From 69ecbbe10f8d19ba5c08df88c6065b0aea2c4aa2 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Wed, 3 Jan 2024 21:21:48 +0100 Subject: [PATCH] feat: synchronize reset in mcu slave tops --- src/mcu_slave/counter.vhd | 9 ++++++++- src/mcu_slave/regs.vhd | 12 ++++++++++-- tb/mcu_slave/counter_tb.vhd | 2 +- tb/mcu_slave/regs_tb.vhd | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/mcu_slave/counter.vhd b/src/mcu_slave/counter.vhd index c1bdb42..fe045e5 100644 --- a/src/mcu_slave/counter.vhd +++ b/src/mcu_slave/counter.vhd @@ -31,6 +31,7 @@ architecture a1 of counter is signal go_next : std_logic; signal rst_n : std_logic; + signal rst_sync : std_logic; signal sda, scl : std_logic; signal sda_enable, scl_enable : std_logic; @@ -38,9 +39,15 @@ architecture a1 of counter is signal tx_valid, tx_ready : std_logic; signal tx_data : std_logic_vector(7 downto 0); begin - rst_n <= not rst_i; + rst_n <= not rst_sync; rst_on <= rst_n; + sync_reset: entity utils.metastability_filter + port map ( + clk_i => clk_i, + signal_i => rst_i, + signal_o => rst_sync); + next_count <= (curr_count + 1) mod MAX when go_next = '1' else curr_count; diff --git a/src/mcu_slave/regs.vhd b/src/mcu_slave/regs.vhd index dc7cb87..5c988c7 100644 --- a/src/mcu_slave/regs.vhd +++ b/src/mcu_slave/regs.vhd @@ -30,6 +30,7 @@ architecture a1 of regs is signal next_regs : regs_t; signal rst_n : std_logic; + signal rst_sync : std_logic; signal sda, scl : std_logic; signal sda_enable, scl_enable : std_logic; @@ -53,8 +54,15 @@ architecture a1 of regs is signal rw : std_logic; begin - rst_n <= not rst_i; - rst_on <= not rst_i; + rst_n <= not rst_sync; + rst_on <= rst_n; + + sync_reset: entity utils.metastability_filter + port map ( + clk_i => clk_i, + signal_i => rst_i, + signal_o => rst_sync); + dev_busy_o <= dev_busy; next_dev_busy <= dev_busy; diff --git a/tb/mcu_slave/counter_tb.vhd b/tb/mcu_slave/counter_tb.vhd index 5a34f48..e89579a 100644 --- a/tb/mcu_slave/counter_tb.vhd +++ b/tb/mcu_slave/counter_tb.vhd @@ -55,7 +55,7 @@ begin -- architecture tb not_scl <= not scl; clk <= not clk after CLK_PERIOD / 2; - rst_n <= '1' after 2 * CLK_PERIOD; + rst_n <= '1' after 6 * CLK_PERIOD; rst <= not rst_n; -- TODO: allow conditions from master... diff --git a/tb/mcu_slave/regs_tb.vhd b/tb/mcu_slave/regs_tb.vhd index 6214620..2997581 100644 --- a/tb/mcu_slave/regs_tb.vhd +++ b/tb/mcu_slave/regs_tb.vhd @@ -56,7 +56,7 @@ begin -- architecture tb not_scl <= not scl; clk <= not clk after CLK_PERIOD / 2; - rst_n <= '1' after 2 * CLK_PERIOD; + rst_n <= '1' after 6 * CLK_PERIOD; rst <= not rst_n; -- TODO: allow conditions from master... -- 2.49.0