-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimeout_cnt.vhm
48 lines (37 loc) · 1.02 KB
/
timeout_cnt.vhm
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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.monitor_pkg.all;
entity timeout_cnt is
generic ( timeout_cc : integer := 3); -- clock cycles timeout
port(
clk : in std_logic;
rst : in std_logic;
enable : in std_logic;
ack : in std_logic;
timeout : out timeout_t;
fault : out std_logic
);
end timeout_cnt;
architecture structure of timeout_cnt is
register variable this : cnt_reg_t reset := CNT_REG_RESET;
begin
counter : process(this,enable,ack)
register this when clk = '1' and clk'event reset when rst = '1';
begin
if (enable = '1') then
if (ack = '1') then
this.cnt := 0;
else
if (this.cnt /= timeout_cc) then
this.cnt := this.cnt + 1; -- start counting
end if;
end if;
else
this.cnt := 0;
end if;
end process;
--timeout <= '1' when (this.cnt = timeout_cc) else '0';
timeout.cnt <= this'register.cnt;
fault <= '1' when (this'register.cnt = timeout_cc) else '0';
end structure;