OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.accelerator/] [dct_to_hibi/] [1.0/] [tb/] [tb_pinger.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
 
5
entity tb_pinger is
6
 
7
  generic (
8
    data_width_g     : integer := 32;
9
    comm_width_g     : integer := 3;
10
    own_hibi_addr_g  : integer;
11
    init_send_addr_g : integer;
12
    start_sending_g  : integer );
13
  port (
14
    clk      : in  std_logic;
15
    rst_n    : in  std_logic;
16
    data_in  : in  std_logic_vector(data_width_g-1 downto 0);
17
    comm_in  : in  std_logic_vector(comm_width_g-1 downto 0);
18
    av_in    : in  std_logic;
19
    empty_in : in  std_logic;
20
    re_out   : out std_logic;
21
    data_out : out std_logic_vector(data_width_g-1 downto 0);
22
    comm_out : out std_logic_vector(comm_width_g-1 downto 0);
23
    av_out   : out std_logic;
24
    full_in  : in  std_logic;
25
    we_out   : out std_logic);
26
 
27
end tb_pinger;
28
 
29
architecture rtl of tb_pinger is
30
 
31
  signal data_counter_r : integer;
32
signal inc_data_counter : std_logic;
33
 
34
  signal wait_delay_r    : integer;
35
  signal delay_counter_r : integer;
36
  signal ping_counter_r  : integer;
37
  type   states is (wait_data, wait_counter, send_av, send_amount, send_data);
38
  signal state           : states;
39
  signal ret_addr_r      : std_logic_vector(data_width_g-1 downto 0);
40
  signal amount_r : std_logic_vector(data_width_g-1 downto 0);
41
 
42
  signal addr_sent : std_logic;
43
  signal data_sent : std_logic;
44
  signal amount_sent : std_logic;
45
begin  -- rtl
46
 
47
  process (clk, rst_n)
48
  begin  -- process
49
    if rst_n = '0' then                 -- asynchronous reset (active low)
50
      ret_addr_r      <= std_logic_vector(to_unsigned(init_send_addr_g, data_width_g));
51
      if start_sending_g = 1 then
52
        state           <= send_av;
53
      else
54
        state <= wait_data;
55
      end if;
56
 
57
 
58
      wait_delay_r    <= 1;
59
      ping_counter_r  <= 0;
60
      delay_counter_r <= 0;
61
      data_counter_r  <= 0;
62
      amount_r <= std_logic_vector( to_unsigned( 10, data_width_g) );
63
 
64
    elsif clk'event and clk = '1' then  -- rising clock edge
65
      case state is
66
        when wait_data =>
67
          if av_in = '0' and empty_in = '0' then
68
 
69
            if data_counter_r = 0 then
70
              amount_r <= data_in;
71
            end if;
72
            if data_counter_r = 1 then
73
              ret_addr_r <= data_in;
74
            end if;
75
 
76
            if data_counter_r = to_integer(unsigned(amount_r)+1) then
77
              state          <= wait_counter;
78
              data_counter_r <= 0;
79
            else
80
              data_counter_r <= data_counter_r + 1;
81
            end if;
82
          end if;
83
 
84
        when wait_counter =>
85
          if delay_counter_r = wait_delay_r then
86
            state           <= send_av;
87
            delay_counter_r <= 0;
88
          else
89
            delay_counter_r <= delay_counter_r + 1;
90
          end if;
91
 
92
        when send_av =>
93
 
94
          if addr_sent = '1' then
95
            state <= send_amount;
96
          end if;
97
 
98
        when send_amount =>
99
          if amount_sent = '1' then
100
            state <= send_data;
101
          end if;
102
 
103
        when send_data =>
104
 
105
          if inc_data_counter = '1' then
106
            data_counter_r <= data_counter_r + 1;
107
          end if;
108
 
109
          if data_sent = '1' then
110
            state          <= wait_data;
111
            data_counter_r <= 0;
112
 
113
            if ping_counter_r = 100 then
114
              ping_counter_r <= 0;
115
              wait_delay_r   <= wait_delay_r + 1;
116
            else
117
              ping_counter_r <= ping_counter_r + 1;
118
            end if;
119
 
120
          end if;
121
      end case;
122
    end if;
123
  end process;
124
 
125
  process (full_in, state, ret_addr_r, rst_n, data_counter_r, amount_r)
126
  begin  -- process
127
    av_out    <= '0';
128
    we_out    <= '0';
129
    data_out  <= (others => '0');
130
    comm_out  <= (others => '0');
131
    re_out    <= '0';
132
    data_sent <= '0';
133
    addr_sent <= '0';
134
    amount_sent <= '0';
135
    inc_data_counter <= '0';
136
 
137
    case state is
138
      when wait_data =>
139
        re_out <= '1';
140
      when wait_counter =>
141
        re_out <= '1';
142
 
143
      when send_av =>
144
        if full_in = '0' and rst_n = '1' then
145
          we_out    <= '1';
146
          av_out    <= '1';
147
          data_out  <= ret_addr_r;
148
          comm_out  <= "010";
149
          addr_sent <= '1';
150
        end if;
151
 
152
      when send_amount =>
153
        if full_in = '0' then
154
          we_out    <= '1';
155
          data_out  <= std_logic_vector( unsigned( amount_r ) + 1 );
156
          comm_out  <= "010";
157
          amount_sent <= '1';
158
        end if;
159
 
160
      when send_data =>
161
        if full_in = '0' then
162
          we_out   <= '1';
163
          if data_counter_r = 0 then
164
            data_out <= std_logic_vector(to_unsigned(own_hibi_addr_g, data_width_g));
165
          else
166
            data_out <= std_logic_vector(to_unsigned(data_counter_r,data_width_g));
167
          end if;
168
          comm_out <= "010";
169
 
170
          inc_data_counter <= '1';
171
 
172
          if data_counter_r = to_integer( unsigned(amount_r) + 1) then
173
            data_sent <= '1';
174
          end if;
175
 
176
        end if;
177
    end case;
178
 
179
  end process;
180
 
181
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.