]> jspc29.x-matter.uni-frankfurt.de Git - trbnet.git/commitdiff
*** empty log message ***
authorhadeshyp <hadeshyp>
Thu, 10 Jun 2010 11:26:39 +0000 (11:26 +0000)
committerhadeshyp <hadeshyp>
Thu, 10 Jun 2010 11:26:39 +0000 (11:26 +0000)
trb_net16_hub_base.vhd
trb_net16_hub_streaming_port.vhd
trb_net16_obuf.vhd

index 7844e68bc28b21e40bfd95ec2a9f0a4063ad83a6..1a369ec07bae75ca3c4b17e03d203d33eeed13ca 100644 (file)
@@ -298,6 +298,8 @@ architecture trb_net16_hub_base_arch of trb_net16_hub_base is
   signal reg_STAT_POINTS_locked  : std_logic_vector(MII_NUMBER-1 downto 0);
   signal reg_excl_enable         : std_logic_vector(MII_NUMBER-1 downto 0);
 
+  signal mii_error               : std_logic_vector(31 downto 0);
+
   attribute syn_preserve : boolean;
   attribute syn_keep : boolean;
   attribute syn_preserve of m_DATA_IN : signal is true;
@@ -1138,7 +1140,8 @@ HUB_MED_CONNECTED(31 downto MII_NUMBER) <= (others => '1');
   buf_HC_STAT_REGS(7*32-1 downto 6*32+17)  <= (others => '0');
   buf_HC_STAT_REGS(8*32-1 downto 7*32)      <= stat_ipu_fsm;
   buf_HC_STAT_REGS(16*32-1 downto 12*32)    <= HC_STAT_ack_waiting;
-  buf_HC_STAT_REGS(32*32-1 downto 16*32)    <= (others => '0');
+  buf_HC_STAT_REGS(16*32+MII_NUMBER-1 downto 16*32)    <= mii_error(MII_NUMBER-1 downto 0);
+  buf_HC_STAT_REGS(32*32-1 downto 16*32+MII_NUMBER)    <= (others => '0');
   buf_HC_STAT_REGS(36*32-1 downto 32*32)    <= HUB_STAT_ERRORBITS;
   buf_HC_STAT_REGS(64*32-1 downto 36*32)    <= (others => '0');
 
@@ -1147,6 +1150,19 @@ HUB_MED_CONNECTED(31 downto MII_NUMBER) <= (others => '1');
     buf_HC_STAT_REGS(6*32+i) <= '1' when (i < MII_NUMBER or (i = MII_NUMBER and INT_NUMBER > 0)) and MII_IS_DOWNLINK(i) = 1  else '0';
   end generate;
 
+  PROC_MED_ERROR : process(CLK)
+    begin
+      if rising_edge(CLK) then
+        gen_bits : for i in 0 to MII_NUMBER-1 loop
+          if MED_STAT_OP(i*16+7 downto i*16+4) = x"9" then
+            mii_error(i) <= '1';
+          elsif STAT_REG_STROBE(16) = '1' then
+            mii_error(i) <= '0';
+          end if;
+        end loop;
+      end if;
+    end process;
+
 
 
   PROC_TIMEOUT : process(CLK)
index 10b6fa444be3c92afc88403ababdff551a7959b6..cafe0c5922298f2c8fe9df838ea9999a600f6a97 100644 (file)
@@ -145,7 +145,7 @@ signal cts_reply_dataready_in  : std_logic;
 signal cts_reply_packet_num_in : std_logic_vector(2 downto 0);
 signal cts_reply_read_out      : std_logic;
 
-signal common_ctrl             : std_logic_vector(std_COMSTATREG*32-1 downto 0);
+signal common_ctrl             : std_logic_vector(std_COMCTRLREG*32-1 downto 0);
 signal common_stat             : std_logic_vector(std_COMSTATREG*32-1 downto 0);
 signal my_address              : std_logic_vector(15 downto 0);
 
index 40d2ec393e880aef440f6aff4da31a510857db0e..2d17da227023092935a56631f7b48c4ceb60ffb9 100644 (file)
@@ -1,4 +1,3 @@
-
 LIBRARY IEEE;
 USE IEEE.std_logic_1164.ALL;
 use ieee.numeric_std.all;
