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 4

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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