----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date: 
-- Design Name: 
-- Module Name: dig_iq_decoder - imp
-- Project Name: 
-- Target Devices: 
-- Tool Versions: 
-- Description: 
-- 
-- Dependencies: 
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
--
-- 
----------------------------------------------------------------------------------


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
--Library xpm;
--use xpm.vcomponents.all;
--library UNISIM;
--use UNISIM.VComponents.all;

entity dig_iq_decoder is

  port ( 
    aclk                  : in std_logic;
    aresetn               : in std_logic;

    select_12b            : in  std_logic;
    
    s_axis_tdata          : in  std_logic_vector(239 downto 0);
    s_axis_tvalid         : in  std_logic;

    m_axis_tdata          : out std_logic_vector(319 downto 0);
    m_axis_tvalid         : out std_logic
    );
end dig_iq_decoder;

architecture imp of dig_iq_decoder is

  signal tvalid_int : std_logic := '0';

begin

  m_axis_tvalid <= tvalid_int;


  process(aclk, aresetn)
  begin
    if(aresetn = '0')then
      tvalid_int <= '0';
    elsif(rising_edge(aclk))then
      tvalid_int <= s_axis_tvalid;
    end if;
  end process;
  
  process(aclk)
  begin 
  
    if(rising_edge(aclk))then

      if(select_12b = '0')then  
        m_axis_tdata(15  downto 0   ) <=  s_axis_tdata(15  downto 0   );    --  REAL[0]
        m_axis_tdata(31  downto 16  ) <=  s_axis_tdata(32  downto 17  );    --  IMAG[0]
        m_axis_tdata(47  downto 32  ) <=  s_axis_tdata(49  downto 34  );    --  REAL[1]
        m_axis_tdata(63  downto 48  ) <=  s_axis_tdata(66  downto 51  );    --  IMAG[1]
        m_axis_tdata(79  downto 64  ) <=  s_axis_tdata(83  downto 68  );    --  REAL[2]
        m_axis_tdata(95  downto 80  ) <=  s_axis_tdata(100 downto 85  );    --  IMAG[2]
        m_axis_tdata(111 downto 96  ) <=  s_axis_tdata(117 downto 102 );    --  REAL[3] 
        m_axis_tdata(127 downto 112 ) <=  s_axis_tdata(134 downto 119 );    --  IMAG[3]
        m_axis_tdata(143 downto 128 ) <=  s_axis_tdata(151 downto 136 );    --  REAL[4]
        m_axis_tdata(159 downto 144 ) <=  s_axis_tdata(168 downto 153 );    --  IMAG[4] 
        m_axis_tdata(175 downto 160 ) <=  s_axis_tdata(185 downto 170 );    --  REAL[5]
        m_axis_tdata(191 downto 176 ) <=  s_axis_tdata(202 downto 187 );    --  IMAG[5]
        m_axis_tdata(207 downto 192 ) <=  s_axis_tdata(219 downto 204 );    --  REAL[6]
        m_axis_tdata(223 downto 208 ) <=  s_axis_tdata(236 downto 221 );    --  IMAG[6] 
      else
        m_axis_tdata(15  downto 0   ) <=  s_axis_tdata(11  downto 0   ) & "0000";    --  REAL[0]
        m_axis_tdata(31  downto 16  ) <=  s_axis_tdata(23  downto 12  ) & "0000";    --  IMAG[0]
        m_axis_tdata(47  downto 32  ) <=  s_axis_tdata(35  downto 24  ) & "0000";    --  REAL[1]
        m_axis_tdata(63  downto 48  ) <=  s_axis_tdata(47  downto 36  ) & "0000";    --  IMAG[1]
        m_axis_tdata(79  downto 64  ) <=  s_axis_tdata(59  downto 48  ) & "0000";    --  REAL[2]
        m_axis_tdata(95  downto 80  ) <=  s_axis_tdata(71  downto 60  ) & "0000";    --  IMAG[2]
        m_axis_tdata(111 downto 96  ) <=  s_axis_tdata(83  downto 72  ) & "0000";    --  REAL[3] 
        m_axis_tdata(127 downto 112 ) <=  s_axis_tdata(95  downto 84  ) & "0000";    --  IMAG[3]
        m_axis_tdata(143 downto 128 ) <=  s_axis_tdata(107 downto 96  ) & "0000";    --  REAL[4]
        m_axis_tdata(159 downto 144 ) <=  s_axis_tdata(119 downto 108 ) & "0000";    --  IMAG[4] 
        m_axis_tdata(175 downto 160 ) <=  s_axis_tdata(131 downto 120 ) & "0000";    --  REAL[5]
        m_axis_tdata(191 downto 176 ) <=  s_axis_tdata(143 downto 132 ) & "0000";    --  IMAG[5]
        m_axis_tdata(207 downto 192 ) <=  s_axis_tdata(155 downto 144 ) & "0000";    --  REAL[6]
        m_axis_tdata(223 downto 208 ) <=  s_axis_tdata(167 downto 156 ) & "0000";    --  IMAG[6]        
      end if;
      
      m_axis_tdata(239 downto 224 ) <=  s_axis_tdata(179 downto 168 ) & "0000";    --  REAL[7]
      m_axis_tdata(255 downto 240 ) <=  s_axis_tdata(191 downto 180 ) & "0000";    --  IMAG[7]
      m_axis_tdata(271 downto 256 ) <=  s_axis_tdata(203 downto 192 ) & "0000";    --  REAL[8]
      m_axis_tdata(287 downto 272 ) <=  s_axis_tdata(215 downto 204 ) & "0000";    --  IMAG[8]
      m_axis_tdata(303 downto 288 ) <=  s_axis_tdata(227 downto 216 ) & "0000";    --  REAL[9]
      m_axis_tdata(319 downto 304 ) <=  s_axis_tdata(239 downto 228 ) & "0000";    --  IMAG[9]
      
    end if;
  end process;
 

end imp;
