1 |
2 |
craighaywo |
----------------------------------------------------------------------------------
|
2 |
|
|
-- This program is free software; you can redistribute it and/or
|
3 |
|
|
-- modify it under the terms of the GNU General Public License
|
4 |
|
|
-- as published by the Free Software Foundation; either version 2
|
5 |
|
|
-- of the License, or (at your option) any later version.
|
6 |
|
|
--
|
7 |
|
|
-- This program is distributed in the hope that it will be useful,
|
8 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10 |
|
|
-- GNU General Public License for more details.
|
11 |
|
|
--
|
12 |
|
|
-- You should have received a copy of the GNU General Public License
|
13 |
|
|
-- along with this program; if not, write to the Free Software
|
14 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
15 |
|
|
-- 02111-1307, USA.
|
16 |
|
|
--
|
17 |
|
|
-- ©2011 - X Engineering Software Systems Corp. (www.xess.com)
|
18 |
|
|
----------------------------------------------------------------------------------
|
19 |
|
|
|
20 |
|
|
----------------------------------------------------------------------------------
|
21 |
|
|
-- Modules for passing bits into a clock domain.
|
22 |
|
|
----------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
library IEEE;
|
26 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
27 |
|
|
|
28 |
|
|
package SyncToClockPckg is
|
29 |
|
|
|
30 |
|
|
-- Pass a bit into a clock domain.
|
31 |
|
|
component SyncToClock is
|
32 |
|
|
port (
|
33 |
|
|
clk_i : in std_logic; -- Clock for the domain being entered.
|
34 |
|
|
unsynced_i : in std_logic; -- Signal that is entering domain.
|
35 |
|
|
synced_o : out std_logic -- Signal sync'ed to clock domain
|
36 |
|
|
);
|
37 |
|
|
end component;
|
38 |
|
|
|
39 |
|
|
-- Pass a bus into a clock domain.
|
40 |
|
|
component SyncBusToClock is
|
41 |
|
|
port (
|
42 |
|
|
clk_i : in std_logic; -- Clock for the domain being entered.
|
43 |
|
|
unsynced_i : in std_logic_vector; -- Bus signal that is entering domain.
|
44 |
|
|
synced_o : out std_logic_vector -- Bus signal sync'ed to clock domain
|
45 |
|
|
);
|
46 |
|
|
end component;
|
47 |
|
|
|
48 |
|
|
end package;
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
library IEEE;
|
53 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
54 |
|
|
|
55 |
|
|
entity SyncToClock is
|
56 |
|
|
port (
|
57 |
|
|
clk_i : in std_logic; -- Clock for the domain being entered.
|
58 |
|
|
unsynced_i : in std_logic; -- Signal that is entering domain.
|
59 |
|
|
synced_o : out std_logic -- Signal sync'ed to clock domain
|
60 |
|
|
);
|
61 |
|
|
end entity;
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
architecture arch of SyncToClock is
|
65 |
|
|
constant syncStages_c : natural := 2; -- Number of stages in the sync'ing register.
|
66 |
|
|
-- This is the sync'ing shift register. The index indicates the number of clocked flip-flops the incoming signal
|
67 |
|
|
-- has passed through, so sync_r(1) is one clk_i cycle stage, sync_r(2) is two cycles, etc.
|
68 |
|
|
signal sync_r : std_logic_vector(syncStages_c downto 1);
|
69 |
|
|
begin
|
70 |
|
|
process(clk_i)
|
71 |
|
|
begin
|
72 |
|
|
if rising_edge(clk_i) then
|
73 |
|
|
-- Shift the unsync'ed signal into one end of the sync'ing register.
|
74 |
|
|
sync_r <= sync_r(syncStages_c-1 downto 1) & unsynced_i;
|
75 |
|
|
end if;
|
76 |
|
|
end process;
|
77 |
|
|
-- Output the sync'ed signal from the other end of the shift register.
|
78 |
|
|
synced_o <= sync_r(syncStages_c);
|
79 |
|
|
end architecture;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
library IEEE;
|
84 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
85 |
|
|
use work.SyncToClockPckg.all;
|
86 |
|
|
|
87 |
|
|
entity SyncBusToClock is
|
88 |
|
|
port (
|
89 |
|
|
clk_i : in std_logic; -- Clock for the domain being entered.
|
90 |
|
|
unsynced_i : in std_logic_vector; -- Bus signal that is entering domain.
|
91 |
|
|
synced_o : out std_logic_vector -- Bus signal sync'ed to clock domain
|
92 |
|
|
);
|
93 |
|
|
end entity;
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
architecture arch of SyncBusToClock is
|
97 |
|
|
begin
|
98 |
|
|
SyncLoop : for i in unsynced_i'range generate
|
99 |
|
|
begin
|
100 |
|
|
USyncBit : component SyncToClock
|
101 |
|
|
port map(
|
102 |
|
|
clk_i => clk_i,
|
103 |
|
|
unsynced_i => unsynced_i(i),
|
104 |
|
|
synced_o => synced_o(i)
|
105 |
|
|
);
|
106 |
|
|
end generate;
|
107 |
|
|
end architecture;
|