aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/top/x400/rf/sim/tb_capture_sysref.vhd
blob: eb5cbcf08ff3884a6662afc6c213b84a6cbcacb0 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--
-- Copyright 2021 Ettus Research, a National Instruments Brand
--
-- SPDX-License-Identifier: LGPL-3.0-or-later
--
-- Module: tb_capture_sysref
--
-- Description:
--
--   Self-checking testbench for tb_capture_sysref.
--

library IEEE;
  use IEEE.std_logic_1164.all;
  use IEEE.numeric_std.all;

entity tb_capture_sysref is
end tb_capture_sysref;


architecture RTL of tb_capture_sysref is

  component capture_sysref
    port (
      pll_ref_clk     : in  std_logic;
      rfdc_clk        : in  std_logic;
      sysref_in       : in  std_logic;
      enable_rclk     : in  std_logic;
      sysref_out_pclk : out std_logic;
      sysref_out_rclk : out std_logic);
  end component;

  signal enable_rclk     : std_logic := '0';
  signal sysref_out_pclk : std_logic := '0';
  signal sysref_out_rclk : std_logic := '0';
  signal sysref_in       : std_logic := '0';

  signal SysrefDly, SysrefDlyDly, rSysref : std_logic := '0';

  signal StopSim : boolean;
  constant kPerPRC : time := 30 ns;
  constant kPerRF  : time := 10 ns;

  signal PllRefClk : std_logic := '1';
  signal RfdcClk   : std_logic := '1';

  procedure ClkWait(X : positive := 1) is
  begin
    for i in 1 to X loop
      wait until rising_edge(PllRefClk);
    end loop;
  end procedure ClkWait;

begin

  PllRefClk <= not PllRefClk after kPerPRC/2 when not StopSim else '0';
  RfdcClk   <= not RfdcClk   after kPerRF/2  when not StopSim else '0';

  dut: capture_sysref
    port map (
      pll_ref_clk     => PllRefClk,
      rfdc_clk        => RfdcClk,
      sysref_in       => sysref_in,
      enable_rclk     => enable_rclk,
      sysref_out_pclk => sysref_out_pclk,
      sysref_out_rclk => sysref_out_rclk
    );

  main: process
  begin
    enable_rclk <= '1';
    ClkWait(100);
    wait until falling_edge(sysref_out_rclk);
    ClkWait;
    wait until falling_edge(RfdcClk);
    enable_rclk <= '0';
    ClkWait(100);
    wait until falling_edge(RfdcClk);
    enable_rclk <= '1';
    ClkWait(100);

    StopSim <= true;
    wait;
  end process;

  sysref: process(PllRefClk)
    variable count : integer := 1;
  begin
    if rising_edge(PllRefClk) then
      count := count +1;
      if count = 10 then
        sysref_in <= not sysref_in;
        count := 1;
      end if;
    end if;
  end process;

  checker_pll_ref_clk: process(PllRefClk)
  begin
    if falling_edge(PllRefClk) then
      SysrefDly    <= sysref_in;
      SysrefDlyDly <= SysrefDly;
      assert SysrefDlyDly = sysref_out_pclk
        report "SYSREF incorrectly captured in the PllRefClk domain"
        severity error;
    end if;
  end process;

  checker_rfdc_clk: process(RfdcClk)
  begin
    if falling_edge(RfdcClk) then
      rSysref    <= sysref_out_pclk;
      assert (rSysref = sysref_out_rclk) or (enable_rclk = '0')
        report "SYSREF incorrectly captured in the RfdcClk domain."
        severity error;
    end if;
  end process;

end RTL;