AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Files Variables
RTO_CALC.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 11:26:24 09/13/2013
6 -- Design Name:
7 -- Module Name: RTO_CALC - Behavioral
8 -- Project Name:
9 -- Target Devices:
10 -- Tool versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 library IEEE;
21 use IEEE.STD_LOGIC_1164.ALL;
22 use IEEE.STD_LOGIC_ARITH.ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.ALL;
24 use IEEE.std_logic_misc.all;
25 use IEEE.numeric_std.all;
26 
27 -- Uncomment the following library declaration if using
28 -- arithmetic functions with Signed or Unsigned values
29 --use IEEE.NUMERIC_STD.ALL;
30 
31 -- Uncomment the following library declaration if instantiating
32 -- any Xilinx primitives in this code.
33 --library UNISIM;
34 --use UNISIM.VComponents.all;
35 
36 entity RTO_CALC is
37  Port ( clk : in STD_LOGIC;
38  RTT : in STD_LOGIC_VECTOR (15 downto 0);
39  RTO_backoff : in STD_LOGIC;
40  LISTEN : in STD_LOGIC;
41  sample_RTT : in STD_LOGIC;
42  RTO : out STD_LOGIC_VECTOR (15 downto 0);
43  debug : out STD_LOGIC_VECTOR (135 downto 0)
44  );
45 end RTO_CALC;
46 
47 architecture Behavioral of RTO_CALC is
48 constant RTOmin : std_logic_vector(15 downto 0) := x"00f4"; -- 1 second
49 constant RTOmax : std_logic_vector(15 downto 0) := x"3938"; -- 60 seconds
50 signal first_RTT : std_logic := '1';
51 signal latch_RTO : std_logic := '1';
52 signal sample_RTT_dl : std_logic_vector(2 downto 0) := (others => '0');
53 signal RTO_i : std_logic_vector(16 downto 0) := (others => '0');
54 signal RTO_backoffed : std_logic_vector(16 downto 0) := (others => '0');
55 signal RTTVAR : std_logic_vector(16 downto 0) := (others => '0');
56 signal SRTT : std_logic_vector(15 downto 0) := (others => '0');
57 signal OneSubAlphaSRTT : std_logic_vector(15 downto 0) := (others => '0');
58 signal OneSubBetaRTTVAR : std_logic_vector(15 downto 0) := (others => '0');
59 signal BetaSRTT_SUB_RTT : std_logic_vector(14 downto 0) := (others => '0');
60 begin
61 debug(135 downto 84) <= (others => '0');
62 debug(83) <= first_RTT;
63 debug(82) <= sample_RTT;
64 debug(81 downto 65) <= RTO_i;
65 debug(64 downto 48) <= RTTVAR;
66 debug(47 downto 32) <= '0' & BetaSRTT_SUB_RTT;
67 debug(31 downto 16) <= SRTT;
68 debug(15 downto 0) <= RTT;
69 process(clk)
70 begin
71  if(clk'event and clk = '1')then
72  if(RTO_backoffed(16) = '1' or RTO_backoffed(15 downto 0) > RTOmax)then
73  RTO <= RTOmax;
74  elsif(RTO_backoffed(15 downto 0) < RTOmin)then
75  RTO <= RTOmin;
76  else
77  RTO <= RTO_backoffed(15 downto 0);
78  end if;
79  if(RTO_backoff = '1')then
80  latch_RTO <= '1';
81  elsif(sample_RTT = '1')then
82  latch_RTO <= '0';
83  end if;
84  if(RTO_backoff = '1')then
85  RTO_backoffed(16) <= RTO_backoffed(16) or RTO_backoffed(15);
86  RTO_backoffed(15 downto 0) <= RTO_backoffed(14 downto 0) & '0';
87  elsif(latch_RTO = '0')then
88  RTO_backoffed <= RTO_i;
89  end if;
90  if(first_RTT = '1')then
91  RTO_i <= '0' & x"02dc"; -- 3 second
92  elsif(RTTVAR(16 downto 14) /= "000")then
93  RTO_i(16) <= '1';
94  else
95  RTO_i <= ('0' & SRTT) + ('0' & RTTVAR(13 downto 2) & "01");
96  end if;
97  if(LISTEN = '1' or (RTO_backoff = '1' and latch_RTO = '1'))then
98  first_RTT <= '1';
99  elsif(sample_RTT = '1')then
100  first_RTT <= '0';
101  end if;
102  OneSubAlphaSRTT <= SRTT - ("000" & SRTT(15 downto 3));
103  if(RTTVAR(16) = '1')then
104  OneSubBetaRTTVAR <= x"c000";
105  else
106  OneSubBetaRTTVAR <= RTTVAR(15 downto 0) - ("00" & RTTVAR(15 downto 2));
107  end if;
108  BetaSRTT_SUB_RTT <= ('0' & SRTT(15 downto 2)) - ('0' & RTT(15 downto 2));
109  sample_RTT_dl <= sample_RTT_dl(1 downto 0) & sample_RTT;
110  if(sample_RTT_dl(2) = '1')then
111  if(first_RTT = '1')then
112  RTTVAR <= "00" & RTT(15 downto 1);
113  SRTT <= RTT;
114  else
115  if(BetaSRTT_SUB_RTT(14) = '0')then
116  RTTVAR <= ('0' & OneSubBetaRTTVAR) + ("00" & BetaSRTT_SUB_RTT);
117  else
118  RTTVAR <= ('0' & OneSubBetaRTTVAR) + ("00" & not BetaSRTT_SUB_RTT);
119  end if;
120  SRTT <= OneSubAlphaSRTT + ("000" & RTT(15 downto 3));
121  end if;
122  end if;
123  end if;
124 end process;
125 
126 end Behavioral;
127