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

Subversion Repositories astron_mm

[/] [astron_mm/] [trunk/] [common_mem_mux.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) 2011
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
-------------------------------------------------------------------------------
23
-- 
24
-- Purpose: Combines an array of MM interfaces into a single MM interface.
25
-- Description:
26
--   The common_mem_mux unit combines an array of mosi's and miso's to one
27
--   single set of mosi and miso. Should be used to decrease the amount of
28
--   slave memory interfaces to the MM bus.
29
--
30
--                                  g_rd_latency
31
--                                 ______________
32
--        strip index:             |            |
33
--        mosi.address[h:w] ---+-->| delay line |--\
34
--                             |   |____________|  |
35
--                             |                   |
36
--                 selected    v                   |
37
--   mosi -------> mosi_arr.wr[ ]-----------------------------> mosi_arr
38
--                          rd                     |
39
--                                        selected v
40
--   miso <-------------------------------miso_arr[ ]<--------- miso_arr
41
--
42
--        . not selected mosi_arr get mosi but with wr='0', rd='0'
43
--        . not selected miso_arr are ignored
44
--
45
--   Use default g_broadcast=FALSE for multiplexed individual MM access to
46
--   each mosi_arr/miso_arr MM port. When g_broadcast=TRUE then a write
47
--   access to MM port [0] is passed on to all ports and a read access is
48
--   done from MM port [0]. The other ports cannot be read.
49
--
50
-- Remarks:
51
-- . In simulation selecting an unused element address will cause a simulation
52
--   failure. Therefore the element index is only accepted when it is in the
53
--   g_nof_mosi-1 DOWNTO 0 range.
54
-- . In case multiple common_mem_mux would be used in series, then only the
55
--   top one needs to account for g_rd_latency>0, the rest can use 0.
56
--
57
-------------------------------------------------------------------------------
58
 
59
 
60
LIBRARY IEEE, common_pkg_lib, common_ram_lib;
61
USE IEEE.STD_LOGIC_1164.ALL;
62
USE common_pkg_lib.common_pkg.ALL;
63
USE common_ram_lib.common_ram_pkg.ALL;
64
 
65
ENTITY common_mem_mux IS
66
  GENERIC (
67
    g_broadcast   : BOOLEAN := FALSE;
68
    g_nof_mosi    : POSITIVE := 256;     -- Number of memory interfaces in the array.
69
    g_mult_addr_w : POSITIVE := 8;       -- Address width of each memory-interface element in the muliplexed array.
70
    g_rd_latency  : NATURAL := 0
71
  );
72
  PORT (
73
    clk      : IN  STD_LOGIC := '0';   -- only used when g_rd_latency > 0
74
    mosi     : IN  t_mem_mosi;
75
    miso     : OUT t_mem_miso;
76
    mosi_arr : OUT t_mem_mosi_arr(g_nof_mosi - 1 DOWNTO 0);
77
    miso_arr : IN  t_mem_miso_arr(g_nof_mosi - 1 DOWNTO 0) := (OTHERS=>c_mem_miso_rst)
78
  );
79
END common_mem_mux;
80
 
81
ARCHITECTURE rtl OF common_mem_mux IS
82
 
83
  CONSTANT c_index_w        : NATURAL := ceil_log2(g_nof_mosi);
84
  CONSTANT c_total_addr_w   : NATURAL := c_index_w + g_mult_addr_w;
85
 
86
  SIGNAL index_arr : t_natural_arr(0 TO g_rd_latency);
87
  SIGNAL index_rw  : NATURAL;  -- read or write access
88
  SIGNAL index_rd  : NATURAL;  -- read response
89
 
90
BEGIN
91
 
92
  gen_single : IF g_broadcast=FALSE AND g_nof_mosi=1 GENERATE
93
    mosi_arr(0) <= mosi;
94
    miso        <= miso_arr(0);
95
  END GENERATE;
96
 
97
  gen_multiple : IF g_broadcast=FALSE AND g_nof_mosi>1 GENERATE
98
    -- The activated element of the array is detected here
99
    index_arr(0) <= TO_UINT(mosi.address(c_total_addr_w-1 DOWNTO g_mult_addr_w));
100
 
101
    -- Pipeline the index of the activated element to account for the read latency
102
    p_clk : PROCESS(clk)
103
    BEGIN
104
      IF rising_edge(clk) THEN
105
        index_arr(1 TO g_rd_latency) <= index_arr(0 TO g_rd_latency-1);
106
      END IF;
107
    END PROCESS;
108
 
109
    index_rw <= index_arr(0);
110
    index_rd <= index_arr(g_rd_latency);
111
 
112
    -- Master access, can be write or read
113
    p_mosi_arr : PROCESS(mosi, index_rw)
114
    BEGIN
115
      FOR I IN 0 TO g_nof_mosi-1 LOOP
116
        mosi_arr(I)    <= mosi;
117
        mosi_arr(I).rd <= '0';
118
        mosi_arr(I).wr <= '0';
119
        IF I = index_rw THEN
120
          mosi_arr(I).rd <= mosi.rd;
121
          mosi_arr(I).wr <= mosi.wr;
122
        END IF;
123
      END LOOP;
124
    END PROCESS;
125
 
126
    -- Slave response to read access after g_rd_latency clk cycles
127
    p_miso : PROCESS(miso_arr, index_rd)
128
    BEGIN
129
      miso <= c_mem_miso_rst;
130
      FOR I IN 0 TO g_nof_mosi-1 LOOP
131
        IF I = index_rd THEN
132
          miso <= miso_arr(I);
133
        END IF;
134
      END LOOP;
135
    END PROCESS;
136
  END GENERATE;
137
 
138
  gen_broadcast : IF g_broadcast=TRUE GENERATE
139
    mosi_arr <= (OTHERS=>mosi);  -- broadcast write to all [g_nof_mosi-1:0] MM ports
140
    miso     <= miso_arr(0);     -- broadcast read only from MM port [0]
141
  END GENERATE;
142
 
143
END rtl;

powered by: WebSVN 2.1.0

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