aboutsummaryrefslogtreecommitdiff
path: root/src/t_fir_fileio.vhd
blob: 3fd8363efbe3ee44d55d0bbf026d83ff5ab6cf58 (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
-------------------------------------------------------------------------------
-- Module     : t_fir_fileio
-------------------------------------------------------------------------------
-- Author     : Matthias Kamuf
-- Company    : University of Applied Sciences Augsburg
-------------------------------------------------------------------------------
-- Description: Testbench for module fir
--              
------------------------------------------------------------------------------
-- Revisions  : see end of file
------------------------------------------------------------------------------- 
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;
USE STD.textio.ALL;

ENTITY t_fir IS

END t_fir;

ARCHITECTURE tbench OF t_fir IS

  COMPONENT fir IS
    PORT (
      clk_i    : IN  std_ulogic;
      rst_ni   : IN  std_ulogic;
      valid_i  : IN  std_ulogic;
      sample_i : IN  std_ulogic_vector(13 DOWNTO 0);
      valid_o  : OUT std_ulogic;
      sample_o : OUT std_ulogic_vector(13 DOWNTO 0));
  END COMPONENT fir;

  -- component ports
  SIGNAL clk        : std_ulogic;
  SIGNAL rst_n      : std_ulogic;
  SIGNAL valid_in   : std_ulogic;
  SIGNAL sample_in  : std_ulogic_vector(13 DOWNTO 0);
  SIGNAL valid_out  : std_ulogic;
  SIGNAL sample_out : std_ulogic_vector(13 DOWNTO 0);

  -- definition of a clock period
  CONSTANT period : time    := 20 ns;
  -- switch for clock generator
  SIGNAL clken_p  : boolean := true;

BEGIN

  -- component instantiation
  DUT : fir
    PORT MAP (
      clk_i    => clk,
      rst_ni   => rst_n,
      valid_i  => valid_in,
      sample_i => sample_in,
      valid_o  => valid_out,
      sample_o => sample_out);

  -- clock generation
  clock_proc : PROCESS
  BEGIN
    WHILE clken_p LOOP
      clk <= '0'; WAIT FOR period/2;
      clk <= '1'; WAIT FOR period/2;
    END LOOP;
    WAIT;
  END PROCESS;

  reset : rst_n <= '0', '1' AFTER period;

  stimuli_observer : PROCESS
    VARIABLE Li      : line;            -- pointer to file input buffer
    VARIABLE Vi      : integer;
    FILE stimulifile : text OPEN read_mode IS "stimuli/fir_stimuli.dat";

    VARIABLE Lo     : line;             -- pointer to file output buffer
    VARIABLE Vo     : integer;
    FILE resultfile : text OPEN write_mode IS "log/fir_result.dat";

  BEGIN

    valid_in  <= '1';
    sample_in <= (OTHERS => '0');

    WAIT UNTIL rst_n = '1';             -- wait for reset

    WHILE (NOT endfile(stimulifile)) LOOP
      IF valid_in = '1' THEN
        readline(stimulifile, Li);
        read(Li, Vi);
        sample_in <= std_ulogic_vector(to_signed(Vi, sample_in'length));
      END IF;
      IF valid_out = '1' THEN
        Vo := to_integer(signed(sample_out));
        write(Lo, Vo);
        writeline(resultfile, Lo);
      END IF;
      WAIT UNTIL clk = '1';
    END LOOP;

    clken_p <= false;                   -- switch off clock generator

    WAIT;
  END PROCESS;
END tbench;


-------------------------------------------------------------------------------
-- Revisions:
-- ----------
-- $Id:$
-------------------------------------------------------------------------------