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

Subversion Repositories astron_diagnostics

[/] [astron_diagnostics/] [trunk/] [diag_block_gen_reg.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-----------------------------------------------------------------------------      
2
--                                                                                 
3 3 danv
-- Copyright 2020
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
-- 
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
 
22 4 danv
library IEEE, common_pkg_lib, astron_ram_lib, common_components_lib;
23 2 danv
use IEEE.std_logic_1164.ALL;
24
use IEEE.numeric_std.ALL;
25
use common_pkg_lib.common_pkg.ALL;
26 4 danv
use astron_ram_lib.common_ram_pkg.ALL;
27 2 danv
use work.diag_pkg.ALL;
28
 
29
entity diag_block_gen_reg is
30
  generic (
31
    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
32
    g_diag_block_gen_rst : t_diag_block_gen := c_diag_block_gen_rst
33
  );
34
  port (
35
    mm_rst  : in  std_logic;                   -- Clocks and reset
36
    mm_clk  : in  std_logic;
37
    dp_rst  : in  std_logic := '0';
38
    dp_clk  : in  std_logic;
39
    mm_mosi : in  t_mem_mosi;                  -- Memory Mapped Slave in mm_clk domain
40
    mm_miso : out t_mem_miso       := c_mem_miso_rst;
41
    bg_ctrl : out t_diag_block_gen := g_diag_block_gen_rst
42
  );
43
end diag_block_gen_reg;
44
 
45
architecture rtl of diag_block_gen_reg is
46
 
47
  constant c_adrs_width : positive := c_diag_bg_reg_adr_w;
48
  signal   mm_bg_ctrl   : t_diag_block_gen := g_diag_block_gen_rst;
49
  signal   dp_bg_ctrl   : t_diag_block_gen := g_diag_block_gen_rst;
50
 
51
begin
52
 
53
  ------------------------------------------------------------------------------                                        
54
  -- MM register access in the mm_clk domain                                                                            
55
  -- . Hardcode the shared MM slave register directly in RTL instead of using                                           
56
  --   the common_reg_r_w instance. Directly using RTL is easier when the large                                         
57
  --   MM register has multiple different fields and with different read and                                            
58
  --   write options per field in one MM register.                                                                      
59
  ------------------------------------------------------------------------------                                        
60
 
61
  p_mm_reg : process (mm_rst, mm_clk)
62
  begin
63
    if(mm_rst = '1') then
64
      mm_miso    <= c_mem_miso_rst;
65
      mm_bg_ctrl <= g_diag_block_gen_rst;
66
    elsif(rising_edge(mm_clk)) then
67
      -- Read access defaults                                                                                           
68
      mm_miso.rdval <= '0';
69
      -- Write access: set register value                                                                               
70
      if(mm_mosi.wr = '1') then
71
        case TO_UINT(mm_mosi.address(c_adrs_width-1 downto 0)) is
72
          when 0 =>
73
            mm_bg_ctrl.enable                 <= mm_mosi.wrdata(0);
74
            mm_bg_ctrl.enable_sync            <= mm_mosi.wrdata(1);
75
          when 1 =>
76
            mm_bg_ctrl.samples_per_packet     <= mm_mosi.wrdata(c_diag_bg_samples_per_packet_w -1 downto 0);
77
          when 2 =>
78
            mm_bg_ctrl.blocks_per_sync        <= mm_mosi.wrdata(c_diag_bg_blocks_per_sync_w    -1 downto 0);
79
          when 3 =>
80
            mm_bg_ctrl.gapsize                <= mm_mosi.wrdata(c_diag_bg_gapsize_w            -1 downto 0);
81
          when 4 =>
82
            mm_bg_ctrl.mem_low_adrs           <= mm_mosi.wrdata(c_diag_bg_mem_low_adrs_w       -1 downto 0);
83
          when 5 =>
84
            mm_bg_ctrl.mem_high_adrs          <= mm_mosi.wrdata(c_diag_bg_mem_high_adrs_w      -1 downto 0);
85
          when 6 =>
86
            mm_bg_ctrl.bsn_init(31 downto  0) <= mm_mosi.wrdata(31 downto 0);
87
          when 7 =>
88
            mm_bg_ctrl.bsn_init(63 downto 32) <= mm_mosi.wrdata(31 downto 0);
89
          when others => null;  -- not used MM addresses
90
        end case;
91
      -- Read access: get register value                                                                                
92
      elsif mm_mosi.rd = '1' then
93
        mm_miso       <= c_mem_miso_rst;    -- set unused rddata bits to '0' when read                                  
94
        mm_miso.rdval <= '1';
95
        case TO_UINT(mm_mosi.address(c_adrs_width-1 downto 0)) is
96
          -- Read Block Sync
97
          when 0 =>
98
            mm_miso.rddata(0)                                          <= mm_bg_ctrl.enable;
99
            mm_miso.rddata(1)                                          <= mm_bg_ctrl.enable_sync;
100
          when 1 =>
101
            mm_miso.rddata(c_diag_bg_samples_per_packet_w -1 downto 0) <= mm_bg_ctrl.samples_per_packet;
102
          when 2 =>
103
            mm_miso.rddata(c_diag_bg_blocks_per_sync_w    -1 downto 0) <= mm_bg_ctrl.blocks_per_sync;
104
          when 3 =>
105
            mm_miso.rddata(c_diag_bg_gapsize_w            -1 downto 0) <= mm_bg_ctrl.gapsize;
106
          when 4 =>
107
            mm_miso.rddata(c_diag_bg_mem_low_adrs_w       -1 downto 0) <= mm_bg_ctrl.mem_low_adrs;
108
          when 5 =>
109
            mm_miso.rddata(c_diag_bg_mem_high_adrs_w      -1 downto 0) <= mm_bg_ctrl.mem_high_adrs;
110
          when 6 =>
111
            mm_miso.rddata(31 downto 0) <= mm_bg_ctrl.bsn_init(31 downto 0);
112
          when 7 =>
113
            mm_miso.rddata(31 downto 0) <= mm_bg_ctrl.bsn_init(63 downto 32);
114
          when others => null;  -- not used MM addresses
115
        end case;
116
      end if;
117
    end if;
118
  end process;
119
 
120
  ------------------------------------------------------------------------------                                        
121
  -- Transfer register value between mm_clk and dp_clk domain.                                                          
122
  -- If the function of the register ensures that the value will not be used                                            
123
  -- immediately when it was set, then the transfer between the clock domains                                           
124
  -- can be done by wires only. Otherwise if the change in register value can                                           
125
  -- have an immediate effect then the bit or word value needs to be transfered                                         
126
  -- using:                                                                                                             
127
  --                                                                                                                    
128
  -- . common_async            --> for single-bit level signal                                                          
129
  -- . common_spulse           --> for single-bit pulse signal                                                          
130
  -- . common_reg_cross_domain --> for a multi-bit (a word) signal                                                      
131
  --                                                                                                                    
132
  -- Typically always use a crossing component for the single bit signals (to                                           
133
  -- be on the save side) and only use a crossing component for the word                                                
134
  -- signals if it is necessary (to avoid using more logic than necessary).                                             
135
  ------------------------------------------------------------------------------                                        
136
 
137
  no_cross : if g_cross_clock_domain = FALSE generate
138
    dp_bg_ctrl <= mm_bg_ctrl;
139
  end generate;  -- no_cross                                                                                            
140
 
141
  gen_crossing : if g_cross_clock_domain = TRUE generate
142
    -- Assume diag BG enable gets written last, so when diag BG enable is transfered properly to the dp_clk domain, then
143
    -- the other diag BG control fields are stable as well
144
    u_bg_enable : entity common_components_lib.common_async
145
    generic map (
146
      g_rst_level => '0'
147
    )
148
    port map (
149
      rst  => dp_rst,
150
      clk  => dp_clk,
151
      din  => mm_bg_ctrl.enable,
152
      dout => dp_bg_ctrl.enable
153
    );
154
    dp_bg_ctrl.enable_sync        <= mm_bg_ctrl.enable_sync;
155
    dp_bg_ctrl.samples_per_packet <= mm_bg_ctrl.samples_per_packet;
156
    dp_bg_ctrl.blocks_per_sync    <= mm_bg_ctrl.blocks_per_sync;
157
    dp_bg_ctrl.gapsize            <= mm_bg_ctrl.gapsize;
158
    dp_bg_ctrl.mem_low_adrs       <= mm_bg_ctrl.mem_low_adrs;
159
    dp_bg_ctrl.mem_high_adrs      <= mm_bg_ctrl.mem_high_adrs;
160
    dp_bg_ctrl.bsn_init           <= mm_bg_ctrl.bsn_init;
161
  end generate;  -- gen_crossing                                                                                           
162
 
163
  bg_ctrl <= dp_bg_ctrl;
164
 
165
end rtl;

powered by: WebSVN 2.1.0

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