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

powered by: WebSVN 2.1.0

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