-------------------------------------------------------------------------------
--
-- Copyright 2022
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-------------------------------------------------------------------------------
-- Author: Job van Wee
-- Purpose: Resize the input data vector so that the output data vector can be
--  stored into the ddr memory.
--
-- Description:
--  The input data gets resized and put into the output data vector.
--
-- Remark:
--  Use VHDL coding template from:
--  https://support.astron.nl/confluence/display/SBe/VHDL+design+patterns+for+RTL+coding
--  The output vector must be larger than the input vector.

LIBRARY IEEE, dp_lib, common_lib;
USE IEEE.std_logic_1164.ALL;
USE dp_lib.dp_stream_pkg.ALL;
USE common_lib.common_pkg.ALL;

ENTITY ddrctrl_output_repack IS
  GENERIC (
    g_nof_streams   : POSITIVE := 12;
    g_data_w        : NATURAL  := 14
  );
  PORT (
    in_sosi         : IN  t_dp_sosi     := c_dp_sosi_init;
    out_sosi_arr    : OUT t_dp_sosi_arr(g_nof_streams-1 DOWNTO 0) := (OTHERS => c_dp_sosi_init)
  );
END ddrctrl_output_repack;

ARCHITECTURE rtl OF ddrctrl_output_repack IS

BEGIN

  -- putting the data from the stream into different streams.
  gen_repack_data : FOR I IN 0 TO g_nof_streams-1 GENERATE
    out_sosi_arr(I).data <= in_sosi.data(g_data_w*(I+1)-1 DOWNTO g_data_w*I);
    out_sosi_arr(I).bsn  <= in_sosi.bsn(c_dp_stream_bsn_w-1 DOWNTO 0);
  END GENERATE;

END rtl;