@@ -51,87 +50,107 @@ architecture trb_net16_obuf_arch of trb_net16_obuf is
   attribute syn_sharing of trb_net16_obuf_arch : architecture is "off";
 
 
-  signal current_output_data_buffer : STD_LOGIC_VECTOR (c_DATA_WIDTH-1 downto 0);
-  signal current_output_num_buffer : STD_LOGIC_VECTOR (c_NUM_WIDTH-1 downto 0);
-  signal current_ACK_word, current_EOB_word, current_DATA_word, current_NOP_word :
-    STD_LOGIC_VECTOR (15 downto 0);
-  signal comb_dataready, comb_next_read, comb_read ,sbuf_free: STD_LOGIC;
-  signal reg_INT_READ_OUT , next_INT_READ_OUT:STD_LOGIC;
-
-  signal next_SEND_ACK_IN, reg_SEND_ACK_IN : STD_LOGIC;
-  signal send_ACK, send_EOB, send_DATA : STD_LOGIC;
-
-  signal CURRENT_DATA_COUNT : unsigned (DATA_COUNT_WIDTH-1  downto 0);
---  signal max_DATA_COUNT, next_max_DATA_COUNT : STD_LOGIC_VECTOR (15 downto 0);
-  signal max_DATA_COUNT_minus_one : unsigned (DATA_COUNT_WIDTH-1 downto 0);
-  signal TRANSMITTED_BUFFERS : unsigned (1 downto 0);
-  signal increase_TRANSMITTED_BUFFERS, decrease_TRANSMITTED_BUFFERS : STD_LOGIC;
-
-  signal SEND_BUFFER_SIZE_IN : STD_LOGIC_VECTOR (3 downto 0);
-  signal REC_BUFFER_SIZE_IN  : STD_LOGIC_VECTOR (3 downto 0);
-  signal SEND_ACK_IN         : STD_LOGIC;
-  signal GOT_ACK_IN          : STD_LOGIC;
-
-  signal transfer_counter    : std_logic_vector(c_NUM_WIDTH-1 downto 0);
-  signal saved_packet_type   : std_logic_vector(2 downto 0);
-  signal reg_SEND_ACK_IN_2,next_SEND_ACK_IN_2  : std_logic;
+  signal current_output_data_buffer      : std_logic_vector (c_DATA_WIDTH-1 downto 0);
+  signal current_output_num_buffer       : std_logic_vector (c_NUM_WIDTH-1 downto 0);
+  signal current_ACK_word                : std_logic_vector (15 downto 0);
+  signal current_EOB_word                : std_logic_vector (15 downto 0);
+  signal current_DATA_word               : std_logic_vector (15 downto 0);
+  signal current_NOP_word                : std_logic_vector (15 downto 0);
+  signal comb_dataready                  : std_logic;
+  signal comb_next_read                  : std_logic;
+  signal sbuf_free                       : std_logic;
+  signal reg_INT_READ_OUT                : std_logic;
+  signal next_INT_READ_OUT               : std_logic;
+  signal next_SEND_ACK_IN                : std_logic;
+  signal reg_SEND_ACK_IN                 : std_logic;
+  signal send_ACK                        : std_logic;
+  signal send_EOB                        : std_logic;
+  signal send_DATA                       : std_logic;
+  signal CURRENT_DATA_COUNT              : unsigned (DATA_COUNT_WIDTH-1  downto 0);
+  signal max_DATA_COUNT_minus_one        : unsigned (DATA_COUNT_WIDTH-1 downto 0);
+  signal TRANSMITTED_BUFFERS             : unsigned (1 downto 0);
+  signal inc_TRANSMITTED_BUFFERS    : std_logic;
+  signal decrease_TRANSMITTED_BUFFERS    : std_logic;
+
+  signal SEND_BUFFER_SIZE_IN             : std_logic_vector (3 downto 0);
+  signal REC_BUFFER_SIZE_IN              : std_logic_vector (3 downto 0);
+  signal SEND_ACK_IN                     : std_logic;
+  signal GOT_ACK_IN                      : std_logic;
+
+  signal transfer_counter                : std_logic_vector(c_NUM_WIDTH-1 downto 0);
+  signal saved_packet_type               : std_logic_vector(2 downto 0);
+  signal reg_SEND_ACK_IN_2               : std_logic;
+  signal next_SEND_ACK_IN_2              : std_logic;
 
   type sending_state_t is (idle, sending_ack, sending_eob);
