]> jspc29.x-matter.uni-frankfurt.de Git - trbnet.git/commitdiff
new hub version, Jan
authorhadeshyp <hadeshyp>
Mon, 26 Nov 2007 22:01:39 +0000 (22:01 +0000)
committerhadeshyp <hadeshyp>
Mon, 26 Nov 2007 22:01:39 +0000 (22:01 +0000)
trb_net16_api_base.vhd
trb_net16_hub_base.vhd
trb_net16_hub_func.vhd
xilinx/trb_net16_bram_fifo.vhd
xilinx/trb_net_fifo_arch.vhd

index fc86f5efb168ad6e6a8fee7fc3edf2498075d108..abd2a252b19bf64753030c5aa3280cc2cbf52936 100644 (file)
@@ -276,6 +276,8 @@ begin
   gennotterm: if API_TYPE = 0 generate
     INT_MASTER_READ_OUT <= '1';
     INT_SLAVE_DATAREADY_OUT <= '0';
+    INT_SLAVE_DATA_OUT <= (others => '0');
+    INT_SLAVE_PACKET_NUM_OUT <= (others => '0');
   end generate;
 
 ---------------------------------------
index f27bf80d6b7802f7733d70978f40bd27591d3dda..f3828e215f4ef2550ffeab73b28a35e619abdf08 100644 (file)
@@ -11,56 +11,60 @@ entity trb_net16_hub_base is
   generic (
   --general settings
     MUX_SECURE_MODE         : integer range 0 to 1 := 0;
-    MUX_WIDTH               : integer range 1 to 5 := 3;
-    MUX_CTRL_CHANNEL        : integer range 0 to 2**(MUX_WIDTH-1)-1 := 3;
+    MUX_WIDTH               : integer range 1 to 3 := 3;
     DATA_WIDTH              : integer range 16 to 16 := 16;
     NUM_WIDTH               : integer range 2 to 2 := 2;
+  --hub control
+    HUB_ADDRESS             : std_logic_vector(15 downto 0) := x"F001";
+    HUB_CTRL_CHANNELNUM     : integer range 0 to 2**(MUX_WIDTH-1)-1 := 3;
+    HUB_CTRL_DEPTH          : integer range 0 to 6 := 1;
   --media interfaces
     MII_NUMBER              : integer range 2 to 16 := 2;
 --each row is one media interface and each column is one channel. starting with 0,0, ending with 15,15
-    MII_INIT_DEPTH    : hub_iobuf_config_t := (1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1);
-    MII_REPLY_DEPTH   : hub_iobuf_config_t := (1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               6,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               6,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
-                                               0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1);
+                                    --CHANNEL  3 2 1 0
+    MII_INIT_DEPTH    : hub_iobuf_config_t := (1,6,0,0,    --MII 0
+                                               1,6,0,0,
+                                               1,6,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0);   --MII 15
+    MII_REPLY_DEPTH    : hub_iobuf_config_t := (1,6,0,0,    --MII 0
+                                               1,6,0,0,
+                                               1,6,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0,
+                                               0,0,0,0);   --MII 15
   -- settings for apis
-    API_NUMBER              : integer range 0 to 16 := 1;
+    API_NUMBER              : integer range 0 to 16 := 0;
     API_CHANNELS            : hub_api_config_t := (3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3);
                                 --channel, each api is connected to
     API_TYPE                : hub_api_config_t := (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
-    API_INIT_DEPTH          : hub_api_config_t := (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
-    API_REPLY_DEPTH         : hub_api_config_t := (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
-    API_FIFO_TO_INT_DEPTH   : hub_api_config_t := (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
-    API_FIFO_TO_APL_DEPTH   : hub_api_config_t := (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
+    API_INIT_DEPTH          : hub_api_config_t := (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+    API_REPLY_DEPTH         : hub_api_config_t := (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+    API_FIFO_TO_INT_DEPTH   : hub_api_config_t := (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+    API_FIFO_TO_APL_DEPTH   : hub_api_config_t := (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
   --trigger reading interfaces
-    TRG_NUMBER              : integer range 0 to 16 := 1;
+    TRG_NUMBER              : integer range 0 to 16 := 0;
     TRG_CHANNELS            : hub_api_config_t := (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
     );
   port (
@@ -124,56 +128,75 @@ entity trb_net16_hub_base is
 end entity;
 
 architecture trb_net16_hub_base_arch of trb_net16_hub_base is
-  constant total_point_num : integer := MII_NUMBER*2**(MUX_WIDTH-1) + API_NUMBER + TRG_NUMBER;
-  signal m_DATAREADY_OUT : std_logic_vector (total_point_num*2**MUX_WIDTH-1 downto 0);
-  signal m_DATA_OUT      : std_logic_vector (total_point_num*DATA_WIDTH*2**MUX_WIDTH-1 downto 0);
-  signal m_PACKET_NUM_OUT: std_logic_vector (total_point_num*NUM_WIDTH*2**MUX_WIDTH-1 downto 0);
-  signal m_READ_IN       : std_logic_vector (total_point_num*2**MUX_WIDTH-1 downto 0);
-  signal m_DATAREADY_IN  : std_logic_vector (total_point_num*2**MUX_WIDTH-1 downto 0);
-  signal m_DATA_IN       : std_logic_vector (total_point_num*DATA_WIDTH*2**MUX_WIDTH-1 downto 0);
-  signal m_PACKET_NUM_IN : std_logic_vector (total_point_num*NUM_WIDTH*2**MUX_WIDTH-1 downto 0);
-  signal m_READ_OUT      : std_logic_vector (total_point_num*2**MUX_WIDTH-1 downto 0);
-  signal m_ERROR_IN      : std_logic_vector (total_point_num*3*2**MUX_WIDTH-1 downto 0);
+  constant total_point_num : integer := MII_NUMBER*2**(MUX_WIDTH-1) + API_NUMBER + TRG_NUMBER + 1;
+  signal m_DATAREADY_OUT : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)-1 downto 0);
+  signal m_DATA_OUT      : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)*DATA_WIDTH-1 downto 0);
+  signal m_PACKET_NUM_OUT: std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)*NUM_WIDTH-1 downto 0);
+  signal m_READ_IN       : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)-1 downto 0);
+  signal m_DATAREADY_IN  : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)-1 downto 0);
+  signal m_DATA_IN       : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)*DATA_WIDTH-1 downto 0);
+  signal m_PACKET_NUM_IN : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)*NUM_WIDTH-1 downto 0);
+  signal m_READ_OUT      : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)-1 downto 0);
+  signal m_ERROR_IN      : std_logic_vector (MII_NUMBER*2**(MUX_WIDTH)*3-1 downto 0);
 
