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

Subversion Repositories astron_mm

[/] [astron_mm/] [trunk/] [common_reg_r_w.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) 2009
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
LIBRARY IEEE, common_pkg_lib, common_components_lib, common_ram_lib;
23
USE IEEE.STD_LOGIC_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
USE common_ram_lib.common_ram_pkg.ALL;
27
 
28
-- Derived from LOFAR cfg_single_reg
29
 
30
-- Purpose: Provide a MM interface to a register vector
31
--
32
-- Description:
33
--   The register has g_reg.nof_dat words and each word is g_reg.dat_w bits 
34
--   wide. At the control side the register is accessed per word using the
35
--   address input wr_adr or rd_adr as index. At the data side the whole
36
--   register of g_reg.dat_w*g_reg.nof_dat bits is available at once. This is
37
--   the key difference with using a RAM.
38
--   E.g. for g_reg.nof_dat = 3 and g_reg.dat_w = 32 the addressing accesses
39
--   the register bits as follows:
40
--     wr_adr[1:0], rd_adr[1:0] = 0 --> reg[31:0]
41
--     wr_adr[1:0], rd_adr[1:0] = 1 --> reg[63:32]
42
--     wr_adr[1:0], rd_adr[1:0] = 2 --> reg[95:64]
43
--   E.g. for wr_adr = 0 and wr_en = '1': out_reg[31:0] = wr_dat[31:0]
44
--   E.g. for rd_adr = 0 and rd_en = '1':  rd_dat[31:0] = in_reg[31:0]
45
--
46
--   The word in the register that got accessed is reported via reg_wr_arr
47
--   or via reg_rd_arr depended on whether it was a write access or an read
48
--   access.
49
--
50
-- Usage:
51
-- 1) Connect out_reg to in_reg for write and readback register.
52
-- 2) Do not connect out_reg to in_reg for seperate write only register and
53
--    read only register at the same address.
54
-- 3) Leave out_reg OPEN for read only register.
55
-- 4) Connect wr_adr and rd_adr to have a shared address bus register.
56
 
57
ENTITY common_reg_r_w IS
58
  GENERIC (
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
    rst         : IN  STD_LOGIC := '0';
64
    clk         : IN  STD_LOGIC;
65
    clken       : IN  STD_LOGIC := '1';
66
    -- control side
67
    wr_en       : IN  STD_LOGIC;
68
    wr_adr      : IN  STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
69
    wr_dat      : IN  STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
70
    rd_en       : IN  STD_LOGIC;
71
    rd_adr      : IN  STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
72
    rd_dat      : OUT STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
73
    rd_val      : OUT STD_LOGIC;
74
    -- data side
75
    reg_wr_arr  : OUT STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
76
    reg_rd_arr  : OUT STD_LOGIC_VECTOR(            g_reg.nof_dat-1 DOWNTO 0);
77
    out_reg     : OUT STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
78
    in_reg      : IN  STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0)
79
  );
80
END common_reg_r_w;
81
 
82
 
83
ARCHITECTURE rtl OF common_reg_r_w IS
84
 
85
  CONSTANT c_rd_latency  : NATURAL := 1;
86
  CONSTANT c_pipeline    : NATURAL := g_reg.latency - c_rd_latency;
87
  CONSTANT c_pipe_dat_w  : NATURAL := 1 + g_reg.dat_w;  -- pipeline rd_val & rd_dat together
88
 
89
  SIGNAL pipe_dat_in     : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
90
  SIGNAL pipe_dat_out    : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
91
 
92
  SIGNAL nxt_reg_wr_arr  : STD_LOGIC_VECTOR(reg_wr_arr'RANGE);
93
  SIGNAL nxt_reg_rd_arr  : STD_LOGIC_VECTOR(reg_rd_arr'RANGE);
94
 
95
  SIGNAL i_out_reg       : STD_LOGIC_VECTOR(out_reg'RANGE);
96
  SIGNAL nxt_out_reg     : STD_LOGIC_VECTOR(out_reg'RANGE);
97
 
98
  SIGNAL int_rd_dat      : STD_LOGIC_VECTOR(rd_dat'RANGE);
99
  SIGNAL int_rd_val      : STD_LOGIC;
100
  SIGNAL nxt_rd_dat      : STD_LOGIC_VECTOR(rd_dat'RANGE);
101
  SIGNAL nxt_rd_val      : STD_LOGIC;
102
 
103
BEGIN
104
 
105
  out_reg <= i_out_reg;
106
 
107
  -- Pipeline to support read data latency > 1
108
  u_pipe_rd : ENTITY common_components_lib.common_pipeline
109
  GENERIC MAP (
110
    g_pipeline   => c_pipeline,
111
    g_in_dat_w   => c_pipe_dat_w,
112
    g_out_dat_w  => c_pipe_dat_w
113
  )
114
  PORT MAP (
115
    clk     => clk,
116
    clken   => clken,
117
    in_dat  => pipe_dat_in,
118
    out_dat => pipe_dat_out
119
  );
120
 
121
  pipe_dat_in <= int_rd_val & int_rd_dat;
122
 
123
  rd_dat <= pipe_dat_out(pipe_dat_out'HIGH-1 DOWNTO 0);
124
  rd_val <= pipe_dat_out(pipe_dat_out'HIGH);
125
 
126
 
127
  p_reg : PROCESS (rst, clk)
128
  BEGIN
129
    IF rst = '1' THEN
130
      -- Output signals.
131
      reg_wr_arr <= (OTHERS => '0');
132
      reg_rd_arr <= (OTHERS => '0');
133
      int_rd_val <= '0';
134
      int_rd_dat <= (OTHERS => '0');
135
      -- Internal signals.
136
      i_out_reg <= g_init_reg(out_reg'RANGE);
137
    ELSIF rising_edge(clk) THEN
138
      -- Output signals.
139
      reg_wr_arr <= nxt_reg_wr_arr;
140
      reg_rd_arr <= nxt_reg_rd_arr;
141
      int_rd_val <= nxt_rd_val;
142
      int_rd_dat <= nxt_rd_dat;
143
      -- Internal signals.
144
      i_out_reg <= nxt_out_reg;
145
    END IF;
146
  END PROCESS;
147
 
148
 
149
  p_control : PROCESS (rd_en, int_rd_dat, rd_adr, in_reg, i_out_reg, wr_adr, wr_en, wr_dat)
150
  BEGIN
151
    nxt_rd_val <= rd_en;  -- rd_val depends only on rd_en, so for an out of range address the old rd_dat is output
152
 
153
    nxt_reg_rd_arr <= (OTHERS=>'0');
154
    nxt_rd_dat <= int_rd_dat;
155
    IF rd_en = '1' THEN
156
      FOR i IN 0 TO g_reg.nof_dat-1 LOOP
157
        IF UNSIGNED(rd_adr) = i THEN
158
          nxt_reg_rd_arr(I) <= '1';
159
          nxt_rd_dat <= in_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w);
160
        END IF;
161
      END LOOP;
162
    END IF;
163
 
164
    nxt_reg_wr_arr <= (OTHERS=>'0');
165
    nxt_out_reg <= i_out_reg;
166
    IF wr_en = '1' THEN
167
      FOR i IN 0 TO g_reg.nof_dat-1 LOOP
168
        IF UNSIGNED(wr_adr) = i THEN
169
          nxt_reg_wr_arr(I) <= '1';
170
          nxt_out_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w) <= wr_dat;
171
        END IF;
172
      END LOOP;
173
    END IF;
174
  END PROCESS;
175
 
176
END rtl;

powered by: WebSVN 2.1.0

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