-  signal next_sending_state, sending_state : sending_state_t;
---  signal sending_state_bits : std_logic;
-
-  signal reset_DATA_COUNT : std_logic;
-  signal increase_DATA_COUNT : std_logic;
-
-  signal CRC_RESET, CRC_enable : std_logic;
-  signal CRC : std_logic_vector(15 downto 0);
-  signal buf_MED_DATAREADY_OUT : std_logic;
-  signal buf_MED_PACKET_NUM_OUT : std_logic_vector(c_NUM_WIDTH-1 downto 0);
-  signal sbuf_status : std_logic;
-  signal crc_match : std_logic;
-  signal buffer_number : unsigned(15 downto 0);
-
-  signal buf_INT_READ_OUT : std_logic;
-  signal int_dataready_in_i : std_logic;
-  signal int_data_in_i      : std_logic_vector(15 downto 0);
-  signal int_packet_num_in_i: std_logic_vector(2 downto 0);
-  signal last_buf_INT_READ_OUT : std_logic;
-
-  signal wait_for_ack_timeout : std_logic;
-  signal wait_for_ack_counter : unsigned(8 downto 0);
-  signal wait_for_ack_max_bit : std_logic_vector(2 downto 0);
-  signal timer_tick           : std_logic;
-
- attribute syn_preserve : boolean;
-  attribute syn_keep : boolean;
+  signal next_sending_state              : sending_state_t;
+  signal sending_state                   : sending_state_t;
+
+  signal reset_DATA_COUNT                : std_logic;
+  signal inc_DATA_COUNT             : std_logic;
+
+  signal CRC_RESET                       : std_logic;
+  signal CRC_enable                      : std_logic;
+  signal CRC                             : std_logic_vector(15 downto 0);
+  signal buf_MED_DATAREADY_OUT           : std_logic;
+  signal buf_MED_PACKET_NUM_OUT          : std_logic_vector(c_NUM_WIDTH-1 downto 0);
+  signal sbuf_status                     : std_logic;
+  signal crc_match                       : std_logic;
+  signal buffer_number                   : unsigned(15 downto 0);
+
+  signal buf_INT_READ_OUT                : std_logic;
+  signal int_dataready_in_i              : std_logic;
+  signal int_data_in_i                   : std_logic_vector(15 downto 0);
+  signal int_packet_num_in_i             : std_logic_vector(2 downto 0);
+  signal last_buf_INT_READ_OUT           : std_logic;
+
+  signal wait_for_ack_timeout            : std_logic;
+  signal wait_for_ack_counter            : unsigned(8 downto 0);
+  signal wait_for_ack_max_bit            : std_logic_vector(2 downto 0);
+  signal timer_tick                      : std_logic;
+
+  attribute syn_preserve : boolean;
+  attribute syn_keep     : boolean;
   attribute syn_preserve of wait_for_ack_timeout : signal is true;
   attribute syn_preserve of wait_for_ack_counter : signal is true;
   attribute syn_preserve of wait_for_ack_max_bit : signal is true;
-  attribute syn_preserve of timer_tick : signal is true;
-  attribute syn_keep of wait_for_ack_timeout : signal is true;
-  attribute syn_keep of wait_for_ack_counter : signal is true;
-  attribute syn_keep of wait_for_ack_max_bit : signal is true;
-  attribute syn_keep of timer_tick : signal is true;
+  attribute syn_preserve of timer_tick           : signal is true;
+  attribute syn_keep of wait_for_ack_timeout     : signal is true;
+  attribute syn_keep of wait_for_ack_counter     : signal is true;
+  attribute syn_keep of wait_for_ack_max_bit     : signal is true;
+  attribute syn_keep of timer_tick               : signal is true;
 
 
 begin
 
-  INT_READ_OUT <= buf_INT_READ_OUT;
+---------------------------------------------------------------------
+-- read signal to internal logic
+---------------------------------------------------------------------
   buf_INT_READ_OUT <= not int_dataready_in_i or reg_INT_READ_OUT;
 
