-------------------------------------------------------------------------------
--
-- (C) Copyright 2017 DFC Design, s.r.o., Brno, Czech Republic
-- Author: Marek Kvas (m.kvas@dspfpga.com)
--
-------------------------------------------------------------------------------
--
-- One bit clock domain crossing for Xilinx Vivado toolchain.
--
-------------------------------------------------------------------------------


library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity xcdc_bit is
   generic (
      g_length       : integer := 2;
      g_rst_val      : std_logic := '0'
           );
   port (
      RSTN        : in  std_logic;
      DCLK        : in  std_logic;
      DATA_IN     : in  std_logic;
      DATA_OUT    : out std_logic
        );
end entity;


architecture synthesis of xcdc_bit is
   signal dl   : std_logic_vector(g_length - 1  downto 0) := (others => '0');

   -- Prevent optimization like shift register replacement,
   -- ensure close placement of sync-chain and 
   -- make Vivado happy
   attribute ASYNC_REG           : string;
   attribute ASYNC_REG of dl     : signal is "true";

begin

   dl_shift_proc : process(DCLK)
   begin
      if rising_edge(DCLK) then
         if RSTN = '0' then
            dl <= (others => g_rst_val);
         else
            dl <= dl(dl'left - 1 downto 0) & DATA_IN;
         end if;
      end if;
   end process;

   DATA_OUT <= dl(dl'left);


end architecture;