OpenCores
URL https://opencores.org/ocsvn/astron_mm/astron_mm/trunk

Subversion Repositories astron_mm

[/] [astron_mm/] [trunk/] [common_reg_r_w_dc.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2012
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
-- Purpose: Provide dual clock domain crossing to common_reg_r_w.vhd
23
-- Description:
24
-- . Write vector to out_reg
25
-- . Read vector from in_reg or readback from out_reg
26
--
27
--   31             24 23             16 15              8 7               0  wi
28
--  |-----------------|-----------------|-----------------|-----------------|
29
--  |                              data[31:0]                               |  0
30
--  |-----------------------------------------------------------------------|
31
--  |                              data[63:32]                              |  1
32
--  |-----------------------------------------------------------------------|
33
--
34
-- . g_readback
35
--   When g_readback is TRUE then the written data is read back from the st_clk
36
--   domain directly into the mm_clk domain, so without ST --> MM clock domain
37
--   crossing logic. This is allowed because the read back value is stable. 
38
--   For readback the out_reg needs to be connected to in_reg, independent of
39
--   the g_readback setting, because the readback value is read back from the
40
--   st_clk domain. In this way the readback value also reveals that the 
41
--   written value is indeed available in the st_clk domain (ie. this shows 
42
--   that the st_clk is active). If g_cross_clock_domain=FALSE, then g_readback
43
--   is don't care.
44
--   In fact g_readback could better be called g_st_readback. An alternative
45
--   g_mm_readback could define direct read back in the MM clock domain and
46
--   would allow leaving the in_reg not connected.
47
 
48
LIBRARY IEEE, common_pkg_lib, common_components_lib, common_ram_lib;
49
USE IEEE.STD_LOGIC_1164.ALL;
50
USE common_pkg_lib.common_pkg.ALL;
51
USE common_ram_lib.common_ram_pkg.ALL;
52
 
53
ENTITY common_reg_r_w_dc IS
54
  GENERIC (
55
    g_cross_clock_domain : BOOLEAN := TRUE;  -- use FALSE when mm_clk and st_clk are the same, else use TRUE to cross the clock domain
56
    g_in_new_latency     : NATURAL := 0;  -- >= 0
57
    g_readback           : BOOLEAN := FALSE;  -- must use FALSE for write/read or read only register when g_cross_clock_domain=TRUE
58
    --g_readback           : BOOLEAN := TRUE;   -- can use TRUE for write and readback register
59
    g_reg                : t_c_mem := c_mem_reg;
60
    g_init_reg           : STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
61
  );
62
  PORT (
63
    -- Clocks and reset
64
    mm_rst      : IN  STD_LOGIC;   -- reset synchronous with mm_clk
65
    mm_clk      : IN  STD_LOGIC;   -- memory-mapped bus clock
66
    st_rst      : IN  STD_LOGIC;   -- reset synchronous with st_clk
67
    st_clk      : IN  STD_LOGIC;   -- other clock domain clock
68
 
69
    -- Memory Mapped Slave in mm_clk domain
70
    sla_in      : IN  t_mem_mosi;  -- actual ranges defined by g_reg
71
    sla_out     : OUT t_mem_miso;  -- actual ranges defined by g_reg
72
 
73
    -- MM registers in st_clk domain
74
    reg_wr_arr  : OUT STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
75
    reg_rd_arr  : OUT STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
76
    in_new      : IN  STD_LOGIC := '1';
77
    in_reg      : IN  STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
78
    out_reg     : OUT STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
79
    out_new     : OUT STD_LOGIC    -- Pulses '1' when new data has been written. 
80
  );
81
END common_reg_r_w_dc;
82
 
83
 
84
ARCHITECTURE str OF common_reg_r_w_dc IS
85
 
86
  -- Registers in mm_clk domain
87
  SIGNAL vector_wr_arr   : STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
88
  SIGNAL vector_rd_arr   : STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
89
  SIGNAL out_vector      : STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
90
  SIGNAL in_vector       : STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
91
 
92
  -- Initialize output to avoid Warning: (vsim-8684) No drivers exist on out port *, and its initial value is not used
93
  SIGNAL i_sla_out       : t_mem_miso := c_mem_miso_rst;
94
 
95
  SIGNAL reg_wr_arr_i    : STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
96
  SIGNAL wr_pulse        : STD_LOGIC;
97
  SIGNAL toggle          : STD_LOGIC;
98
  SIGNAL out_new_i       : STD_LOGIC;
99
 
100
BEGIN
101
 
102
  ------------------------------------------------------------------------------
103
  -- MM register access in the mm_clk domain
104
  ------------------------------------------------------------------------------
105
 
106
  sla_out <= i_sla_out;
107
 
108
  u_reg : ENTITY work.common_reg_r_w
109
  GENERIC MAP (
110
    g_reg      => g_reg,
111
    g_init_reg => g_init_reg
112
  )
113
  PORT MAP (
114
    rst         => mm_rst,
115
    clk         => mm_clk,
116
    -- control side
117
    wr_en       => sla_in.wr,
118
    wr_adr      => sla_in.address(g_reg.adr_w-1 DOWNTO 0),
119
    wr_dat      => sla_in.wrdata(g_reg.dat_w-1 DOWNTO 0),
120
    rd_en       => sla_in.rd,
121
    rd_adr      => sla_in.address(g_reg.adr_w-1 DOWNTO 0),
122
    rd_dat      => i_sla_out.rddata(g_reg.dat_w-1 DOWNTO 0),
123
    rd_val      => i_sla_out.rdval,
124
    -- data side
125
    reg_wr_arr  => vector_wr_arr,
126
    reg_rd_arr  => vector_rd_arr,
127
    out_reg     => out_vector,
128
    in_reg      => in_vector
129
  );
130
 
131
 
132
  ------------------------------------------------------------------------------
133
  -- Transfer register value between mm_clk and st_clk domain.
134
  -- If the function of the register ensures that the value will not be used
135
  -- immediately when it was set, then the transfer between the clock domains
136
  -- can be done by wires only. Otherwise if the change in register value can
137
  -- have an immediate effect then the bit or word value needs to be transfered
138
  -- using:
139
  --
140
  -- . common_async            --> for single-bit level signal
141
  -- . common_spulse           --> for single-bit pulse signal
142
  -- . common_reg_cross_domain --> for a multi-bit (a word) signal
143
  --
144
  -- Typically always use a crossing component for the single bit signals (to
145
  -- be on the save side) and only use a crossing component for the word
146
  -- signals if it is necessary (to avoid using more logic than necessary).
147
  ------------------------------------------------------------------------------
148
 
149
  no_cross : IF g_cross_clock_domain = FALSE GENERATE
150
    in_vector   <= in_reg;
151
    out_reg     <= out_vector;
152
    reg_wr_arr  <= vector_wr_arr;
153
    reg_rd_arr  <= vector_rd_arr;
154
    out_new     <= vector_wr_arr(0);
155
  END GENERATE;  -- no_cross
156
 
157
  gen_cross : IF g_cross_clock_domain = TRUE GENERATE
158
 
159
    gen_rdback : IF g_readback=TRUE GENERATE
160
      in_vector <= in_reg;
161
    END GENERATE;
162
 
163
    gen_rd : IF g_readback=FALSE GENERATE
164
      u_in_vector : ENTITY work.common_reg_cross_domain
165
      GENERIC MAP (
166
        g_in_new_latency => g_in_new_latency
167
      )
168
      PORT MAP (
169
        in_rst      => st_rst,
170
        in_clk      => st_clk,
171
        in_new      => in_new,
172
        in_dat      => in_reg,
173
        in_done     => OPEN,
174
        out_rst     => mm_rst,
175
        out_clk     => mm_clk,
176
        out_dat     => in_vector,
177
        out_new     => OPEN
178
      );
179
    END GENERATE;
180
 
181
    u_out_reg : ENTITY work.common_reg_cross_domain
182
    GENERIC MAP(
183
      g_out_dat_init => g_init_reg
184
    )
185
    PORT MAP (
186
      in_rst      => mm_rst,
187
      in_clk      => mm_clk,
188
      in_dat      => out_vector,
189
      in_done     => OPEN,
190
      out_rst     => st_rst,
191
      out_clk     => st_clk,
192
      out_dat     => out_reg,
193
      out_new     => out_new_i
194
    );
195
 
196
    u_toggle : ENTITY common_components_lib.common_switch
197
    GENERIC MAP (
198
      g_rst_level    => '0',
199
      g_priority_lo  => FALSE,
200
      g_or_high      => FALSE,
201
      g_and_low      => FALSE
202
    )
203
    PORT MAP (
204
      rst         => st_rst,
205
      clk         => st_clk,
206
      switch_high => wr_pulse,
207
      switch_low  => out_new_i,
208
      out_level   => toggle
209
    );
210
 
211
    wr_pulse   <= '0' WHEN vector_or(reg_wr_arr_i)='0' ELSE '1';
212
    out_new    <= out_new_i AND toggle;
213
    reg_wr_arr <= reg_wr_arr_i;
214
 
215
    gen_access_evt : FOR I IN 0 TO g_reg.nof_dat-1 GENERATE
216
      u_reg_wr_arr : ENTITY common_components_lib.common_spulse
217
      PORT MAP (
218
        in_rst    => mm_rst,
219
        in_clk    => mm_clk,
220
        in_pulse  => vector_wr_arr(I),
221
        in_busy   => OPEN,
222
        out_rst   => st_rst,
223
        out_clk   => st_clk,
224
        out_pulse => reg_wr_arr_i(I)
225
      );
226
 
227
      u_reg_rd_arr : ENTITY common_components_lib.common_spulse
228
      PORT MAP (
229
        in_rst    => mm_rst,
230
        in_clk    => mm_clk,
231
        in_pulse  => vector_rd_arr(I),
232
        in_busy   => OPEN,
233
        out_rst   => st_rst,
234
        out_clk   => st_clk,
235
        out_pulse => reg_rd_arr(I)
236
      );
237
    END GENERATE;
238
 
239
  END GENERATE;  -- gen_cross
240
 
241
END str;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.