+---------------------------------------------------------------------
+-- I/O
+---------------------------------------------------------------------
+  INT_READ_OUT       <= buf_INT_READ_OUT;
+  MED_PACKET_NUM_OUT <= buf_MED_PACKET_NUM_OUT;
+  MED_DATAREADY_OUT  <= buf_MED_DATAREADY_OUT;
 
-    SYNC_INT_DATA_INPUTS : process(CLK)
-      begin
-        if rising_edge(CLK) then
-          if RESET = '1' then
-            int_dataready_in_i <= '0';
-          elsif buf_INT_READ_OUT = '1' then --reply_dataready_in_i(i) = '0' or buf_REPLY_READ_OUT(i) = '1' then
-            int_dataready_in_i  <= INT_DATAREADY_IN;
-            int_data_in_i       <= INT_DATA_IN;
-            int_packet_num_in_i <= INT_PACKET_NUM_IN;
-          end if;
+---------------------------------------------------------------------
+-- Register inputs from internal logic
+---------------------------------------------------------------------
+
+  SYNC_INT_DATA_INPUTS : process(CLK)
+    begin
+      if rising_edge(CLK) then
+        if RESET = '1' then
+          int_dataready_in_i <= '0';
+        elsif buf_INT_READ_OUT = '1' then --reply_dataready_in_i(i) = '0' or buf_REPLY_READ_OUT(i) = '1' then
+          int_dataready_in_i  <= INT_DATAREADY_IN;
+          int_data_in_i       <= INT_DATA_IN;
+          int_packet_num_in_i <= INT_PACKET_NUM_IN;
         end if;
-      end process;
+      end if;
+    end process;
 
   proc_SAVE_INT_READ_OUT : process(CLK)
     begin
@@ -144,32 +163,30 @@ begin
       end if;
     end process;
 
---  gen_sbuf : if SECURE_MODE = 1 generate
-    THE_SBUF : trb_net16_sbuf
-      generic map (
-        VERSION => SBUF_VERSION
-        )
-      port map (
-        CLK   => CLK,
-        RESET  => RESET,
-        CLK_EN => CLK_EN,
-        COMB_DATAREADY_IN => comb_dataready,
-        COMB_next_READ_OUT => comb_next_read,
-        COMB_READ_IN => comb_read,
-        COMB_DATA_IN => current_output_data_buffer,
-        COMB_PACKET_NUM_IN => current_output_num_buffer,
-        SYN_DATAREADY_OUT => buf_MED_DATAREADY_OUT,
-        SYN_DATA_OUT => MED_DATA_OUT,
-        SYN_PACKET_NUM_OUT => buf_MED_PACKET_NUM_OUT,
-        SYN_READ_IN => MED_READ_IN,
-        STAT_BUFFER => sbuf_status
-        );
-
-  MED_PACKET_NUM_OUT <= buf_MED_PACKET_NUM_OUT;
-  MED_DATAREADY_OUT  <= buf_MED_DATAREADY_OUT;
-    comb_read    <= '1';
-
-   process(CLK)
+---------------------------------------------------------------------
+-- The SBUF to buffer data to the multiplexer
+---------------------------------------------------------------------
+  THE_SBUF : trb_net16_sbuf
+    generic map (
+      VERSION => SBUF_VERSION
+      )
+    port map (
+      CLK   => CLK,
+      RESET  => RESET,
+      CLK_EN => CLK_EN,
+      COMB_DATAREADY_IN => comb_dataready,
+      COMB_next_READ_OUT => comb_next_read,
+      COMB_READ_IN => '1',
+      COMB_DATA_IN => current_output_data_buffer,
+      COMB_PACKET_NUM_IN => current_output_num_buffer,
+      SYN_DATAREADY_OUT => buf_MED_DATAREADY_OUT,
+      SYN_DATA_OUT => MED_DATA_OUT,
+      SYN_PACKET_NUM_OUT => buf_MED_PACKET_NUM_OUT,
+      SYN_READ_IN => MED_READ_IN,
+      STAT_BUFFER => sbuf_status
+      );
+
+   proc_delay_sbuf_free : process(CLK)
       begin
         if rising_edge(CLK) then
           if RESET = '1' then
@@ -179,45 +196,42 @@ begin
           end if;
         end if;
       end process;