-  signal hub_to_buf_INIT_DATAREADY: std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal hub_to_buf_INIT_DATA     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal hub_to_buf_INIT_PACKET_NUM:std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal hub_to_buf_INIT_READ     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
+  signal hub_to_buf_INIT_DATAREADY: std_logic_vector (total_point_num-1 downto 0);
+  signal hub_to_buf_INIT_DATA     : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal hub_to_buf_INIT_PACKET_NUM:std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal hub_to_buf_INIT_READ     : std_logic_vector (total_point_num-1 downto 0);
 
-  signal buf_to_hub_INIT_DATAREADY: std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal buf_to_hub_INIT_DATA     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal buf_to_hub_INIT_PACKET_NUM:std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal buf_to_hub_INIT_READ     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
+  signal buf_to_hub_INIT_DATAREADY: std_logic_vector (total_point_num-1 downto 0);
+  signal buf_to_hub_INIT_DATA     : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal buf_to_hub_INIT_PACKET_NUM:std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal buf_to_hub_INIT_READ     : std_logic_vector (total_point_num-1 downto 0);
 
-  signal hub_to_buf_REPLY_DATAREADY: std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal hub_to_buf_REPLY_DATA     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal hub_to_buf_REPLY_PACKET_NUM:std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal hub_to_buf_REPLY_READ     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal hub_to_buf_REPLY_SEND_HEADER : std_logic_vector(2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
+  signal hub_to_buf_REPLY_DATAREADY: std_logic_vector (total_point_num-1 downto 0);
+  signal hub_to_buf_REPLY_DATA     : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal hub_to_buf_REPLY_PACKET_NUM:std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal hub_to_buf_REPLY_READ     : std_logic_vector (total_point_num-1 downto 0);
+  signal hub_to_buf_REPLY_SEND_HEADER : std_logic_vector(total_point_num-1 downto 0);
   
-  signal buf_to_hub_REPLY_DATAREADY: std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal buf_to_hub_REPLY_DATA     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal buf_to_hub_REPLY_PACKET_NUM:std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal buf_to_hub_REPLY_READ     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal buf_to_hub_REPLY_SEND_HEADER : std_logic_vector(2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
+  signal buf_to_hub_REPLY_DATAREADY: std_logic_vector (total_point_num-1 downto 0);
+  signal buf_to_hub_REPLY_DATA     : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal buf_to_hub_REPLY_PACKET_NUM:std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal buf_to_hub_REPLY_READ     : std_logic_vector (total_point_num-1 downto 0);
+  signal buf_to_hub_REPLY_SEND_HEADER : std_logic_vector(total_point_num-1 downto 0);
+
+  signal HUB_INIT_DATAREADY_OUT    : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_INIT_DATA_OUT         : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal HUB_INIT_PACKET_NUM_OUT   : std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal HUB_INIT_READ_IN          : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_INIT_DATAREADY_IN     : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_INIT_DATA_IN          : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal HUB_INIT_PACKET_NUM_IN    : std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal HUB_INIT_READ_OUT         : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_REPLY_DATAREADY_OUT   : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_REPLY_DATA_OUT        : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal HUB_REPLY_PACKET_NUM_OUT  : std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal HUB_REPLY_READ_IN         : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_REPLY_DATAREADY_IN    : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_REPLY_DATA_IN         : std_logic_vector (total_point_num*DATA_WIDTH-1 downto 0);
+  signal HUB_REPLY_PACKET_NUM_IN   : std_logic_vector (total_point_num*NUM_WIDTH-1 downto 0);
+  signal HUB_REPLY_READ_OUT        : std_logic_vector (total_point_num-1 downto 0);
+  signal HUB_REPLY_SEND_HEADER_OUT : std_logic_vector (total_point_num-1 downto 0);
+
+  signal HC_DATA_IN       :  std_logic_vector (DATA_WIDTH-1 downto 0);
+  signal HC_PACKET_NUM_IN :  std_logic_vector (NUM_WIDTH-1 downto 0);
+  signal HC_WRITE_IN      :  std_logic;
+  signal HC_FIFO_FULL_OUT :  std_logic;
+  signal HC_SHORT_TRANSFER_IN :  std_logic;
+  signal HC_DTYPE_IN      :  std_logic_vector (3 downto 0);
+  signal HC_ERROR_PATTERN_IN :   std_logic_vector (31 downto 0);
+  signal HC_SEND_IN       :  std_logic;
+  signal HC_TARGET_ADDRESS_IN :  std_logic_vector (15 downto 0);
+  signal HC_DATA_OUT      :  std_logic_vector (DATA_WIDTH-1 downto 0);
+  signal HC_PACKET_NUM_OUT:  std_logic_vector (NUM_WIDTH-1 downto 0);
+  signal HC_TYP_OUT       :  std_logic_vector (2 downto 0);
+  signal HC_DATAREADY_OUT :  std_logic;
+  signal HC_READ_IN       :  std_logic;
+  signal HC_RUN_OUT       :  std_logic;
+  signal HC_MY_ADDRESS_IN :  std_logic_vector (15 downto 0);
+  signal HC_SEQNR_OUT     :  std_logic_vector (7 downto 0);
 
-  signal HUB_INIT_DATAREADY_OUT    : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_INIT_DATA_OUT         : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal HUB_INIT_PACKET_NUM_OUT   : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal HUB_INIT_READ_IN          : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_INIT_DATAREADY_IN     : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_INIT_DATA_IN          : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal HUB_INIT_PACKET_NUM_IN    : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal HUB_INIT_READ_OUT         : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_REPLY_DATAREADY_OUT   : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_REPLY_DATA_OUT        : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal HUB_REPLY_PACKET_NUM_OUT  : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal HUB_REPLY_READ_IN         : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_REPLY_DATAREADY_IN    : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_REPLY_DATA_IN         : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*DATA_WIDTH-1 downto 0);
-  signal HUB_REPLY_PACKET_NUM_IN   : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num*NUM_WIDTH-1 downto 0);
-  signal HUB_REPLY_READ_OUT        : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
-  signal HUB_REPLY_SEND_HEADER_OUT : std_logic_vector (2**(MUX_WIDTH-1)*total_point_num-1 downto 0);
 
   component trb_net16_hub_logic is
   generic (
@@ -307,7 +330,7 @@ end component;
   end component;
   
   
-  component trb_net16_base_api is
+  component trb_net16_api_base is
     generic (
       API_TYPE : integer := 1;
       FIFO_TO_INT_DEPTH : integer := 1;
@@ -409,11 +432,12 @@ begin
   end generate;
 
 --generate IOBufs for MII
-  gen_iobufs: for i in 0 to total_point_num-1 generate
+  gen_iobufs: for i in 0 to MII_NUMBER*2**(MUX_WIDTH-1)-1 generate
+  begin
     IOBUF: trb_net16_iobuf
       generic map (
-        INIT_DEPTH =>  calc_depth(i,MII_INIT_DEPTH, API_INIT_DEPTH, MII_NUMBER, API_NUMBER, MUX_WIDTH),
-        REPLY_DEPTH => calc_depth(i,MII_REPLY_DEPTH, API_REPLY_DEPTH, MII_NUMBER, API_NUMBER, MUX_WIDTH)
+        INIT_DEPTH =>  calc_depth(i,MII_INIT_DEPTH, API_INIT_DEPTH, MII_NUMBER, API_NUMBER, MUX_WIDTH, HUB_CTRL_DEPTH),
+        REPLY_DEPTH => calc_depth(i,MII_REPLY_DEPTH, API_REPLY_DEPTH, MII_NUMBER, API_NUMBER, MUX_WIDTH, HUB_CTRL_DEPTH)
         )
       port map (
         --  Misc
@@ -477,12 +501,190 @@ begin
         STAT_CTRL_REPLY_BUFFER => IOBUF_STAT_CTRL_REPLY_BUFFER((i+1)*32-1 downto i*32)
         );
   end generate;
-
+  gen_ctrl_api : if 1 = 1 generate
+    constant i         : integer := 2**(MUX_WIDTH-1)*MII_NUMBER;
+  begin
+    CTRL_API : trb_net16_api_base
+      generic map(
+        API_TYPE               => 0,
+        FIFO_TO_INT_DEPTH      => HUB_CTRL_DEPTH,
+        FIFO_TO_APL_DEPTH      => HUB_CTRL_DEPTH,
+        FIFO_TERM_BUFFER_DEPTH => 0
+        )
+      port map(
+        --  Misc
+        CLK    => CLK,
+        RESET  => RESET,
+        CLK_EN => CLK_EN,
+        -- APL Transmitter port
+        APL_DATA_IN           => HC_DATA_IN(DATA_WIDTH-1 downto 0),
+        APL_PACKET_NUM_IN     => HC_PACKET_NUM_IN(NUM_WIDTH-1 downto 0),
+        APL_WRITE_IN          => HC_WRITE_IN,
+        APL_FIFO_FULL_OUT     => HC_FIFO_FULL_OUT,
+        APL_SHORT_TRANSFER_IN => HC_SHORT_TRANSFER_IN,
+        APL_DTYPE_IN          => HC_DTYPE_IN(3 downto 0),
+        APL_ERROR_PATTERN_IN  => HC_ERROR_PATTERN_IN(31 downto 0),
+        APL_SEND_IN           => HC_SEND_IN,
+        APL_TARGET_ADDRESS_IN => HC_TARGET_ADDRESS_IN(15 downto 0),
+        -- Receiver port
+        APL_DATA_OUT          => HC_DATA_OUT(DATA_WIDTH-1 downto 0),
+        APL_PACKET_NUM_OUT    => HC_PACKET_NUM_OUT(NUM_WIDTH-1 downto 0),
+        APL_TYP_OUT           => HC_TYP_OUT(2 downto 0),
+        APL_DATAREADY_OUT     => HC_DATAREADY_OUT,
+        APL_READ_IN           => HC_READ_IN,
+        -- APL Control port
+        APL_RUN_OUT           => HC_RUN_OUT,
+        APL_MY_ADDRESS_IN     => HC_MY_ADDRESS_IN(15 downto 0),
+        APL_SEQNR_OUT         => HC_SEQNR_OUT(7 downto 0),
+        -- Internal direction port
+        INT_MASTER_DATAREADY_OUT  => buf_to_hub_REPLY_DATAREADY(i),
+        INT_MASTER_DATA_OUT       => buf_to_hub_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+        INT_MASTER_PACKET_NUM_OUT => buf_to_hub_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+        INT_MASTER_READ_IN        => buf_to_hub_REPLY_READ(i),
+        INT_MASTER_DATAREADY_IN   => hub_to_buf_REPLY_DATAREADY(i),
+        INT_MASTER_DATA_IN        => hub_to_buf_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+        INT_MASTER_PACKET_NUM_IN  => hub_to_buf_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+        INT_MASTER_READ_OUT       => hub_to_buf_REPLY_READ(i),
+        INT_SLAVE_HEADER_IN       => hub_to_buf_REPLY_SEND_HEADER(i),
+        INT_SLAVE_DATAREADY_OUT   => buf_to_hub_INIT_DATAREADY(i),
+        INT_SLAVE_DATA_OUT        => buf_to_hub_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+        INT_SLAVE_PACKET_NUM_OUT  => buf_to_hub_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+        INT_SLAVE_READ_IN         => buf_to_hub_INIT_READ(i),
+        INT_SLAVE_DATAREADY_IN    => hub_to_buf_INIT_DATAREADY(i),
+        INT_SLAVE_DATA_IN         => hub_to_buf_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+        INT_SLAVE_PACKET_NUM_IN   => hub_to_buf_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+        INT_SLAVE_READ_OUT        => hub_to_buf_INIT_READ(i),
+        -- Status and control port
+        STAT_FIFO_TO_INT          => open,
+        STAT_FIFO_TO_APL          => open
+        );
+  end generate;
+  gen_apisa : if API_NUMBER /= 0 generate
+    gen_apis : for i in 2**(MUX_WIDTH-1)*MII_NUMBER+1 to 2**(MUX_WIDTH-1)*MII_NUMBER+API_NUMBER generate
+                      --+1 because of hub_ctrl
+      constant offset : integer := 2**(MUX_WIDTH-1)*MII_NUMBER + 1;
+      constant aploffset : integer := i - offset;
+    begin
+      gen_pas_api : if API_TYPE(aploffset) = 0 generate
+        PAS_API : trb_net16_api_base
+          generic map(
+            API_TYPE               => API_TYPE(aploffset),
+            FIFO_TO_INT_DEPTH      => API_INIT_DEPTH(aploffset),
+            FIFO_TO_APL_DEPTH      => API_REPLY_DEPTH(aploffset),
+            FIFO_TERM_BUFFER_DEPTH => 0
+            )
+          port map(
+            --  Misc
+            CLK    => CLK,
+            RESET  => RESET,
+            CLK_EN => CLK_EN,
+            -- APL Transmitter port
+            APL_DATA_IN           => APL_DATA_IN((aploffset+1)*DATA_WIDTH-1 downto aploffset * DATA_WIDTH),
+            APL_PACKET_NUM_IN     => APL_PACKET_NUM_IN((aploffset+1)*NUM_WIDTH-1 downto aploffset * NUM_WIDTH),
+            APL_WRITE_IN          => APL_WRITE_IN(aploffset),
+            APL_FIFO_FULL_OUT     => APL_FIFO_FULL_OUT(aploffset),
+            APL_SHORT_TRANSFER_IN => APL_SHORT_TRANSFER_IN(aploffset),
+            APL_DTYPE_IN          => APL_DTYPE_IN((aploffset+1)*4-1 downto aploffset*4),
+            APL_ERROR_PATTERN_IN  => APL_ERROR_PATTERN_IN((aploffset+1)*32-1 downto aploffset*32),
+            APL_SEND_IN           => APL_SEND_IN(aploffset),
+            APL_TARGET_ADDRESS_IN => APL_TARGET_ADDRESS_IN((aploffset+1)*16-1 downto aploffset*16),
+            -- Receiver port
+            APL_DATA_OUT          => APL_DATA_OUT((aploffset+1)*DATA_WIDTH-1 downto aploffset * DATA_WIDTH),
+            APL_PACKET_NUM_OUT    => APL_PACKET_NUM_OUT((aploffset+1)*NUM_WIDTH-1 downto aploffset * NUM_WIDTH),
+            APL_TYP_OUT           => APL_TYP_OUT((aploffset+1)*3-1 downto aploffset*3),
+            APL_DATAREADY_OUT     => APL_DATAREADY_OUT(aploffset),
+            APL_READ_IN           => APL_READ_IN(aploffset),
+            -- APL Control port
+            APL_RUN_OUT           => APL_RUN_OUT(aploffset),
+            APL_MY_ADDRESS_IN     => APL_MY_ADDRESS_IN((aploffset+1)*16-1 downto aploffset*16),
+            APL_SEQNR_OUT         => APL_SEQNR_OUT((aploffset+1)*8-1 downto aploffset*8),
+            -- Internal direction port
+            INT_MASTER_DATAREADY_OUT  => buf_to_hub_REPLY_DATAREADY(i),
+            INT_MASTER_DATA_OUT       => buf_to_hub_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_MASTER_PACKET_NUM_OUT => buf_to_hub_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_MASTER_READ_IN        => buf_to_hub_REPLY_READ(i),
+            INT_MASTER_DATAREADY_IN   => hub_to_buf_REPLY_DATAREADY(i),
+            INT_MASTER_DATA_IN        => hub_to_buf_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_MASTER_PACKET_NUM_IN  => hub_to_buf_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_MASTER_READ_OUT       => hub_to_buf_REPLY_READ(i),
+            INT_SLAVE_HEADER_IN       => hub_to_buf_REPLY_SEND_HEADER(i),
+            INT_SLAVE_DATAREADY_OUT   => buf_to_hub_INIT_DATAREADY(i),
+            INT_SLAVE_DATA_OUT        => buf_to_hub_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_SLAVE_PACKET_NUM_OUT  => buf_to_hub_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_SLAVE_READ_IN         => buf_to_hub_INIT_READ(i),
+            INT_SLAVE_DATAREADY_IN    => hub_to_buf_INIT_DATAREADY(i),
+            INT_SLAVE_DATA_IN         => hub_to_buf_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_SLAVE_PACKET_NUM_IN   => hub_to_buf_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_SLAVE_READ_OUT        => hub_to_buf_INIT_READ(i),
+            -- Status and control port
+            STAT_FIFO_TO_INT          => open,
+            STAT_FIFO_TO_APL          => open
+            );
+      end generate;
+      gen_act_api : if API_TYPE(aploffset) = 1 generate
+        ACT_API : trb_net16_api_base
+          generic map(
+            API_TYPE               => API_TYPE(aploffset),
+            FIFO_TO_INT_DEPTH      => API_INIT_DEPTH(aploffset),
+            FIFO_TO_APL_DEPTH      => API_REPLY_DEPTH(aploffset),
+            FIFO_TERM_BUFFER_DEPTH => 0
+            )
+          port map(
+            --  Misc
+            CLK    => CLK,
+            RESET  => RESET,
+            CLK_EN => CLK_EN,
+            -- APL Transmitter port
+            APL_DATA_IN           => APL_DATA_IN((aploffset+1)*DATA_WIDTH-1 downto aploffset * DATA_WIDTH),
+            APL_PACKET_NUM_IN     => APL_PACKET_NUM_IN((aploffset+1)*NUM_WIDTH-1 downto aploffset * NUM_WIDTH),
+            APL_WRITE_IN          => APL_WRITE_IN(aploffset),
+            APL_FIFO_FULL_OUT     => APL_FIFO_FULL_OUT(aploffset),
+            APL_SHORT_TRANSFER_IN => APL_SHORT_TRANSFER_IN(aploffset),
+            APL_DTYPE_IN          => APL_DTYPE_IN((aploffset+1)*4-1 downto aploffset*4),
+            APL_ERROR_PATTERN_IN  => APL_ERROR_PATTERN_IN((aploffset+1)*32-1 downto aploffset*32),
+            APL_SEND_IN           => APL_SEND_IN(aploffset),
+            APL_TARGET_ADDRESS_IN => APL_TARGET_ADDRESS_IN((aploffset+1)*16-1 downto aploffset*16),
+            -- Receiver port
+            APL_DATA_OUT          => APL_DATA_OUT((aploffset+1)*DATA_WIDTH-1 downto aploffset * DATA_WIDTH),
+            APL_PACKET_NUM_OUT    => APL_PACKET_NUM_OUT((aploffset+1)*NUM_WIDTH-1 downto aploffset * NUM_WIDTH),
+            APL_TYP_OUT           => APL_TYP_OUT((aploffset+1)*3-1 downto aploffset*3),
+            APL_DATAREADY_OUT     => APL_DATAREADY_OUT(aploffset),
+            APL_READ_IN           => APL_READ_IN(aploffset),
+            -- APL Control port
+            APL_RUN_OUT           => APL_RUN_OUT(aploffset),
+            APL_MY_ADDRESS_IN     => APL_MY_ADDRESS_IN((aploffset+1)*16-1 downto aploffset*16),
+            APL_SEQNR_OUT         => APL_SEQNR_OUT((aploffset+1)*8-1 downto aploffset*8),
+            -- Internal direction port
+            INT_MASTER_DATAREADY_OUT  => buf_to_hub_INIT_DATAREADY(i),
+            INT_MASTER_DATA_OUT       => buf_to_hub_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_MASTER_PACKET_NUM_OUT => buf_to_hub_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_MASTER_READ_IN        => buf_to_hub_INIT_READ(i),
+            INT_MASTER_DATAREADY_IN   => hub_to_buf_INIT_DATAREADY(i),
+            INT_MASTER_DATA_IN        => hub_to_buf_INIT_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_MASTER_PACKET_NUM_IN  => hub_to_buf_INIT_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_MASTER_READ_OUT       => hub_to_buf_INIT_READ(i),
+            INT_SLAVE_HEADER_IN       => '0',
+            INT_SLAVE_DATAREADY_OUT   => buf_to_hub_REPLY_DATAREADY(i),
+            INT_SLAVE_DATA_OUT        => buf_to_hub_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_SLAVE_PACKET_NUM_OUT  => buf_to_hub_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_SLAVE_READ_IN         => buf_to_hub_REPLY_READ(i),
+            INT_SLAVE_DATAREADY_IN    => hub_to_buf_REPLY_DATAREADY(i),
+            INT_SLAVE_DATA_IN         => hub_to_buf_REPLY_DATA((i+1)*DATA_WIDTH-1 downto i*DATA_WIDTH),
+            INT_SLAVE_PACKET_NUM_IN   => hub_to_buf_REPLY_PACKET_NUM((i+1)*NUM_WIDTH-1 downto i*NUM_WIDTH),
+            INT_SLAVE_READ_OUT        => hub_to_buf_REPLY_READ(i),
+            -- Status and control port
+            STAT_FIFO_TO_INT          => open,
+            STAT_FIFO_TO_APL          => open
+            );
+      end generate;
+    end generate;
+  end generate;
 --rearrange vectors for hub logic
   gen_rearrange : for CHANNEL in 0 to 2**(MUX_WIDTH-1)-1 generate
     constant api_num         : integer := calc_special_number(CHANNEL, API_NUMBER, API_CHANNELS);
     constant trg_num         : integer := calc_special_number(CHANNEL, TRG_NUMBER, TRG_CHANNELS);
-    constant first_point_num : integer := calc_first_point_number(MII_NUMBER, CHANNEL, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
+    constant first_point_num : integer := calc_first_point_number(MII_NUMBER, CHANNEL, HUB_CTRL_CHANNELNUM, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
+    constant is_ctrl_channel : integer := calc_is_ctrl_channel(CHANNEL, HUB_CTRL_CHANNELNUM);
   begin
     gen_hublogicsignals1 : for mii in 0 to MII_NUMBER-1 generate
       constant buf_to_hub_num : integer := mii*2**(MUX_WIDTH-1)+CHANNEL;
@@ -524,53 +726,95 @@ begin
       HUB_REPLY_READ_IN (hublogic_num)
                                 <= hub_to_buf_REPLY_READ(buf_to_hub_num);
     end generate;
-    
-    gen_hublogicsignals2 : for api in 0 to api_num-1 generate
-      constant hublogic_num   : integer := first_point_num + 2**(MUX_WIDTH-1) + calc_special_number(CHANNEL, api, API_CHANNELS);
-      constant buf_to_hub_num : integer := 2**(MUX_WIDTH-1)*MII_NUMBER + calc_special_number(CHANNEL, api, API_CHANNELS);
+    gen_hublogicsignal_ctrl: if is_ctrl_channel = 1 generate
+      constant hublogic_num   : integer := first_point_num + MII_NUMBER; --!num of mii not num of channels!
+      constant buf_to_hub_num : integer := 2**(MUX_WIDTH-1)*MII_NUMBER;
     begin
-      h1: if API_CHANNELS(api) = CHANNEL generate
-        HUB_INIT_DATAREADY_IN (hublogic_num)
-                                  <= buf_to_hub_INIT_DATAREADY(buf_to_hub_num);
-        HUB_INIT_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
-                                  <= buf_to_hub_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
-        HUB_INIT_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
-                                  <= buf_to_hub_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
-        buf_to_hub_INIT_READ(buf_to_hub_num)
-                                  <= HUB_INIT_READ_OUT(hublogic_num);
-  
-        hub_to_buf_INIT_DATAREADY(buf_to_hub_num)
-                                  <= HUB_INIT_DATAREADY_OUT(hublogic_num);
-        hub_to_buf_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
-                                  <= HUB_INIT_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
-        hub_to_buf_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
-                                  <= HUB_INIT_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
-        HUB_INIT_READ_IN (hublogic_num)
-                                  <= hub_to_buf_INIT_READ(buf_to_hub_num);
-  
-        HUB_REPLY_DATAREADY_IN (hublogic_num)
-                                  <= buf_to_hub_REPLY_DATAREADY(buf_to_hub_num);
-        HUB_REPLY_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
-                                  <= buf_to_hub_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
-        HUB_REPLY_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
-                                  <= buf_to_hub_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
-        buf_to_hub_REPLY_READ(buf_to_hub_num)
-                                  <= HUB_REPLY_READ_OUT(hublogic_num);
-  
-        hub_to_buf_REPLY_DATAREADY(buf_to_hub_num)
-                                  <= HUB_REPLY_DATAREADY_OUT(hublogic_num);
-        hub_to_buf_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
-                                  <= HUB_REPLY_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
-        hub_to_buf_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
-                                  <= HUB_REPLY_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
-        HUB_REPLY_READ_IN (hublogic_num)
-                                  <= hub_to_buf_REPLY_READ(buf_to_hub_num);
+      HUB_INIT_DATAREADY_IN (hublogic_num)
+                                <= buf_to_hub_INIT_DATAREADY(buf_to_hub_num);
+      HUB_INIT_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
+                                <= buf_to_hub_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
+      HUB_INIT_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
+                                <= buf_to_hub_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
+      buf_to_hub_INIT_READ(buf_to_hub_num)
+                                <= HUB_INIT_READ_OUT(hublogic_num);
+
+      hub_to_buf_INIT_DATAREADY(buf_to_hub_num)
+                                <= HUB_INIT_DATAREADY_OUT(hublogic_num);
+      hub_to_buf_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
+                                <= HUB_INIT_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
+      hub_to_buf_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
+                                <= HUB_INIT_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
+      HUB_INIT_READ_IN (hublogic_num)
+                                <= hub_to_buf_INIT_READ(buf_to_hub_num);
+
+      HUB_REPLY_DATAREADY_IN (hublogic_num)
+                                <= buf_to_hub_REPLY_DATAREADY(buf_to_hub_num);
+      HUB_REPLY_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
+                                <= buf_to_hub_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
+      HUB_REPLY_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
+                                <= buf_to_hub_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
+      buf_to_hub_REPLY_READ(buf_to_hub_num)
+                                <= HUB_REPLY_READ_OUT(hublogic_num);
+
+      hub_to_buf_REPLY_DATAREADY(buf_to_hub_num)
+                                <= HUB_REPLY_DATAREADY_OUT(hublogic_num);
+      hub_to_buf_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
+                                <= HUB_REPLY_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
+      hub_to_buf_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
+                                <= HUB_REPLY_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
+      HUB_REPLY_READ_IN (hublogic_num)
+                                <= hub_to_buf_REPLY_READ(buf_to_hub_num);
+    end generate;
+    g5: if api_num /= 0 generate
+      gen_hublogicsignals2 : for api in 0 to api_num-1 generate
+        constant hublogic_num   : integer := first_point_num + MII_NUMBER + is_ctrl_channel + calc_special_number(CHANNEL, api, API_CHANNELS);
+        constant buf_to_hub_num : integer := 2**(MUX_WIDTH-1)*MII_NUMBER + is_ctrl_channel + api;
+                    --calc_special_number(CHANNEL, api, API_CHANNELS)
+      begin
+        h1: if API_CHANNELS(api) = CHANNEL generate
+          HUB_INIT_DATAREADY_IN (hublogic_num)
+                                    <= buf_to_hub_INIT_DATAREADY(buf_to_hub_num);
+          HUB_INIT_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
+                                    <= buf_to_hub_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
+          HUB_INIT_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
+                                    <= buf_to_hub_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
+          buf_to_hub_INIT_READ(buf_to_hub_num)
+                                    <= HUB_INIT_READ_OUT(hublogic_num);
+    
+          hub_to_buf_INIT_DATAREADY(buf_to_hub_num)
+                                    <= HUB_INIT_DATAREADY_OUT(hublogic_num);
+          hub_to_buf_INIT_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
+                                    <= HUB_INIT_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
+          hub_to_buf_INIT_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
+                                    <= HUB_INIT_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
+          HUB_INIT_READ_IN (hublogic_num)
+                                    <= hub_to_buf_INIT_READ(buf_to_hub_num);
+    
+          HUB_REPLY_DATAREADY_IN (hublogic_num)
+                                    <= buf_to_hub_REPLY_DATAREADY(buf_to_hub_num);
+          HUB_REPLY_DATA_IN ((hublogic_num+1)*16-1 downto hublogic_num*16)
+                                    <= buf_to_hub_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16);
+          HUB_REPLY_PACKET_NUM_IN ((hublogic_num+1)*2-1 downto hublogic_num*2)
+                                    <= buf_to_hub_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2);
+          buf_to_hub_REPLY_READ(buf_to_hub_num)
+                                    <= HUB_REPLY_READ_OUT(hublogic_num);
+    
+          hub_to_buf_REPLY_DATAREADY(buf_to_hub_num)
+                                    <= HUB_REPLY_DATAREADY_OUT(hublogic_num);
+          hub_to_buf_REPLY_DATA((buf_to_hub_num+1)*16-1 downto buf_to_hub_num*16)
+                                    <= HUB_REPLY_DATA_OUT((hublogic_num+1)*16-1 downto hublogic_num*16);
+          hub_to_buf_REPLY_PACKET_NUM((buf_to_hub_num+1)*2-1 downto buf_to_hub_num*2)
+                                    <= HUB_REPLY_PACKET_NUM_OUT((hublogic_num+1)*2-1 downto hublogic_num*2);
+          HUB_REPLY_READ_IN (hublogic_num)
+                                    <= hub_to_buf_REPLY_READ(buf_to_hub_num);
+        end generate;
       end generate;
     end generate;
     g3: if trg_num /= 0 generate
-        gen_hublogicsignals3 : for trg in 0 to trg_num-1 generate
-        constant hublogic_num   : integer := first_point_num + 2**(MUX_WIDTH-1) + api_num + calc_special_number(CHANNEL, trg, TRG_CHANNELS);
-        constant buf_to_hub_num : integer := 2**(MUX_WIDTH-1)*MII_NUMBER + api_num + calc_special_number(CHANNEL, trg, TRG_CHANNELS);
+      gen_hublogicsignals3 : for trg in 0 to trg_num-1 generate
+        constant hublogic_num   : integer := first_point_num + MII_NUMBER + is_ctrl_channel + api_num + calc_special_number(CHANNEL, trg, TRG_CHANNELS);
+        constant buf_to_hub_num : integer := 2**(MUX_WIDTH-1)*MII_NUMBER + is_ctrl_channel + api_num + trg;
       begin
         h1: if TRG_CHANNELS(trg) = CHANNEL generate
           HUB_INIT_DATAREADY_IN (hublogic_num)
@@ -615,8 +859,8 @@ begin
 
 --generate hub logic
   gen_hub_logic: for i in 0 to 2**(MUX_WIDTH-1)-1 generate
-    constant point_num       : integer := calc_point_number      (MII_NUMBER, i, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
-    constant first_point_num : integer := calc_first_point_number(MII_NUMBER, i, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
+    constant point_num       : integer := calc_point_number      (MII_NUMBER, i, HUB_CTRL_CHANNELNUM, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
+    constant first_point_num : integer := calc_first_point_number(MII_NUMBER, i, HUB_CTRL_CHANNELNUM, API_NUMBER, API_CHANNELS, TRG_NUMBER, TRG_CHANNELS);
     constant next_point_num  : integer := first_point_num + point_num;
   begin
     HUBLOGIC : trb_net16_hub_logic
index cb5687d42f8d863f3c201494c0e0aad3941991be..67b9b44ea1b01a1c658ccf67608e529e8fa39c31 100644 (file)
@@ -6,11 +6,12 @@ use work.trb_net_std.all;
 
 package trb_net16_hub_func is
 
-  type hub_iobuf_config_t is array(0 to 255) of integer;
+  type hub_iobuf_config_t is array(0 to 63) of integer;
   type hub_api_config_t is array(0 to 15) of integer;
 
   function calc_point_number (MII_NUMBER   : integer;
                               CHANNEL      : integer;
+                              HUB_CTRL_CHANNEL : integer;
                               API_NUMBER   : integer;
                               API_CHANNELS : hub_api_config_t;
                               TRG_NUMBER   : integer;
@@ -22,11 +23,13 @@ package trb_net16_hub_func is
                       API_DEPTH       : hub_api_config_t;
                       MII_NUMBER      : integer;
                       API_NUMBER      : integer;
-                      MUX_WIDTH       : integer)
+                      MUX_WIDTH       : integer;
+                      HUB_CTRL_DEPTH : integer)
     return integer;
 
   function calc_first_point_number (MII_NUMBER : integer;
                               CHANNEL      : integer;
+                              HUB_CTRL_CHANNEL : integer;
                               API_NUMBER   : integer;
                               API_CHANNELS : hub_api_config_t;
                               TRG_NUMBER   : integer;
@@ -39,6 +42,9 @@ package trb_net16_hub_func is
     return integer;
 
 
+  function calc_is_ctrl_channel(CHANNEL : integer; HUB_CTRL_CHANNEL : integer)
+    return integer;
+
   function reportint(i : integer)
     return integer;
 
@@ -47,6 +53,16 @@ end package trb_net16_hub_func;
 
 package body trb_net16_hub_func is
 
+  function calc_is_ctrl_channel(CHANNEL : integer; HUB_CTRL_CHANNEL : integer)
+    return integer is
+    begin
+      if CHANNEL = HUB_CTRL_CHANNEL then
+        return 1;
+      else
+        return 0;
+      end if;
+    end function;
+
   function reportint(i : integer)
     return integer is
     begin
@@ -56,6 +72,7 @@ package body trb_net16_hub_func is
 
   function calc_point_number (MII_NUMBER   : integer;
                               CHANNEL      : integer;
+                              HUB_CTRL_CHANNEL : integer;
                               API_NUMBER   : integer;
                               API_CHANNELS : hub_api_config_t;
                               TRG_NUMBER   : integer;
@@ -64,13 +81,16 @@ package body trb_net16_hub_func is
     variable tmp : integer := 0;
     begin
       tmp := MII_NUMBER;
-      report "MII"&integer'image(tmp);
-      for i in 0 to API_NUMBER-1 loop
-        if(API_CHANNELS(i) = CHANNEL) then
-          tmp := tmp + 1;
-        end if;
-      end loop;
-      report "API"&integer'image(tmp);
+      if HUB_CTRL_CHANNEL = CHANNEL then
+        tmp := tmp + 1;
+      end if;
+      if API_NUMBER /= 0 then
+        for i in 0 to API_NUMBER-1 loop
+          if(API_CHANNELS(i) = CHANNEL) then
+            tmp := tmp + 1;
+          end if;
+        end loop;
+      end if;
       if TRG_NUMBER /= 0 then
         for i in 0 to TRG_NUMBER-1 loop
           if(TRG_CHANNELS(i) = CHANNEL) then
@@ -78,7 +98,6 @@ package body trb_net16_hub_func is
           end if;
         end loop;
       end if;
-      report "ALL"&integer'image(tmp);
       return tmp;
     end function;
 
@@ -88,6 +107,7 @@ package body trb_net16_hub_func is
     return integer is
     variable tmp : integer := 0;
     begin
+      tmp := 0;
       if NUMBER /= 0 then
         for i in 0 to NUMBER-1 loop
           if(CHANNELS(i) = CHANNEL) then
@@ -103,11 +123,15 @@ package body trb_net16_hub_func is
                       API_DEPTH    : hub_api_config_t;
                       MII_NUMBER   : integer;
                       API_NUMBER   : integer;
-                      MUX_WIDTH    : integer)
+                      MUX_WIDTH    : integer;
+                      HUB_CTRL_DEPTH : integer)
     return integer is
     begin
       if(POINT < MII_NUMBER*2**(MUX_WIDTH-1)) then
-        return MII_DEPTH((POINT / MII_NUMBER)*16 + (POINT mod MII_NUMBER));
+        report integer'image(MII_DEPTH((POINT / 2**(MUX_WIDTH-1))*4 + (POINT mod 2**(MUX_WIDTH-1))));
+        return MII_DEPTH((POINT / 2**(MUX_WIDTH-1))*4 + (POINT mod 2**(MUX_WIDTH-1)));
+      elsif(POINT = MII_NUMBER*2**(MUX_WIDTH-1)) then
+        return HUB_CTRL_DEPTH;
       elsif POINT < MII_NUMBER*2**(MUX_WIDTH-1) + API_NUMBER then
         return API_DEPTH(POINT-(MII_NUMBER*2**(MUX_WIDTH-1)));
       else
@@ -118,6 +142,7 @@ package body trb_net16_hub_func is
 
   function calc_first_point_number (MII_NUMBER   : integer;
                                     CHANNEL      : integer;
+                                    HUB_CTRL_CHANNEL : integer;
                                     API_NUMBER   : integer;
                                     API_CHANNELS : hub_api_config_t;
                                     TRG_NUMBER   : integer;
@@ -128,8 +153,9 @@ package body trb_net16_hub_func is
       if CHANNEL = 0 then
         return 0;
       end if;
+      tmp := 0;
       for i in 0 to CHANNEL-1 loop
-        tmp := tmp + calc_point_number(MII_NUMBER,i,API_NUMBER,API_CHANNELS,TRG_NUMBER,TRG_CHANNELS);
+        tmp := tmp + calc_point_number(MII_NUMBER,i,HUB_CTRL_CHANNEL,API_NUMBER,API_CHANNELS,TRG_NUMBER,TRG_CHANNELS);
       end loop;
       return tmp;
     end function;
index c005425d0c6e92fc22b7066d22bb231eeccd3b38..9730b4fb8682fd0fd6a607bbefc13f13574ce2fe 100644 (file)
@@ -178,7 +178,7 @@ process(clock)
   begin
     if rising_edge(clock) then
       if fifo_gsr = '1' or (empty = '0' and emptyg = '1') then
-        read_after_empty <= '0';
+        read_after_empty <= empty;
       elsif read_enable_in = '1' then
         read_after_empty <= '1';
       end if;
index 7e8cafcfe050b6865bae64925a708e7cf265ef24..91fb10d03b1c63b1afbba7db14c3116597956fcb 100644 (file)
@@ -141,16 +141,16 @@ begin
     reg_empty: process(CLK)
     begin
       if rising_edge(CLK) then
-      if RESET = '1' then
-        current_EMPTY <= '1';
-        current_FULL <= '0';
-      elsif CLK_EN = '1' then
-        current_EMPTY <= next_EMPTY;
-        current_FULL  <= next_FULL;
-      else
-        current_EMPTY <= current_EMPTY;
-        current_FULL  <= current_FULL;
-      end if;
+        if RESET = '1' then
+          current_EMPTY <= '1';
+          current_FULL <= '0';
+        elsif CLK_EN = '1' then
+          current_EMPTY <= next_EMPTY;
+          current_FULL  <= next_FULL;
+        else
+          current_EMPTY <= current_EMPTY;
+          current_FULL  <= current_FULL;
+        end if;
       end if;
     end process;