forked from yol/ethernet_mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_generator.vhd
74 lines (63 loc) · 1.66 KB
/
reset_generator.vhd
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
-- This file is part of the ethernet_mac project.
--
-- For the full copyright and license information, please read the
-- LICENSE.md file that was distributed with this source code.
-- Monitor the speed and issue a core-wide reset if it changes
library ieee;
use ieee.std_logic_1164.all;
use work.ethernet_types.all;
entity reset_generator is
generic(
-- Number of clock_i ticks reset should get asserted for
RESET_TICKS : positive := 1000
);
port(
clock_i : in std_ulogic;
-- Speed signal synchronous to clock_i
speed_i : in t_ethernet_speed;
-- Asynchronous reset input for this logic
-- Do NOT connect reset_i and reset_o anywhere in the design
reset_i : in std_ulogic;
-- Reset output
-- Is also asserted whenever reset_i is asserted
reset_o : out std_ulogic
);
end entity;
architecture rtl of reset_generator is
type t_state is (
WATCH,
RESET
);
signal state : t_state := WATCH;
signal reset_counter : integer range 0 to RESET_TICKS;
signal last_speed : t_ethernet_speed;
begin
speed_watch : process(reset_i, clock_i)
begin
if reset_i = '1' then
last_speed <= SPEED_UNSPECIFIED;
state <= WATCH;
reset_o <= '1';
elsif rising_edge(clock_i) then
reset_o <= '0';
case state is
when WATCH =>
null;
when RESET =>
reset_o <= '1';
if reset_counter = RESET_TICKS then
state <= WATCH;
else
reset_counter <= reset_counter + 1;
end if;
end case;
if speed_i /= last_speed then
-- Speed was changed
state <= RESET;
-- Always reset counter
reset_counter <= 0;
end if;
last_speed <= speed_i;
end if;
end process;
end architecture;