1 |
42 |
lmaarsen |
--------------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- Ethernet Switch on Configurable Logic IP Core ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the ESoCL project ----
|
6 |
|
|
---- http://www.opencores.org/cores/esoc/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description: see design description ESoCL_dd_71022001.pdf ----
|
9 |
|
|
---- ----
|
10 |
|
|
---- To Do: see roadmap description ESoCL_dd_71022001.pdf ----
|
11 |
|
|
---- and/or release bulleting ESoCL_rb_71022001.pdf ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- Author(s): L.Maarsen ----
|
14 |
|
|
---- Bert Maarsen, lmaarsen@opencores.org ----
|
15 |
|
|
---- ----
|
16 |
|
|
--------------------------------------------------------------------------------
|
17 |
|
|
---- ----
|
18 |
|
|
---- Copyright (C) 2009 Authors and OPENCORES.ORG ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- This source file may be used and distributed without ----
|
21 |
|
|
---- restriction provided that this copyright statement is not ----
|
22 |
|
|
---- removed from the file and that any derivative work contains ----
|
23 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
24 |
|
|
---- ----
|
25 |
|
|
---- This source file is free software; you can redistribute it ----
|
26 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
27 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
28 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
29 |
|
|
---- later version. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- This source is distributed in the hope that it will be ----
|
32 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
33 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
34 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
35 |
|
|
---- details. ----
|
36 |
|
|
---- ----
|
37 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
38 |
|
|
---- Public License along with this source; if not, download it ----
|
39 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
40 |
|
|
---- ----
|
41 |
|
|
--------------------------------------------------------------------------------
|
42 |
|
|
-- Object : Entity work.esoc_port_mal_clock
|
43 |
|
|
-- Last modified : Mon Apr 14 12:49:01 2014.
|
44 |
|
|
--------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
library ieee, std, work;
|
49 |
|
|
use ieee.std_logic_1164.all;
|
50 |
|
|
use std.textio.all;
|
51 |
|
|
use ieee.numeric_std.all;
|
52 |
|
|
use work.package_esoc_configuration.all;
|
53 |
|
|
|
54 |
|
|
entity esoc_port_mal_clock is
|
55 |
|
|
port(
|
56 |
|
|
clk_control : in STD_LOGIC;
|
57 |
|
|
clk_rgmii : out std_logic;
|
58 |
|
|
clk_rgmii_125m : in std_logic;
|
59 |
|
|
clk_rgmii_25m : in std_logic;
|
60 |
|
|
clk_rgmii_2m5 : in std_logic;
|
61 |
|
|
ena_10 : in STD_LOGIC;
|
62 |
|
|
eth_mode : in STD_LOGIC;
|
63 |
|
|
reset : in STD_LOGIC;
|
64 |
|
|
set_10 : out STD_LOGIC := '0'; -- '0'
|
65 |
|
|
set_1000 : out STD_LOGIC := '0');
|
66 |
|
|
end entity esoc_port_mal_clock;
|
67 |
|
|
|
68 |
|
|
--------------------------------------------------------------------------------
|
69 |
|
|
-- Object : Architecture work.esoc_port_mal_clock.esoc_port_mal_clock
|
70 |
|
|
-- Last modified : Mon Apr 14 12:49:01 2014.
|
71 |
|
|
--------------------------------------------------------------------------------
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
architecture esoc_port_mal_clock of esoc_port_mal_clock is
|
75 |
|
|
|
76 |
|
|
constant clk_off: std_logic := '1';
|
77 |
|
|
constant clk_on: std_logic := '0';
|
78 |
|
|
|
79 |
|
|
signal clk125m: std_logic;
|
80 |
|
|
signal clk125_stop: std_logic;
|
81 |
|
|
signal clk125_stopped: std_logic;
|
82 |
|
|
signal clk125_stop_reg: std_logic_vector(1 downto 0);
|
83 |
|
|
signal clk125_stopped_reg: std_logic_vector(1 downto 0);
|
84 |
|
|
constant clk125m_reset: std_logic := clk_off;
|
85 |
|
|
|
86 |
|
|
signal clk25m: std_logic;
|
87 |
|
|
signal clk25_stop: std_logic;
|
88 |
|
|
signal clk25_stopped: std_logic;
|
89 |
|
|
signal clk25_stop_reg: std_logic_vector(1 downto 0);
|
90 |
|
|
signal clk25_stopped_reg: std_logic_vector(1 downto 0);
|
91 |
|
|
constant clk25m_reset: std_logic := clk_on;
|
92 |
|
|
|
93 |
|
|
signal clk2m5: std_logic;
|
94 |
|
|
signal clk2m5_stop: std_logic;
|
95 |
|
|
signal clk2m5_stopped: std_logic;
|
96 |
|
|
signal clk2m5_stop_reg: std_logic_vector(1 downto 0);
|
97 |
|
|
signal clk2m5_stopped_reg: std_logic_vector(1 downto 0);
|
98 |
|
|
constant clk2m5_reset: std_logic := clk_off;
|
99 |
|
|
|
100 |
|
|
type speeds is (none, s10m, s100m, s1000m);
|
101 |
|
|
signal speed_setting: speeds;
|
102 |
|
|
signal speed_current: speeds;
|
103 |
|
|
|
104 |
|
|
type switch_states is (idle, wait_for_stop);
|
105 |
|
|
signal switch_state: switch_states;
|
106 |
|
|
|
107 |
|
|
begin
|
108 |
|
|
|
109 |
|
|
-- Define unused speed control signals
|
110 |
|
|
set_10 <= '0';
|
111 |
|
|
set_1000 <= '0';
|
112 |
|
|
|
113 |
|
|
-- Create speed select signals
|
114 |
|
|
speed_setting <= s1000m when reset = '1' else
|
115 |
|
|
s10m when eth_mode = '0' and ena_10 = '1' else
|
116 |
|
|
s100m when eth_mode = '0' and ena_10 = '0' else
|
117 |
|
|
s1000m;
|
118 |
|
|
|
119 |
|
|
-- Clock control 125MHz
|
120 |
|
|
clk125ctl: process (clk_rgmii_125m, reset)
|
121 |
|
|
begin
|
122 |
|
|
if reset = '1' then
|
123 |
|
|
clk125_stop_reg <= (others => clk125m_reset);
|
124 |
|
|
|
125 |
|
|
-- synchronize stop input command with clock
|
126 |
|
|
elsif clk_rgmii_125m'event and clk_rgmii_125m = '1' then
|
127 |
|
|
clk125_stop_reg <= clk125_stop & clk125_stop_reg(clk125_stop_reg'high downto 1);
|
128 |
|
|
|
129 |
|
|
end if;
|
130 |
|
|
end process clk125ctl;
|
131 |
|
|
|
132 |
|
|
-- use synchronized stop commando to switch on/off clock, reply with stopped indication
|
133 |
|
|
clk125m <= clk_rgmii_125m when clk125_stop_reg(0) = '0' else '1';
|
134 |
|
|
clk125_stopped <= clk125_stop_reg(0);
|
135 |
|
|
|
136 |
|
|
-- Clock control 25MHz
|
137 |
|
|
clk25ctl: process (clk_rgmii_25m, reset)
|
138 |
|
|
begin
|
139 |
|
|
if reset = '1' then
|
140 |
|
|
clk25_stop_reg <= (others => clk25m_reset);
|
141 |
|
|
|
142 |
|
|
-- synchronize stop input command with clock
|
143 |
|
|
elsif clk_rgmii_25m'event and clk_rgmii_25m = '1' then
|
144 |
|
|
clk25_stop_reg <= clk25_stop & clk25_stop_reg(clk25_stop_reg'high downto 1);
|
145 |
|
|
|
146 |
|
|
end if;
|
147 |
|
|
end process clk25ctl;
|
148 |
|
|
|
149 |
|
|
-- use synchronized stop commando to switch on/off clock, reply with stopped indication
|
150 |
|
|
clk25m <= clk_rgmii_25m when clk25_stop_reg(0) = '0' else '1';
|
151 |
|
|
clk25_stopped <= clk25_stop_reg(0);
|
152 |
|
|
|
153 |
|
|
-- Clock control 2.5MHz
|
154 |
|
|
clk2m5ctl: process (clk_rgmii_2m5, reset)
|
155 |
|
|
begin
|
156 |
|
|
if reset = '1' then
|
157 |
|
|
clk2m5_stop_reg <= (others => clk2m5_reset);
|
158 |
|
|
|
159 |
|
|
-- synchronize stop input command with clock
|
160 |
|
|
elsif clk_rgmii_2m5'event and clk_rgmii_2m5 = '1' then
|
161 |
|
|
clk2m5_stop_reg <= clk2m5_stop & clk2m5_stop_reg(clk2m5_stop_reg'high downto 1);
|
162 |
|
|
|
163 |
|
|
end if;
|
164 |
|
|
end process clk2m5ctl;
|
165 |
|
|
|
166 |
|
|
-- use synchronized stop commando to switch on/off clock, reply with stopped indication
|
167 |
|
|
clk2m5 <= clk_rgmii_2m5 when clk2m5_stop_reg(0) = '0' else '1';
|
168 |
|
|
clk2m5_stopped <= clk2m5_stop_reg(0);
|
169 |
|
|
|
170 |
|
|
-- Clock switch
|
171 |
|
|
clkswitch: process (clk_control, reset)
|
172 |
|
|
begin
|
173 |
|
|
if reset = '1' then
|
174 |
|
|
clk125_stop <= clk125m_reset;
|
175 |
|
|
clk25_stop <= clk25m_reset;
|
176 |
|
|
clk2m5_stop <= clk2m5_reset;
|
177 |
|
|
clk125_stopped_reg <= (others => clk125m_reset);
|
178 |
|
|
clk25_stopped_reg <= (others => clk25m_reset);
|
179 |
|
|
clk2m5_stopped_reg <= (others => clk2m5_reset);
|
180 |
|
|
speed_current <= s1000m;
|
181 |
|
|
switch_state <= idle;
|
182 |
|
|
|
183 |
|
|
elsif clk_control'event and clk_control = '1' then
|
184 |
|
|
-- store speed setting for change detection
|
185 |
|
|
speed_current <= speed_setting;
|
186 |
|
|
|
187 |
|
|
-- synchronize stopped indication with clock
|
188 |
|
|
clk125_stopped_reg <= clk125_stopped & clk125_stopped_reg(clk125_stopped_reg'high downto 1);
|
189 |
|
|
clk25_stopped_reg <= clk25_stopped & clk25_stopped_reg(clk25_stopped_reg'high downto 1);
|
190 |
|
|
clk2m5_stopped_reg <= clk2m5_stopped & clk2m5_stopped_reg(clk2m5_stopped_reg'high downto 1);
|
191 |
|
|
|
192 |
|
|
case switch_state is
|
193 |
|
|
when idle => -- Send stop command to all clock source when setting changed
|
194 |
|
|
if speed_current /= speed_setting then
|
195 |
|
|
clk125_stop <= '1';
|
196 |
|
|
clk25_stop <= '1';
|
197 |
|
|
clk2m5_stop <= '1';
|
198 |
|
|
switch_state <= wait_for_stop;
|
199 |
|
|
end if;
|
200 |
|
|
|
201 |
|
|
when wait_for_stop => -- When setting is stable, wait for stopped indication of all clock sources
|
202 |
|
|
if speed_current /= speed_setting then
|
203 |
|
|
NULL;
|
204 |
|
|
|
205 |
|
|
elsif clk125_stopped_reg(0) = '1' and clk25_stopped_reg(0) = '1' and clk2m5_stopped_reg(0) = '1' then
|
206 |
|
|
-- enable only the required clock source by deasserting its stop input
|
207 |
|
|
if speed_setting = s10m then
|
208 |
|
|
clk2m5_stop <= '0';
|
209 |
|
|
elsif speed_setting = s100m then
|
210 |
|
|
clk25_stop <= '0';
|
211 |
|
|
elsif speed_setting = s1000m then
|
212 |
|
|
clk125_stop <= '0';
|
213 |
|
|
end if;
|
214 |
|
|
|
215 |
|
|
switch_state <= idle;
|
216 |
|
|
end if;
|
217 |
|
|
|
218 |
|
|
when others => switch_state <= idle;
|
219 |
|
|
end case;
|
220 |
|
|
|
221 |
|
|
end if;
|
222 |
|
|
end process clkswitch;
|
223 |
|
|
|
224 |
|
|
-- Drive RGMII interface clock, push/force clock onto clock network (if not done by tool)
|
225 |
|
|
clk_rgmii <= clk125m and clk25m and clk2m5;
|
226 |
|
|
--clk_rgmii <= clk_rgmii_125m;
|
227 |
|
|
|
228 |
|
|
end architecture esoc_port_mal_clock ; -- of esoc_port_mal_clock
|