-    --sbuf_free    <= comb_next_read;
---   end generate;
---   gen_non_sbuf : if SECURE_MODE = 0 generate
---     MED_DATAREADY_OUT <= comb_dataready;
---     MED_DATA_OUT <= current_output_data_buffer;
---     MED_PACKET_NUM_OUT <= current_output_num_buffer;
---     sbuf_free <= MED_READ_IN;
---   end generate;
-
-
 
+---------------------------------------------------------------------
+-- Make control and status signals based on if ack. is used or not
+---------------------------------------------------------------------
   gen1 : if USE_ACKNOWLEDGE = 1 generate
     decrease_TRANSMITTED_BUFFERS <= GOT_ACK_IN;
-    send_ACK     <= SEND_ACK_IN or reg_SEND_ACK_IN or reg_SEND_ACK_IN_2;
-    next_SEND_ACK_IN_2 <= (reg_SEND_ACK_IN_2 or SEND_ACK_IN) and reg_SEND_ACK_IN;
-    send_DATA    <= not TRANSMITTED_BUFFERS(1);
-    send_EOB     <= '1' when (CURRENT_DATA_COUNT = max_DATA_COUNT_minus_one and saved_packet_type /= TYPE_TRM) else '0';
+    send_ACK                     <= SEND_ACK_IN or reg_SEND_ACK_IN or reg_SEND_ACK_IN_2;
+    next_SEND_ACK_IN_2           <= (reg_SEND_ACK_IN_2 or SEND_ACK_IN) and reg_SEND_ACK_IN;
+    send_DATA                    <= not TRANSMITTED_BUFFERS(1);
+    send_EOB                     <= '1' when (CURRENT_DATA_COUNT = max_DATA_COUNT_minus_one and saved_packet_type /= TYPE_TRM) else '0';
     -- buffer registers
-    STAT_BUFFER(1 downto 0)   <= std_logic_vector(TRANSMITTED_BUFFERS);
-    STAT_BUFFER(14 downto 2)  <= (others => '0');
-    STAT_BUFFER(15)           <= send_DATA;
-    STAT_BUFFER(20 downto 16) <= std_logic_vector(CURRENT_DATA_COUNT(4 downto 0));
-    STAT_BUFFER(31 downto 21) <= (others => '0');
-    SEND_BUFFER_SIZE_IN       <= CTRL_BUFFER(3 downto 0);
-    REC_BUFFER_SIZE_IN        <= CTRL_BUFFER(7 downto 4);
-    SEND_ACK_IN               <= CTRL_BUFFER(8);
-    GOT_ACK_IN                <= CTRL_BUFFER(9);
+    STAT_BUFFER(1 downto 0)      <= std_logic_vector(TRANSMITTED_BUFFERS);
+    STAT_BUFFER(14 downto 2)     <= (others => '0');
+    STAT_BUFFER(15)              <= send_DATA;
+    STAT_BUFFER(20 downto 16)    <= std_logic_vector(CURRENT_DATA_COUNT(4 downto 0));
+    STAT_BUFFER(31 downto 21)    <= (others => '0');
+    SEND_BUFFER_SIZE_IN          <= CTRL_BUFFER(3 downto 0);
+    REC_BUFFER_SIZE_IN           <= CTRL_BUFFER(7 downto 4);
+    SEND_ACK_IN                  <= CTRL_BUFFER(8);
+    GOT_ACK_IN                   <= CTRL_BUFFER(9);
   end generate;
 
   gen1a : if USE_ACKNOWLEDGE = 0 generate
-    send_EOB <= '0';
-    send_ACK <= '0';
-    reg_SEND_ACK_IN <= '0';
-    reg_SEND_ACK_IN_2 <= '0';
-    send_DATA <= '1';
-    CURRENT_DATA_COUNT <= (others => '0');
-    max_DATA_COUNT_minus_one <= (others => '0');
+    send_EOB                     <= '0';
+    send_ACK                     <= '0';
+    reg_SEND_ACK_IN              <= '0';
+    reg_SEND_ACK_IN_2            <= '0';
+    send_DATA                    <= '1';
+    CURRENT_DATA_COUNT           <= (others => '0');
+    max_DATA_COUNT_minus_one     <= (others => '0');
   end generate;
 
