aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/bug0129/mwe.vhdl
blob: 888634ef1609c11ec5ba958672d193f3246cf1e7 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
library IEEE;
use IEEE.std_logic_1164.all;

entity MWE is
  port (
    clk      : in std_logic;
    start    : in std_logic;
    continue : in std_logic;
    tready   : in std_logic
    );
end;

architecture RTL of MWE is

  constant C_CTR_MAX : natural := 10;

  type t_state is (e_idle, e_count, e_do_something_else);

  type t_rec is record
    state : t_state;
    ctr   : natural range 0 to C_CTR_MAX + 5;
  end record t_rec;

  signal r      : t_rec := (e_idle, 0);
  signal r_next : t_rec;

begin

  p_main: process (all)

    procedure count (
      constant r_ctr : in  natural;
      variable v_ctr : out natural
    ) is
    begin
      if r_ctr < C_CTR_MAX then
        if tready then
          v_ctr := r_ctr + 1;
        else
          v_ctr := r_ctr;
        end if;
--    else              <-- missing
--      v_ctr := r_ctr;
      end if;
    end procedure;

    variable v : t_rec;

  begin

    v := r;

    case r.state is

      when e_idle =>
        if start then
          v.state := e_count;
        end if;

      when e_count =>
        count(r.ctr, v.ctr);

        if continue then
          v.ctr   := 0;
          v.state := e_do_something_else;
        end if;

      when e_do_something_else =>
        v.state := e_idle;

    end case;

    r_next <= v;

  end process p_main;

  p_update_state : process (clk)
  begin
    if rising_edge(clk) then
      assert now /= 105 ns or r_next.ctr = 7 severity failure;
      --  report "cntr=" & natural'image(r_next.ctr);
      r <= r_next;
    end if;
  end process;

end;
library IEEE;
use IEEE.std_logic_1164.all;

use std.env.stop;

entity MWE_TB is
end;

architecture Sim of MWE_TB is

  signal clk      : std_logic := '0';
  signal start    : std_logic;
  signal continue : std_logic;
  signal tready   : std_logic;

begin

  clk <= not clk after 5 ns;

  i_DUT : entity work.MWE(RTL)
    port map (
      clk      => clk,
      start    => start,
      continue => continue,
      tready   => tready
    );

  p_run : process

  begin

    start    <= '0';
    continue <= '0';
    tready   <= '0';

    wait for 15 ns;

    start <= '1';

    wait for 10 ns;

    start <= '0';

    wait for 10 ns;

    tready <= '1';

    wait for 150 ns;

    continue <= '1';

    wait for 10 ns;

    continue <= '0';

    wait for 50 ns;

    std.env.stop;

  end process;

end;