summaryrefslogtreecommitdiffstats
path: root/fpga/hw-v2/src/usbrx/toplevel/usbrx_clkgen.vhd
blob: b1fc9a8376b39e97b4944a65811c21e9227bc491 (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
149
150
151
152
153
154
---------------------------------------------------------------------------------------------------
-- Filename    : usbrx_clkgen.vhd
-- Project     : OsmoSDR FPGA Firmware
-- Purpose     : Clock Management
---------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
-- written by Matthias Kleffel                                                   --
--                                                                               --
-- This program is free software; you can redistribute it and/or modify          --
-- it under the terms of the GNU General Public License as published by          --
-- the Free Software Foundation as version 3 of the License, or                  --
--                                                                               --
-- This program is distributed in the hope that it will be useful,               --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of                --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  --
-- GNU General Public License V3 for more details.                               --
--                                                                               --
-- You should have received a copy of the GNU General Public License             --
-- along with this program. If not, see <http://www.gnu.org/licenses/>.          --
-----------------------------------------------------------------------------------

library ieee;
	use ieee.std_logic_1164.all;
	use ieee.std_logic_misc.all;
	use ieee.numeric_std.all;
library xp2;
	use xp2.all;
	use xp2.components.all;
library work;
	use work.all;
	use work.mt_toolbox.all;
	
entity usbrx_clkgen is
	port(
		-- clock input
		clk_30_pclk	: in  std_logic;		-- 30MHz
		ext_rst     : in  std_logic;		-- external reset
	
		-- system clock
		clk_30 		: out std_logic;		-- 30MHz clock
		clk_80 		: out std_logic;		-- 80MHz clock
		rst_30	 	: out std_logic;		-- 30MHz reset
		rst_80	 	: out std_logic			-- 80MHz reset
	);
end usbrx_clkgen;

architecture rtl of usbrx_clkgen is

	-- reset generation
	signal rst_pll 		: std_logic;		-- reset signal for PLLs
	signal pll_locked	: std_logic;		-- PLLs locked
	signal reset_i	 	: std_logic;		-- reset-signal
	
	-- system clock management
	signal clk_80_pll	: std_logic;
	
	-- enusure that signal-names are kept (important for timing contraints)
	attribute syn_keep of clk_80_pll : signal is true;
	
	-- component declaration
    component EPLLD1
        generic (CLKOK_BYPASS : in String; CLKOS_BYPASS : in String; 
                CLKOP_BYPASS : in String; DUTY : in Integer; 
                PHASEADJ : in String; PHASE_CNTL : in String; 
                CLKOK_DIV : in Integer; CLKFB_DIV : in Integer; 
                CLKOP_DIV : in Integer; CLKI_DIV : in Integer;
                FIN  : in String);
        port (CLKI: in std_logic; CLKFB: in std_logic; RST: in std_logic; 
            RSTK: in std_logic; DPAMODE: in std_logic; DRPAI3: in std_logic; 
            DRPAI2: in std_logic; DRPAI1: in std_logic; DRPAI0: in std_logic; 
            DFPAI3: in std_logic; DFPAI2: in std_logic; DFPAI1: in std_logic; 
            DFPAI0: in std_logic; PWD: in std_logic; CLKOP: out std_logic; 
            CLKOS: out std_logic; CLKOK: out std_logic; LOCK: out std_logic; 
            CLKINTFB: out std_logic);
    end component;
			
begin

	--
	-- reset generation
	--
	
	-- generate asynchronous reset-signal
	rg: entity mt_reset_gen
		port map (
			clk 		=> clk_30_pclk,
			ext_rst     => ext_rst,
			pll_locked	=> pll_locked,
			reset_pll	=> rst_pll,
			reset_sys	=> reset_i
		);
	
	-- sync reset to clock-domains
	rs30: entity mt_reset_sync
		port map (
			clk     => clk_30_pclk,
			rst_in  => reset_i, 
			rst_out => rst_30
		);
	rs80: entity mt_reset_sync
		port map (
			clk     => clk_80_pll,
			rst_in  => reset_i, 
			rst_out => rst_80
		);

	--
	-- system clock
	--
	
	-- PLL for system-clock
    pll : EPLLD1
		generic map (
			FIN          => "30.0",
			CLKOK_BYPASS => "DISABLED",
			CLKOS_BYPASS => "DISABLED", 
			CLKOP_BYPASS => "DISABLED", 
			PHASE_CNTL   => "STATIC", 
			DUTY         => 8, 
			PHASEADJ     => "0.0",
			CLKOK_DIV    => 2,
			CLKOP_DIV    => 8,
			CLKFB_DIV    => 8, 
			CLKI_DIV     => 3
		)
		port map (
			CLKI    => clk_30_pclk,
			CLKFB   => clk_80_pll,
			RST     => rst_pll, 
			RSTK    => '0', 
			DPAMODE => '0',
			DRPAI3  => '0', 
			DRPAI2  => '0',
			DRPAI1  => '0',
			DRPAI0  => '0', 
			DFPAI3  => '0',
			DFPAI2  => '0',
			DFPAI1  => '0', 
			DFPAI0  => '0',
			PWD     => '0',
			CLKOP   => clk_80_pll, 
			CLKOS   => open, 
			CLKOK   => open,
			LOCK    => pll_locked,
			CLKINTFB=> open
		);
			
	-- output clocks
	clk_30 <= clk_30_pclk;
	clk_80 <= clk_80_pll;
	
end rtl;