Advertisement
rommik

(NEW)dvb_s2x_interleaver.vhd

Dec 19th, 2019
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 8.26 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use std.textio.all;
  5. --use ieee.std_logic_arith.all;
  6.  
  7. entity dvb_s2x_interleaver is
  8.     Port(
  9.         i_clk             :  in  std_logic;                              -- тактирование
  10.         i_res             :  in  std_logic;                              -- сброс
  11.         i_enb             :  in  std_logic;                              -- разрешение работы
  12.         i_QAM_select      :  in  std_logic_vector (2 downto 0);          -- выбор модуляции
  13.         i_frame_select    :  in  std_logic_vector (0 downto 0);          -- выбор фрейма
  14.         i_data            :  in  std_logic_vector (0 downto 0);          -- входные данные
  15.         o_data            :  out std_logic_vector (0 downto 0));         -- выходные данные
  16. end entity;
  17.  
  18. architecture Behavioral of dvb_s2x_interleaver is
  19.  
  20.     type Memory     is array (0 to 64805)     of std_logic_vector (0 downto 0);   -- память
  21.    
  22.     type LUT_add    is array (0 to 1, 0 to 6) of std_logic_vector(15 downto 0);                         -- границы для генератора и счетчика
  23.     type LUT_Modulo is array (0 to 1, 0 to 6) of std_logic_vector(15 downto 0);                         -- значение модулей для фреймов
  24.  
  25.     constant add_LUT    : LUT_add    := (0 => (0 => "0000000000000001", 1 => "0101010001100000", 2 => "0011111101001000",
  26.                                                3 => "0011001010100000", 4 => "0010101000110000", 5 => "0010010000101010",
  27.                                                6 => "0001111110100100"),
  28.                                          1 => (0 => "0000000000000001", 1 => "0001010100011000", 2 => "0000111111010010",
  29.                                                3 => "0000110010101000", 4 => (others => '0'), 5 => (others => '0'), 6 => (others => '0')));
  30.     constant Modulo_LUT : LUT_Modulo := (0 => (0 => "1111110100011111", 1 => "1111110100011111", 2 => "1111110100011111",
  31.                                                3 => "1111110100011111", 4 => "1111110100011111", 5 => "1111110100100101",
  32.                                                6 => "1111110100011111"),
  33.                                          1 => (0 => "0011111101000111",1 => "0011111101000111", 2 => "0011111101000111", 3 => "0011111101000111",
  34.                                                4 => (others => '0'), 5 => (others => '0'),  6 => (others => '0')));
  35.  
  36.     signal interleaver_0       :  Memory;
  37.     signal interleaver_1       :  Memory;
  38.     signal address_0           :  std_logic_vector(15 downto 0);
  39.     signal address_1           :  std_logic_vector(15 downto 0);
  40.     signal WE_0                :  std_logic;
  41.     signal WE_1                :  std_logic;
  42.     signal modulo_0            :  std_logic_vector(15 downto 0);
  43.     signal add_0               :  std_logic_vector(15 downto 0);
  44.     signal sub_0               :  std_logic_vector(15 downto 0);
  45.     signal compare_0           :  std_logic_vector(15 downto 0);
  46.     signal modulo_1            :  std_logic_vector(15 downto 0);
  47.     signal add_1               :  std_logic_vector(15 downto 0);
  48.     signal sub_1               :  std_logic_vector(15 downto 0);
  49.     signal compare_1           :  std_logic_vector(15 downto 0);
  50.     signal frame_latch         :  std_logic_vector(0 downto 0);
  51.     signal QAM                 :  std_logic_vector(2 downto 0);
  52.     signal out_0               :  std_logic_vector(0 downto 0);
  53.     signal out_1               :  std_logic_vector(0 downto 0);
  54.  
  55.    
  56.     component dvb_s2x_RAM
  57.         Port(
  58.             clk       : in std_logic;                              
  59.             res       : in std_logic;    
  60.             WE        : in std_logic;  
  61.             address   : in std_logic_vector(15 downto 0);                              
  62.             in_data   : in std_logic_vector(0 downto 0);
  63.             out_data  : out std_logic_vector(0 downto 0));
  64.     end component;
  65.    
  66. begin
  67.  
  68. RAM_0: dvb_s2x_RAM
  69.     -- for address_0
  70.     port map(
  71.         clk      =>  i_clk,
  72.         res      =>  i_res,
  73.         WE       =>  WE_0,
  74.         address  =>  address_0,
  75.         in_data  =>  i_data,
  76.         out_data =>  out_0);
  77. RAM_1: dvb_s2x_RAM
  78.     -- for address_1
  79.     port map(
  80.         clk      =>  i_clk,
  81.         res      =>  i_res,
  82.         WE       =>  WE_1,
  83.         address  =>  address_1,
  84.         in_data  =>  i_data,
  85.         out_data =>  out_1);
  86.  
  87.  
  88. main:process(i_clk)
  89.        
  90. begin  
  91. if(rising_edge(i_clk)) then
  92.     if(i_enb = '1') then
  93.         if(WE_0 = '0') then
  94.             o_data <= interleaver_0(to_integer(unsigned(address_0)));
  95.             if(address_0 = modulo_0) then
  96.                 address_0 <= (others => '0');
  97.                 WE_0      <= '1';
  98.             elsif(unsigned(address_0) = 0) then
  99.                 address_0 <= std_logic_vector(unsigned(address_0) + unsigned(add_0));
  100.             elsif(unsigned(address_0) < unsigned(compare_0)) then
  101.                 address_0 <= std_logic_vector(unsigned(address_0) + unsigned(add_0));
  102.             else
  103.                 address_0 <= std_logic_vector(unsigned(address_0) - unsigned(sub_0));
  104.             end if;
  105.         else
  106.             QAM                      <= i_QAM_select;
  107.             modulo_0                 <= Modulo_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  108.             add_0                    <= add_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  109.             sub_0                    <= std_logic_vector(unsigned(modulo_0) - unsigned(add_0));
  110.             compare_0                <= std_logic_vector(unsigned(modulo_0) - unsigned(add_0) + 1);
  111.             interleaver_0(to_integer(unsigned(address_0))) <= i_data;
  112.             if(address_0 = modulo_0) then
  113.                 address_0 <= (others => '0');
  114.                 WE_0      <= '0';
  115.                 WE_1      <= '1';
  116.             else
  117.                 address_0 <= std_logic_vector(unsigned(address_0) + 1);
  118.             end if;
  119.         end if;
  120.                 --
  121.         if(WE_1 = '0') then
  122.             o_data <= interleaver_1(to_integer(unsigned(address_1)));
  123.             if(address_1 = modulo_1) then
  124.                 address_1 <= (others => '0');
  125.                 WE_1      <= '1';
  126.             elsif(unsigned(address_1) = 0) then
  127.                 address_1 <= std_logic_vector(unsigned(address_1) + unsigned(add_1));
  128.             elsif(unsigned(address_1) < unsigned(compare_1)) then
  129.                 address_1 <= std_logic_vector(unsigned(address_1) + unsigned(add_1));
  130.             else
  131.                 address_1 <= std_logic_vector(unsigned(address_1) - unsigned(sub_1));
  132.             end if;
  133.         else
  134.             QAM                      <= i_QAM_select;
  135.             modulo_1                 <= Modulo_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  136.             add_1                    <= add_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  137.             sub_1                    <= std_logic_vector(unsigned(modulo_1) - unsigned(add_1));
  138.             compare_1                <= std_logic_vector(unsigned(modulo_1) - unsigned(add_1) + 1);
  139.             interleaver_1(to_integer(unsigned(address_1))) <= i_data;
  140.             if(address_1 = modulo_1) then
  141.                 address_1 <= (others => '0');
  142.                 WE_1      <= '0';
  143.                 WE_0      <= '1';
  144.             else
  145.                 address_1 <= std_logic_vector(unsigned(address_1) + 1);
  146.             end if;
  147.         end if;
  148.     else           
  149.         if(i_res = '1') then
  150.             QAM                <= i_QAM_select;
  151.             frame_latch        <= i_frame_select;
  152.             modulo_0           <= Modulo_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  153.             modulo_1           <= Modulo_LUT(to_integer(unsigned(frame_latch)), to_integer(unsigned(QAM)));
  154.             address_0          <= (others => '0');
  155.             address_1          <= (others => '0');
  156.             WE_0               <='1';
  157.             WE_1               <='0';  
  158.             add_0              <= (others => '0');      
  159.             add_1              <= (others => '0');  
  160.             sub_0              <= std_logic_vector(unsigned(modulo_0) - unsigned(add_0));
  161.             sub_1              <= std_logic_vector(unsigned(modulo_1) - unsigned(add_1));
  162.             compare_0          <= std_logic_vector(unsigned(modulo_0) - unsigned(add_0) + 1);
  163.             compare_1          <= std_logic_vector(unsigned(modulo_1) - unsigned(add_1) + 1);
  164.         else end if;    
  165.     end if;
  166. end if;    
  167. end process;
  168. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement