1
|
---------------------------------------------------------------------------------------------------
|
2
|
-- Filename : mt_clktools.vhd
|
3
|
-- Project : maintech IP-Core toolbox
|
4
|
-- Purpose : Basic tools for clock/reset-generation
|
5
|
---------------------------------------------------------------------------------------------------
|
6
|
|
7
|
-----------------------------------------------------------------------------------
|
8
|
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
|
9
|
-- written by Matthias Kleffel --
|
10
|
-- --
|
11
|
-- This program is free software; you can redistribute it and/or modify --
|
12
|
-- it under the terms of the GNU General Public License as published by --
|
13
|
-- the Free Software Foundation as version 3 of the License, or --
|
14
|
-- --
|
15
|
-- This program is distributed in the hope that it will be useful, --
|
16
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
17
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
18
|
-- GNU General Public License V3 for more details. --
|
19
|
-- --
|
20
|
-- You should have received a copy of the GNU General Public License --
|
21
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
22
|
-----------------------------------------------------------------------------------
|
23
|
|
24
|
-------------------------------------------------------------------------------
|
25
|
-- mt_reset_gen ---------------------------------------------------------------
|
26
|
-------------------------------------------------------------------------------
|
27
|
|
28
|
library ieee;
|
29
|
use ieee.std_logic_1164.all;
|
30
|
use ieee.numeric_std.all;
|
31
|
|
32
|
entity mt_reset_gen is
|
33
|
port (
|
34
|
clk : in std_logic; -- some direct clock-input
|
35
|
ext_rst : in std_logic; -- external reset
|
36
|
pll_locked : in std_logic; -- PLLs locked?
|
37
|
reset_pll : out std_logic; -- reset signal for PLLs
|
38
|
reset_sys : out std_logic -- global reset signal
|
39
|
);
|
40
|
end mt_reset_gen;
|
41
|
|
42
|
architecture rtl of mt_reset_gen is
|
43
|
|
44
|
-- reset generation
|
45
|
signal rst_roc2pll : std_logic_vector(15 downto 0) := (others=>'1'); -- delay between rst_roc <-> rst_pll
|
46
|
signal rst_pll2go : std_logic_vector( 5 downto 0) := (others=>'1'); -- delay between reset_pll <-> reset_I
|
47
|
signal reset_pll_i : std_logic := '1'; -- inner version of 'reset_pll'
|
48
|
signal reset_sys_i : std_logic; -- inner version of 'reset_sys'
|
49
|
|
50
|
-- TODO
|
51
|
signal lockcnt : unsigned(15 downto 0) := (others=>'0');
|
52
|
signal relock : std_logic := '0';
|
53
|
|
54
|
begin
|
55
|
|
56
|
-- generate PLL-reset
|
57
|
process(clk)
|
58
|
begin
|
59
|
if rising_edge(clk) then
|
60
|
-- if ext_rst='0' or relock='1' then
|
61
|
if relock='1' then
|
62
|
rst_roc2pll <= (others=>'1');
|
63
|
reset_pll_i <= '1';
|
64
|
else
|
65
|
rst_roc2pll <= '0' & rst_roc2pll(rst_roc2pll'high downto 1);
|
66
|
reset_pll_i <= rst_roc2pll(0);
|
67
|
end if;
|
68
|
end if;
|
69
|
end process;
|
70
|
|
71
|
-- TODO
|
72
|
process(clk)
|
73
|
begin
|
74
|
if rising_edge(clk) then
|
75
|
-- if ext_rst='0' or pll_locked='1' or relock='1' then
|
76
|
if pll_locked='1' or relock='1' then
|
77
|
lockcnt <= to_unsigned(0,16);
|
78
|
relock <= '0';
|
79
|
else
|
80
|
lockcnt <= lockcnt+1;
|
81
|
if lockcnt=30000-1 then
|
82
|
relock <= '1';
|
83
|
end if;
|
84
|
end if;
|
85
|
end if;
|
86
|
end process;
|
87
|
|
88
|
-- generate system-reset
|
89
|
process(clk, reset_pll_i)
|
90
|
begin
|
91
|
if reset_pll_i = '1' then
|
92
|
reset_sys_i <= '1';
|
93
|
rst_pll2go <= (others=>'1');
|
94
|
elsif rising_edge(clk) then
|
95
|
if pll_locked='0' then
|
96
|
rst_pll2go <= (others=>'1');
|
97
|
reset_sys_i <= '1';
|
98
|
else
|
99
|
rst_pll2go <= '0' & rst_pll2go(rst_pll2go'high downto 1);
|
100
|
reset_sys_i <= rst_pll2go(0);
|
101
|
end if;
|
102
|
end if;
|
103
|
end process;
|
104
|
|
105
|
-- output reset-signal
|
106
|
reset_sys <= reset_sys_i;
|
107
|
|
108
|
-- output PLL-reset
|
109
|
reset_pll <= reset_pll_i;
|
110
|
end;
|
111
|
|
112
|
|
113
|
-------------------------------------------------------------------------------
|
114
|
-- mt_reset_sync --------------------------------------------------------------
|
115
|
-------------------------------------------------------------------------------
|
116
|
|
117
|
library ieee;
|
118
|
use ieee.std_logic_1164.all;
|
119
|
|
120
|
entity mt_reset_sync is
|
121
|
port (
|
122
|
clk : in std_logic;
|
123
|
rst_in : in std_logic;
|
124
|
rst_out : out std_logic
|
125
|
);
|
126
|
end mt_reset_sync;
|
127
|
|
128
|
architecture rtl of mt_reset_sync is
|
129
|
signal taps : std_logic_vector(3 downto 0);
|
130
|
begin
|
131
|
process(clk, rst_in)
|
132
|
begin
|
133
|
if rst_in='1' then
|
134
|
taps <= (others=>'1');
|
135
|
rst_out <= '1';
|
136
|
elsif rising_edge(clk) then
|
137
|
taps <= "0" & taps(taps'high downto 1);
|
138
|
rst_out <= taps(0);
|
139
|
end if;
|
140
|
end process;
|
141
|
end;
|