+
+---------------------------------------------------------------------
+-- Builds the three different packet types the Obuf can send: ACK, EOB, DATA
+---------------------------------------------------------------------
   GENERATE_WORDS : process (transfer_counter, saved_packet_type, int_data_in_i, CRC, buffer_number,
                             CTRL_BUFFER, send_buffer_size_in, current_data_count)
     begin
@@ -244,6 +258,9 @@ begin
      end if;
     end process;
 
+---------------------------------------------------------------------
+-- makes the packet number
+---------------------------------------------------------------------
   REG_TRANSFER_COUNTER : process(CLK)
     begin
       if rising_edge(CLK) then
@@ -259,6 +276,9 @@ begin
       end if;
     end process;
 
+---------------------------------------------------------------------
+-- save which packet type is currently be sent
+---------------------------------------------------------------------
   SAVE_PACKET_TYPE : process(CLK)
     begin
       if rising_edge(CLK) then
@@ -271,7 +291,9 @@ begin
     end process;
 
 
-
+---------------------------------------------------------------------
+-- CRC generator
+---------------------------------------------------------------------
   GEN_CRC : if USE_CHECKSUM = 1 generate
     CRC_gen : trb_net_CRC
       port map(
@@ -282,13 +304,16 @@ begin
         CRC_OUT => CRC,
         CRC_match => crc_match
         );
-  end generate GEN_CRC;
+  end generate;
 
   GEN_NO_CRC : if USE_CHECKSUM = 0 generate
     CRC <= (others => '0');
   end generate;
 
 
+---------------------------------------------------------------------
+-- The main control process (combinatorial part)
+---------------------------------------------------------------------
   --since we count only 64Bit packets, each counter is updated on the last packet
   --the EOB and ACK flags must be available when the last packet is sent.
   --full buffers (despite the sbuf) can only occur on the last packet.
@@ -301,21 +326,21 @@ begin
     begin
       current_output_data_buffer <= current_NOP_word;
       current_output_num_buffer  <= std_logic_vector(transfer_counter);
-      next_INT_READ_OUT     <= '1';
-      increase_TRANSMITTED_BUFFERS <= '0';
-      increase_DATA_COUNT <= '0';
-      reset_DATA_COUNT   <= '0';
-      next_SEND_ACK_IN   <= send_ACK;
-      comb_dataready     <= '0';
-      next_sending_state <= sending_state;
-      CRC_enable         <= '0';
-      CRC_RESET          <= RESET;
-                          --only data words are CRC'ed
-
+      next_INT_READ_OUT          <= '1';
+      inc_TRANSMITTED_BUFFERS    <= '0';
+      inc_DATA_COUNT             <= '0';
+      reset_DATA_COUNT           <= '0';
+      next_SEND_ACK_IN           <= send_ACK;
+      comb_dataready             <= '0';
+      next_sending_state         <= sending_state;
+      CRC_enable                 <= '0';
+      CRC_RESET                  <= RESET;
+
+-- if data is read from INT  --can only happen if idle or sending_data
       if (reg_INT_READ_OUT = '1' and  int_dataready_in_i = '1')  then
-                                      --can only happen if idle or sending_data
         current_output_data_buffer <= current_DATA_word;
 
+        --CRC is only used for data payload
         if int_packet_num_in_i(2) = '0' and saved_packet_type /= TYPE_TRM then
           CRC_enable <= '1';
         else
@@ -324,13 +349,14 @@ begin
 
         comb_dataready        <= '1';
         if transfer_counter = c_F3_next then
-          increase_DATA_COUNT <= '1'; --transfer_counter(1) and not transfer_counter(0);
+          inc_DATA_COUNT <= '1'; --transfer_counter(1) and not transfer_counter(0);
         end if;
+--end of current packet reached, determine next state
         if transfer_counter = c_F3 then
-          if saved_packet_type = TYPE_TRM then  -- or saved_packet_type = TYPE_EOB
+          if saved_packet_type = TYPE_TRM then
             reset_DATA_COUNT <= '1';
             CRC_RESET <= '1';
-            increase_TRANSMITTED_BUFFERS <= '1';
+            inc_TRANSMITTED_BUFFERS <= '1';
             if TRANSMITTED_BUFFERS(0) = '1' then
               next_INT_READ_OUT <= '0';
             end if;
