~ruther/vhdl-playing

ref: 2ea576665fe37b9973e668b99c80ad5737b1ca65 vhdl-playing/fifo/src/resynchronizer.vhd -rw-r--r-- 1.0 KiB
2ea57666 — Rutherther feat(fifo): initial 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library ieee;
use ieee.std_logic_1164.all;

entity resynchronizer is

  generic (
    WIDTH : natural := 2);

  port (
    orig_clk_i   : in  std_logic;
    target_clk_i : in  std_logic;
    sig_i        : in  std_logic;
    sig_o        : out std_logic);

end entity resynchronizer;

architecture a1 of resynchronizer is
  signal sig_sampled : std_logic;

  signal curr_resync : std_logic_vector(WIDTH - 1 downto 0);
  signal next_resync : std_logic_vector(WIDTH - 1 downto 0);
begin  -- architecture a1

  orig_sample: process (orig_clk_i) is
  begin  -- process orig_sample
    if rising_edge(orig_clk_i) then          -- rising clock edge
      sig_sampled <= sig_i;
    end if;
  end process orig_sample;

  synchronizer: process (target_clk_i) is
  begin  -- process synchronizer
    if rising_edge(target_clk_i) then          -- rising clock edge
      curr_resync <= next_resync;
    end if;
  end process synchronizer;

  next_resync <= sig_sampled & curr_resync(WIDTH - 1 downto 1);
  sig_o <= curr_resync(0);

end architecture a1;
Do not follow this link