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

Subversion Repositories astron_multiplexer

[/] [astron_multiplexer/] [trunk/] [common_zip.vhd] - Blame information for rev 3

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
-- Purpose:  Merges the data of multiple input streams into one output stream. 
21
-- 
22
-- Description: An output stream is composed out of the input streams. The duty cycle
23
--              of the in_val signal must be 1/g_nof_streams in order 
24
--              to avoid the loss of data. 
25
 
26
library IEEE, common_pkg_lib;
27
use IEEE.std_logic_1164.ALL;
28
use common_pkg_lib.common_pkg.ALL;
29
 
30
entity common_zip is
31
  generic (
32
    g_nof_streams : natural := 2;  -- Number of input streams to be zipped
33
    g_dat_w       : natural := 8
34
  );
35
  port (
36
    rst        : in  std_logic := '0';
37
    clk        : in  std_logic;
38
    in_val     : in  std_logic := '0';
39
    in_dat_arr : in  t_slv_64_arr(g_nof_streams-1 downto 0);
40
    out_val    : out std_logic;
41
    out_dat    : out std_logic_vector(g_dat_w-1 downto 0)
42
  );
43
end common_zip;
44
 
45
architecture rtl of common_zip is
46
 
47
  type t_dat_arr is array (natural range <>) of std_logic_vector(out_dat'range);
48
 
49
  type reg_type is record
50
    in_dat_arr  : t_dat_arr(g_nof_streams-1 downto 1);  -- Input register
51
    index       : integer range 1 to g_nof_streams;     -- Index
52
    out_dat     : std_logic_vector(g_dat_w-1 downto 0); -- Registered output value
53
    out_val     : std_logic;                            -- Registered data valid signal  
54
  end record;
55
 
56
  signal r, rin : reg_type;
57
 
58
begin
59
 
60
  comb : process(r, rst, in_val, in_dat_arr)
61
    variable v : reg_type;
62
  begin
63
 
64
    v := r;
65
    v.out_val := '0';                                         -- Default the output valid signal is low. 
66
 
67
    if(in_val = '1') then                                     -- Wait for incoming data
68
      v.index   := 1;
69
      v.out_val := '1';
70
      v.out_dat := in_dat_arr(0)(g_dat_w-1 downto 0);         -- Output the first stream already
71
      for I in 1 to g_nof_streams-1 loop
72
        v.in_dat_arr(I) := in_dat_arr(I)(g_dat_w-1 downto 0); -- Store input data in register
73
      end loop;
74
    end if;
75
 
76
    if(r.index < g_nof_streams) then
77
      v.out_val := '1';
78
      v.out_dat := r.in_dat_arr(r.index);                     -- Output the next input stream
79
      v.index   := r.index+1;
80
    end if;
81
 
82
    if(rst = '1') then
83
      v.in_dat_arr := (others => (others => '0'));
84
      v.index      := g_nof_streams;
85
      v.out_dat    := (others => '0');
86
      v.out_val    := '0';
87
    end if;
88
 
89
    rin <= v;
90
 
91
  end process comb;
92
 
93
  regs : process(clk)
94
  begin
95
    if rising_edge(clk) then
96
      r <= rin;
97
    end if;
98
  end process;
99
 
100
  out_dat <= r.out_dat;
101
  out_val <= r.out_val;
102
 
103
end rtl;

powered by: WebSVN 2.1.0

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