@@ -345,6 +371,7 @@ begin
           end if;
         end if;
       end if;
+--state:  sending EOB word
       if sending_state = sending_eob  then
         next_INT_READ_OUT <= '0';
         current_output_data_buffer <= current_EOB_word;
@@ -354,11 +381,12 @@ begin
             next_sending_state <= idle;
             CRC_RESET <= '1';
             reset_DATA_COUNT <= '1';
-            increase_TRANSMITTED_BUFFERS <= '1';
+            inc_TRANSMITTED_BUFFERS <= '1';
           end if;
         end if;
       end if;
 
+--state:  sending ACK word
       if sending_state = sending_ack  then
         next_INT_READ_OUT <= '0';
         current_output_data_buffer <= current_ACK_word;
@@ -371,6 +399,7 @@ begin
         end if;
       end if;
 
+--switch to EOB / ACK sending in case of idle
       if send_EOB = '1' and transfer_counter = c_H0 and (reg_INT_READ_OUT and int_dataready_in_i) = '0' then
         next_sending_state <= sending_eob;
         next_INT_READ_OUT <= '0';
@@ -385,33 +414,37 @@ begin
       end if;
     end process;
 
---sending_state_bits <= '1' when sending_state = sending_ack else '0' when sending_state = sending_eob else 'U';
 
+---------------------------------------------------------------------
+-- Register control process signals
+---------------------------------------------------------------------
   REG1 : process(CLK)
     begin
       if rising_edge(CLK) then
         if RESET = '1' then
-          reg_INT_READ_OUT      <= '0';
-          sending_state <= idle;
+          reg_INT_READ_OUT       <= '0';
+          sending_state          <= idle;
         elsif CLK_EN = '1' then
-          reg_INT_READ_OUT      <= next_INT_READ_OUT;
-          sending_state <= next_sending_state;
+          reg_INT_READ_OUT       <= next_INT_READ_OUT;
+          sending_state          <= next_sending_state;
         end if;
       end if;
     end process;
 
   gen3 : if USE_ACKNOWLEDGE = 0 generate
-    STAT_BUFFER <= (others => '0');
+    STAT_BUFFER         <= (others => '0');
     TRANSMITTED_BUFFERS <= (others => '0');
   end generate;
 
   GEN2 : if USE_ACKNOWLEDGE = 1 generate
+
+--count sent data words
     REG_DATA_COUNT : process(CLK)
       begin
         if rising_edge(CLK) then
           if RESET = '1' or reset_DATA_COUNT = '1' then
             CURRENT_DATA_COUNT    <= (others => '0');
-          elsif CLK_EN = '1' and increase_DATA_COUNT = '1' then
+          elsif CLK_EN = '1' and inc_DATA_COUNT = '1' then
             CURRENT_DATA_COUNT    <= CURRENT_DATA_COUNT + 1;
           end if;
         end if;
@@ -430,6 +463,7 @@ begin
         end if;
       end process;
 
+-- decode maximum buffer size
       process(CLK)
         begin
          if rising_edge(CLK) then
@@ -443,6 +477,7 @@ begin
          end if;
         end process;
 
+-- count how many EOB have been sent and how many ACK have been received. transmitted_buffers is the difference between both
     reg_TRANSMITTED_BUFFERS : process(CLK)
       begin
         if rising_edge(CLK) then
@@ -450,20 +485,22 @@ begin
             TRANSMITTED_BUFFERS <= "00";
             buffer_number <= (others => '0');
           elsif CLK_EN = '1' then
-            if (increase_TRANSMITTED_BUFFERS = '1' and decrease_TRANSMITTED_BUFFERS = '0') then
+            if (inc_TRANSMITTED_BUFFERS = '1' and decrease_TRANSMITTED_BUFFERS = '0') then
               TRANSMITTED_BUFFERS <= TRANSMITTED_BUFFERS +1;
-            elsif (increase_TRANSMITTED_BUFFERS = '0' and decrease_TRANSMITTED_BUFFERS = '1') then
+            elsif (inc_TRANSMITTED_BUFFERS = '0' and decrease_TRANSMITTED_BUFFERS = '1') then
               TRANSMITTED_BUFFERS <= TRANSMITTED_BUFFERS -1;
             end if;
