1 |
2 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
3 |
danv |
-- Copyright 2020
|
4 |
2 |
danv |
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
3 |
danv |
--
|
7 |
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
8 |
|
|
-- you may not use this file except in compliance with the License.
|
9 |
|
|
-- You may obtain a copy of the License at
|
10 |
|
|
--
|
11 |
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
|
--
|
13 |
|
|
-- Unless required by applicable law or agreed to in writing, software
|
14 |
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
15 |
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16 |
|
|
-- See the License for the specific language governing permissions and
|
17 |
|
|
-- limitations under the License.
|
18 |
2 |
danv |
--
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
|
21 |
4 |
danv |
LIBRARY IEEE, common_pkg_lib, common_components_lib, astron_ram_lib;
|
22 |
2 |
danv |
USE IEEE.std_logic_1164.ALL;
|
23 |
|
|
USE IEEE.numeric_std.ALL;
|
24 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
25 |
4 |
danv |
USE astron_ram_lib.common_ram_pkg.ALL;
|
26 |
2 |
danv |
|
27 |
|
|
-- Purpose: Get in_dat from in_clk to out_clk domain when in_new is asserted.
|
28 |
|
|
-- Remarks:
|
29 |
|
|
-- . If in_new is a pulse, then new in_dat is available after g_in_new_latency.
|
30 |
|
|
-- . It is also allowed to hold in_new high, then out_new will pulse once for
|
31 |
|
|
-- every 24 out_clk cycles.
|
32 |
|
|
-- . Use in_done to be sure that in_dat due to in_new has crossed the clock
|
33 |
|
|
-- domain, in case of multiple in_new pulses in a row the in_done will only
|
34 |
|
|
-- pulse when this state remains s_idle, so after the last in_new.
|
35 |
|
|
-- . If the in_dat remains unchanged during the crossing of in_new to out_en
|
36 |
|
|
-- then g_input_buf=FALSE may be used to save some flipflops
|
37 |
|
|
|
38 |
|
|
ENTITY common_reg_cross_domain IS
|
39 |
|
|
GENERIC (
|
40 |
|
|
g_input_buf : BOOLEAN := TRUE;
|
41 |
|
|
g_in_new_latency : NATURAL := 0; -- >= 0
|
42 |
|
|
g_out_dat_init : STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
|
43 |
|
|
);
|
44 |
|
|
PORT (
|
45 |
|
|
in_rst : IN STD_LOGIC;
|
46 |
|
|
in_clk : IN STD_LOGIC;
|
47 |
|
|
in_new : IN STD_LOGIC := '1'; -- when '1' then new in_dat is available after g_in_new_latency
|
48 |
|
|
in_dat : IN STD_LOGIC_VECTOR;
|
49 |
|
|
in_done : OUT STD_LOGIC; -- pulses when no more pending in_new
|
50 |
|
|
out_rst : IN STD_LOGIC;
|
51 |
|
|
out_clk : IN STD_LOGIC;
|
52 |
|
|
out_dat : OUT STD_LOGIC_VECTOR;
|
53 |
|
|
out_new : OUT STD_LOGIC -- when '1' then the out_dat was updated with in_dat due to in_new
|
54 |
|
|
);
|
55 |
|
|
END common_reg_cross_domain;
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
ARCHITECTURE rtl OF common_reg_cross_domain IS
|
59 |
|
|
|
60 |
|
|
CONSTANT c_dat : STD_LOGIC_VECTOR(in_dat'RANGE) := g_out_dat_init(in_dat'RANGE);
|
61 |
|
|
|
62 |
|
|
------------------------------------------------------------------------------
|
63 |
|
|
-- in_clk domain
|
64 |
|
|
------------------------------------------------------------------------------
|
65 |
|
|
SIGNAL reg_new : STD_LOGIC_VECTOR(0 TO g_in_new_latency) := (OTHERS=>'0');
|
66 |
|
|
SIGNAL nxt_reg_new : STD_LOGIC_VECTOR(reg_new'RANGE);
|
67 |
|
|
|
68 |
|
|
SIGNAL in_buf : STD_LOGIC_VECTOR(c_dat'RANGE) := c_dat;
|
69 |
|
|
SIGNAL in_buf_reg : STD_LOGIC_VECTOR(c_dat'RANGE) := c_dat;
|
70 |
|
|
SIGNAL nxt_in_buf_reg : STD_LOGIC_VECTOR(c_dat'RANGE);
|
71 |
|
|
|
72 |
|
|
-- Register access clock domain crossing
|
73 |
|
|
TYPE t_state_enum IS (s_idle, s_busy);
|
74 |
|
|
|
75 |
|
|
SIGNAL cross_req : STD_LOGIC;
|
76 |
|
|
SIGNAL cross_busy : STD_LOGIC;
|
77 |
|
|
SIGNAL nxt_in_done : STD_LOGIC;
|
78 |
|
|
SIGNAL state : t_state_enum;
|
79 |
|
|
SIGNAL nxt_state : t_state_enum;
|
80 |
|
|
SIGNAL prev_state : t_state_enum;
|
81 |
|
|
SIGNAL in_new_hold : STD_LOGIC;
|
82 |
|
|
SIGNAL nxt_in_new_hold : STD_LOGIC;
|
83 |
|
|
|
84 |
|
|
------------------------------------------------------------------------------
|
85 |
|
|
-- out_clk domain
|
86 |
|
|
------------------------------------------------------------------------------
|
87 |
|
|
SIGNAL out_en : STD_LOGIC;
|
88 |
|
|
SIGNAL i_out_dat : STD_LOGIC_VECTOR(c_dat'RANGE) := c_dat; -- register init without physical reset
|
89 |
|
|
SIGNAL nxt_out_dat : STD_LOGIC_VECTOR(c_dat'RANGE);
|
90 |
|
|
|
91 |
|
|
BEGIN
|
92 |
|
|
|
93 |
|
|
out_dat <= i_out_dat;
|
94 |
|
|
|
95 |
|
|
------------------------------------------------------------------------------
|
96 |
|
|
-- in_clk domain
|
97 |
|
|
------------------------------------------------------------------------------
|
98 |
|
|
|
99 |
|
|
reg_new(0) <= in_new;
|
100 |
|
|
|
101 |
|
|
gen_latency : IF g_in_new_latency>0 GENERATE
|
102 |
|
|
p_reg_new : PROCESS(in_rst, in_clk)
|
103 |
|
|
BEGIN
|
104 |
|
|
IF in_rst='1' THEN
|
105 |
|
|
reg_new(1 TO g_in_new_latency) <= (OTHERS=>'0');
|
106 |
|
|
ELSIF rising_edge(in_clk) THEN
|
107 |
|
|
reg_new(1 TO g_in_new_latency) <= nxt_reg_new(1 TO g_in_new_latency);
|
108 |
|
|
END IF;
|
109 |
|
|
END PROCESS;
|
110 |
|
|
|
111 |
|
|
nxt_reg_new(1 TO g_in_new_latency) <= reg_new(0 TO g_in_new_latency-1);
|
112 |
|
|
END GENERATE;
|
113 |
|
|
|
114 |
|
|
p_in_clk : PROCESS(in_rst, in_clk)
|
115 |
|
|
BEGIN
|
116 |
|
|
IF in_rst='1' THEN
|
117 |
|
|
in_new_hold <= '0';
|
118 |
|
|
in_done <= '0';
|
119 |
|
|
state <= s_idle;
|
120 |
|
|
prev_state <= s_idle;
|
121 |
|
|
ELSIF rising_edge(in_clk) THEN
|
122 |
|
|
in_buf_reg <= nxt_in_buf_reg;
|
123 |
|
|
in_new_hold <= nxt_in_new_hold;
|
124 |
|
|
in_done <= nxt_in_done;
|
125 |
|
|
state <= nxt_state;
|
126 |
|
|
prev_state <= state;
|
127 |
|
|
END IF;
|
128 |
|
|
END PROCESS;
|
129 |
|
|
|
130 |
|
|
-- capture the new register data
|
131 |
|
|
no_in_buf : IF g_input_buf=FALSE GENERATE
|
132 |
|
|
in_buf <= in_dat; -- assumes that in_dat remains unchanged during the crossing of in_new to out_en
|
133 |
|
|
END GENERATE;
|
134 |
|
|
|
135 |
|
|
gen_in_buf : IF g_input_buf=TRUE GENERATE
|
136 |
|
|
nxt_in_buf_reg <= in_dat WHEN cross_req='1' ELSE in_buf_reg;
|
137 |
|
|
in_buf <= in_buf_reg;
|
138 |
|
|
END GENERATE;
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
-- handshake control of the clock domain crossing by u_cross_req
|
142 |
|
|
-- hold any subsequent in_new during cross domain busy to ensure that the out_dat will get the latest value of in_dat
|
143 |
|
|
p_state : PROCESS(state, prev_state, reg_new, in_new_hold, cross_busy)
|
144 |
|
|
BEGIN
|
145 |
|
|
cross_req <= '0';
|
146 |
|
|
nxt_in_done <= '0';
|
147 |
|
|
nxt_in_new_hold <= in_new_hold;
|
148 |
|
|
nxt_state <= state;
|
149 |
|
|
CASE state IS
|
150 |
|
|
WHEN s_idle =>
|
151 |
|
|
nxt_in_new_hold <= '0';
|
152 |
|
|
IF reg_new(g_in_new_latency)='1' OR in_new_hold='1' THEN
|
153 |
|
|
cross_req <= '1';
|
154 |
|
|
nxt_state <= s_busy;
|
155 |
|
|
ELSIF UNSIGNED(reg_new)=0 AND prev_state=s_busy THEN
|
156 |
|
|
nxt_in_done <= '1'; -- no pending in_new at input or in shift register and just left s_busy, so signal in_done
|
157 |
|
|
END IF;
|
158 |
|
|
WHEN OTHERS => -- s_busy
|
159 |
|
|
IF reg_new(g_in_new_latency)='1' THEN
|
160 |
|
|
nxt_in_new_hold <= '1';
|
161 |
|
|
END IF;
|
162 |
|
|
IF cross_busy='0' THEN
|
163 |
|
|
nxt_state <= s_idle;
|
164 |
|
|
END IF;
|
165 |
|
|
END CASE;
|
166 |
|
|
END PROCESS;
|
167 |
|
|
|
168 |
|
|
------------------------------------------------------------------------------
|
169 |
|
|
-- cross clock domain
|
170 |
|
|
------------------------------------------------------------------------------
|
171 |
|
|
u_cross_req : ENTITY common_components_lib.common_spulse
|
172 |
|
|
PORT MAP (
|
173 |
|
|
in_rst => in_rst,
|
174 |
|
|
in_clk => in_clk,
|
175 |
|
|
in_pulse => cross_req,
|
176 |
|
|
in_busy => cross_busy,
|
177 |
|
|
out_rst => out_rst,
|
178 |
|
|
out_clk => out_clk,
|
179 |
|
|
out_pulse => out_en
|
180 |
|
|
);
|
181 |
|
|
|
182 |
|
|
------------------------------------------------------------------------------
|
183 |
|
|
-- out_clk domain
|
184 |
|
|
------------------------------------------------------------------------------
|
185 |
|
|
p_out_clk : PROCESS(out_rst, out_clk)
|
186 |
|
|
BEGIN
|
187 |
|
|
IF out_rst='1' THEN
|
188 |
|
|
out_new <= '0';
|
189 |
|
|
ELSIF rising_edge(out_clk) THEN
|
190 |
|
|
i_out_dat <= nxt_out_dat;
|
191 |
|
|
out_new <= out_en;
|
192 |
|
|
END IF;
|
193 |
|
|
END PROCESS;
|
194 |
|
|
|
195 |
|
|
-- some clock cycles after the cross_req the in_buf data is stable for sure
|
196 |
|
|
nxt_out_dat <= in_buf WHEN out_en='1' ELSE i_out_dat;
|
197 |
|
|
|
198 |
|
|
END rtl;
|