Skip to content
Snippets Groups Projects
Select Git revision
  • L2SDP-1106
  • L2SDP-LIFT
  • L2SDP-1113
  • master default protected
  • HPR-158
5 results

tb_common_variable_delay.vhd

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    tb_common_variable_delay.vhd 3.95 KiB
    -- --------------------------------------------------------------------------
    -- Copyright 2020
    -- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
    -- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
    --
    -- Licensed under the Apache License, Version 2.0 (the "License");
    -- you may not use this file except in compliance with the License.
    -- You may obtain a copy of the License at
    --
    -- http://www.apache.org/licenses/LICENSE-2.0
    --
    -- Unless required by applicable law or agreed to in writing, software
    -- distributed under the License is distributed on an "AS IS" BASIS,
    -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    -- See the License for the specific language governing permissions and
    -- limitations under the License.
    -- --------------------------------------------------------------------------
    
    -- --------------------------------------------------------------------------
    -- Author:
    -- . Pieter Donker
    -- Purpose:
    -- . test bench for common_variable_delay.vhd
    -- Description:
    -- . see common_variable_delay
    -- --------------------------------------------------------------------------
    
    
    LIBRARY IEEE;
    USE IEEE.std_logic_1164.ALL;
    USE IEEE.numeric_std.ALL;
    USE work.common_pkg.ALL;
    USE work.common_str_pkg.ALL;
    USE work.tb_common_pkg.ALL;
    
    ENTITY tb_common_variable_delay IS
    END tb_common_variable_delay;
    
    ARCHITECTURE tb OF tb_common_variable_delay IS
    
      CONSTANT c_clk_period       : TIME    := 10 ns;
      CONSTANT c_trigger_interval : NATURAL := 40;  -- in clk's
      CONSTANT c_trigger_latency  : NATURAL := 1;  -- in clk's
    
      -- Use a delay > c_trigger_interval to check wiht exp_triggers_cnt that new
      -- triggers are ignored when a delay is already busy
      CONSTANT c_delay_arr        : t_natural_arr(0 TO 5) := (0, 1, 3, 12, c_trigger_interval * 3, 10);
      
      SIGNAL stimuli_done : STD_LOGIC := '0';
    
      SIGNAL tb_end : STD_LOGIC := '0';
      SIGNAL rst    : STD_LOGIC;
      SIGNAL clk    : STD_LOGIC := '0';
      
      SIGNAL delay       : NATURAL   := 0;
      SIGNAL enable      : STD_LOGIC := '0';
      SIGNAL trigger     : STD_LOGIC := '0';
      SIGNAL trigger_dly : STD_LOGIC := '0';
    
      -- Use triggers_cnt to verify that triggers only occur when enable = '1'
      -- and when the delay is not busy
      SIGNAL triggers_cnt     : NATURAL := 0;
      SIGNAL exp_triggers_cnt : NATURAL := c_delay_arr'LENGTH;
    
    BEGIN
    
      clk <= (NOT clk) OR tb_end AFTER c_clk_period/2;
      rst <= '1', '0' AFTER c_clk_period*4;
    
      -- generate trigger pulse signal
      proc_common_gen_pulse(1, c_trigger_interval, '1', rst, clk, trigger);
    
      p_in_stimuli : PROCESS
      VARIABLE clk_cnt : NATURAL := 0;
      BEGIN
        delay  <= 0;
        enable <= '0';
        
        WAIT UNTIL rst = '0';
        
        -- If enable = 0, no trigger_dly is expected
        proc_common_wait_some_cycles(clk, c_trigger_interval * 3);
    
        -- Enable trigger output and count clk's between trigger and trigger_dly
        enable <= '1';
        FOR i IN c_delay_arr'RANGE LOOP
          delay <= c_delay_arr(i);
          clk_cnt := 0;
          proc_common_wait_until_lo_hi(clk, trigger);
          WHILE trigger_dly = '0' LOOP
            clk_cnt := clk_cnt + 1;
            proc_common_wait_some_cycles(clk, 1);
          END LOOP;
          -- Verify that expected delay was applied
          ASSERT clk_cnt = c_trigger_latency + delay REPORT "delay failure, got " & int_to_str(clk_cnt) & ", expect " & int_to_str(c_trigger_latency+delay) SEVERITY ERROR;
          proc_common_wait_some_cycles(clk, 10);
        END LOOP;
        enable <= '0';
    
        proc_common_wait_some_cycles(clk, c_trigger_interval * 3);
        ASSERT triggers_cnt = exp_triggers_cnt REPORT "wrong number of trigger_dly." SEVERITY ERROR;
    
        proc_common_wait_some_cycles(clk, 10);
        tb_end <= '1';
        WAIT;
      END PROCESS;
    
      triggers_cnt <= triggers_cnt + 1 WHEN rising_edge(clk) AND trigger_dly = '1';
    
      -- device under test
      u_dut : ENTITY work.common_variable_delay
      PORT MAP (
        rst       => rst,
        clk       => clk,
    
        delay     => delay,
        enable    => enable,
        in_pulse  => trigger,
        out_pulse => trigger_dly
      );
          
    END tb;