-            if increase_TRANSMITTED_BUFFERS = '1' then
+            if inc_TRANSMITTED_BUFFERS = '1' then
               buffer_number <= buffer_number + to_unsigned(1,1);
             end if;
           end if;
         end if;
-      end process reg_TRANSMITTED_BUFFERS;
+      end process;
   end generate;
 
-
+---------------------------------------------------------------------
+-- measure time waiting for two ACK - if too long, set error flag
+---------------------------------------------------------------------
   proc_reg_setting : process (CLK)
     begin
       if rising_edge(CLK) then
@@ -476,9 +513,9 @@ begin
     begin
       if rising_edge(CLK) then
         wait_for_ack_timeout <= '0';
-        if TRANSMITTED_BUFFERS(1) = '0' or wait_for_ack_max_bit = "000" then
+        if TRANSMITTED_BUFFERS(1) = '0' or wait_for_ack_max_bit = "000" or wait_for_ack_max_bit = "111" then
           wait_for_ack_counter <= (others => '0');
-        elsif wait_for_ack_counter(to_integer(unsigned(wait_for_ack_max_bit)+to_unsigned(1,1))) = '1' then
+        elsif wait_for_ack_counter(to_integer(unsigned(wait_for_ack_max_bit&'1'))) = '1' then
           wait_for_ack_timeout <= '1';
         elsif timer_tick = '1' then
           wait_for_ack_counter <= wait_for_ack_counter + to_unsigned(1,1);
@@ -486,19 +523,21 @@ begin
       end if;
     end process;
 
-
-STAT_DEBUG(0)    <= '0'; --comb_dataready;
-STAT_DEBUG(3 downto 1) <= "000"; --transfer_counter;
-STAT_DEBUG(4) <= '0'; --buf_MED_DATAREADY_OUT;
-STAT_DEBUG(7 downto 5) <= "000"; --buf_MED_PACKET_NUM_OUT;
-STAT_DEBUG(8) <= '0'; --sbuf_free;
-STAT_DEBUG(9) <= '0'; --comb_next_read;
-STAT_DEBUG(10) <= '0'; --SEND_ACK_IN;
-STAT_DEBUG(11) <= '0'; --reg_SEND_ACK_IN;
-STAT_DEBUG(12) <= '0'; --RESET;
-STAT_DEBUG(14 downto 13) <= std_logic_vector(TRANSMITTED_BUFFERS);
-STAT_DEBUG(17 downto 15) <= REC_BUFFER_SIZE_IN(2 downto 0);
-STAT_DEBUG(19 downto 18) <= transfer_counter(1 downto 0);  --used in hub monitoring!
-STAT_DEBUG(20) <= wait_for_ack_timeout; --used in hub monitoring
-STAT_DEBUG(31 downto 21) <= (others => '0');
+---------------------------------------------------------------------
+-- Debug output
+---------------------------------------------------------------------
+  STAT_DEBUG(0)    <= '0'; --comb_dataready;
+  STAT_DEBUG(3 downto 1) <= "000"; --transfer_counter;
+  STAT_DEBUG(4) <= '0'; --buf_MED_DATAREADY_OUT;
+  STAT_DEBUG(7 downto 5) <= "000"; --buf_MED_PACKET_NUM_OUT;
+  STAT_DEBUG(8) <= '0'; --sbuf_free;
+  STAT_DEBUG(9) <= '0'; --comb_next_read;
+  STAT_DEBUG(10) <= '0'; --SEND_ACK_IN;
+  STAT_DEBUG(11) <= '0'; --reg_SEND_ACK_IN;
+  STAT_DEBUG(12) <= '0'; --RESET;
+  STAT_DEBUG(14 downto 13) <= std_logic_vector(TRANSMITTED_BUFFERS);
+  STAT_DEBUG(17 downto 15) <= REC_BUFFER_SIZE_IN(2 downto 0);
+  STAT_DEBUG(19 downto 18) <= transfer_counter(1 downto 0);  --used in hub monitoring!
+  STAT_DEBUG(20) <= wait_for_ack_timeout; --used in hub monitoring
+  STAT_DEBUG(31 downto 21) <= (others => '0');
 end architecture;