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.communication/] [basic_tester/] [1.0/] [vhd/] [basic_tester_tx.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : A block which sends data to HIBI ver 2 and 3
3
-- Project    : Nocbench & Funbase
4
-------------------------------------------------------------------------------
5
-- File       : basic_tester_tx.vhd
6
-- Author     : ege
7
-- Created    : 2010-03-24
8
-- Last update: 2012-02-06
9
-- Description: Reads ASCII file where each line describes transfer of 1 word.
10
--              Each transfers needs 4 hexadecimal parameters:
11
--               - delay (clock cycles) after previous tx
12
--               - dst address
13
--               - data value
14
--               - command
15
--
16
-------------------------------------------------------------------------------
17
-- Copyright (c) 2010
18
-------------------------------------------------------------------------------
19
-- Revisions  :
20
-- Date        Version  Author  Description
21
-- April 2010   1.0     ege     First version
22
-------------------------------------------------------------------------------
23
-------------------------------------------------------------------------------
24
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
25
--
26
--
27
-- This source file may be used and distributed without
28
-- restriction provided that this copyright statement is not
29
-- removed from the file and that any derivative work contains
30
-- the original copyright notice and the associated disclaimer.
31
--
32
-- This source file is free software; you can redistribute it
33
-- and/or modify it under the terms of the GNU Lesser General
34
-- Public License as published by the Free Software Foundation;
35
-- either version 2.1 of the License, or (at your option) any
36
-- later version.
37
--
38
-- This source is distributed in the hope that it will be
39
-- useful, but WITHOUT ANY WARRANTY; without even the implied
40
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
41
-- PURPOSE.  See the GNU Lesser General Public License for more
42
-- details.
43
--
44
-- You should have received a copy of the GNU Lesser General
45
-- Public License along with this source; if not, download it
46
-- from http://www.opencores.org/lgpl.shtml
47
-------------------------------------------------------------------------------
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.numeric_std.all;
52
 
53
use std.textio.all;
54
use ieee.std_logic_textio.all;                     -- 2010-10-06 for hread
55
 
56
use work.basic_tester_pkg.all;            -- read_conf_file()
57
 
58
entity basic_tester_tx is
59
 
60
  generic (
61
    conf_file_g  : string  := "";
62
    comm_width_g : integer := 5;
63
    data_width_g : integer := 0
64
    );
65
  port (
66
    clk   : in std_logic;
67
    rst_n : in std_logic;
68
 
69
    done_out : out std_logic;           -- if this unit has finished
70
 
71
    -- HIBI wrapper ports
72
    agent_av_out   : out std_logic;
73
    agent_data_out : out std_logic_vector (data_width_g-1 downto 0);
74
    agent_comm_out : out std_logic_vector (comm_width_g-1 downto 0);
75
    agent_we_out   : out std_logic;
76
    agent_full_in  : in  std_logic;
77
    agent_one_p_in : in  std_logic
78
    );
79
 
80
end basic_tester_tx;
81
 
82
 
83
 
84
architecture rtl of basic_tester_tx is
85
 
86
  -- State machine
87
  type control_states is (read_conf, wait_sending, wr_addr, wr_data, finish);
88
  signal curr_state_r : control_states := read_conf;
89
 
90
  signal delay_r    : integer;          -- Counter
91
 
92
  -- Registers may be reset to 'Z' to 'X' so that reset state is clearly
93
  -- distinguished from active state. Using dbg_level_c+Rst_Value array, the
94
  -- rst value may be easily set to '0' for synthesis.
95
  constant dbg_level_c : integer range 0 to 3 := 0;  -- 0= no debug
96
  constant rst_val_arr_c : std_logic_vector (6 downto 0) :=
97
    'X' & 'Z' & 'X' & 'Z' & 'X' & 'Z' & '0';
98
  -- Right now gives a lot of warnings when other than 0
99
 
100
 
101
begin  -- rtl
102
 
103
  main : process (clk, rst_n)
104
    file conf_data_file : text open read_mode is conf_file_g;
105
 
106
    variable delay_v    : integer;
107
    variable dst_ag_v   : integer;
108
    variable data_val_v : integer;
109
    variable cmd_v      : integer;
110
 
111
  begin  -- process main
112
    if rst_n = '0' then                 -- asynchronous reset (active low)
113
      curr_state_r   <= read_conf;
114
      agent_av_out   <= '0';
115
      agent_data_out <= (others => rst_val_arr_c(dbg_level_c*1));
116
      agent_comm_out <= (others => rst_val_arr_c(dbg_level_c*1));
117
      agent_we_out   <= '0';
118
      done_out       <= '0';
119
 
120
      delay_r    <= 0;
121
      delay_v    := 0;
122
      dst_ag_v   := 0;
123
      data_val_v := 0;
124
      cmd_v      := 0;
125
 
126
    elsif clk'event and clk = '1' then  -- rising clock edge
127
 
128
      case curr_state_r is
129
 
130
        when read_conf =>
131
          if agent_full_in = '0' then
132
            -- Read next transfer from file if FIFO has space
133
            -- and the whole file has not yet been read
134
            if endfile(conf_data_file) then
135
              curr_state_r <= finish;
136
              assert false report "End of the configuration file reached"
137
                severity note;
138
            else
139
              read_conf_file (
140
                delay        => delay_v,
141
                dest_agent_n => dst_ag_v,
142
                value        => data_val_v,
143
                cmd          => cmd_v,
144
                conf_dat     => conf_data_file);
145
 
146
              -- report "delay = " & integer'image(delay_v)
147
              --  & ", dst = " & integer'image(dst_ag_v)
148
              --  & ", value = " & integer'image(data_val_v)
149
              --  & ", cmd = " & integer'image(cmd_v);
150
 
151
              -- FSM causes few empty cycles, compensate by
152
              -- decrementing delay_v
153
              delay_v := delay_v -1;
154
 
155
              if cmd_v = -1 then
156
                cmd_v := 2; --use write as default
157
              end if;
158
 
159
              if delay_v < 1 then
160
                -- Start sending directly
161
                if dst_ag_v = 0 then
162
                  curr_state_r <= wr_data;
163
                else
164
                  curr_state_r <= wr_addr;
165
                end if;
166
              else
167
                curr_state_r <= wait_sending;
168
              end if;  -- delay_v              
169
 
170
            end if;  -- endfile
171
            agent_av_out   <= '0';
172
            agent_data_out <= (others => rst_val_arr_c(dbg_level_c*1));
173
            agent_comm_out <= (others => rst_val_arr_c(dbg_level_c*1));
174
            agent_we_out   <= '0';
175
 
176
            delay_r <= delay_v;
177
 
178
          else
179
            -- Keep the old values
180
            -- i.e. either the reset values or keep sending
181
            curr_state_r <= read_conf;
182
          end if;
183
 
184
 
185
        when wait_sending =>
186
          -- Wait for a given num of cycles before sending
187
          delay_r    <= delay_r-1;
188
          if delay_r < 2 then
189
            if dst_ag_v = 0 then
190
              -- Skip the address and send data directly
191
              curr_state_r <= wr_data;
192
            else
193
              curr_state_r <= wr_addr;
194
            end if;
195
          else
196
            curr_state_r <= wait_sending;
197
          end if;
198
 
199
 
200
        when wr_addr =>
201
          if agent_full_in = '0' then
202
            -- Write the address  if there is room in HIBI's tx FIFO
203
            agent_av_out   <= '1';
204
            agent_data_out <= std_logic_vector (to_signed(dst_ag_v, data_width_g));
205
            agent_comm_out <= std_logic_vector (to_signed(cmd_v, comm_width_g));
206
            agent_we_out   <= '1';
207
            curr_state_r   <= wr_data;
208
          else
209
            -- Don't start yet, wait that there is space in FIFO
210
            agent_av_out   <= '0';
211
            agent_data_out <= (others => rst_val_arr_c(dbg_level_c*1));
212
            agent_comm_out <= (others => rst_val_arr_c(dbg_level_c*1));
213
            agent_we_out   <= '0';
214
            curr_state_r   <= wr_addr;
215
          end if;
216
 
217
 
218
 
219
        when wr_data =>
220
          if agent_full_in = '0' then
221
            -- Write the requested data value if there is
222
            -- room in HIBI's tx FIFO
223
            agent_av_out   <= '0';
224
            agent_data_out <= std_logic_vector (to_signed(data_val_v, data_width_g));
225
            agent_comm_out <= std_logic_vector (to_signed(cmd_v, comm_width_g));
226
            agent_we_out   <= '1';
227
            curr_state_r   <= read_conf;
228
 
229
          else
230
            -- Keep the old values (=adst ddress) and stay in this state
231
            curr_state_r <= wr_data;
232
          end if;
233
 
234
 
235
        when finish =>
236
          -- Notify that we're done.
237
          done_out       <= '1';
238
          agent_av_out   <= '0';
239
          agent_data_out <= (others => rst_val_arr_c(dbg_level_c*1));
240
          agent_comm_out <= (others => rst_val_arr_c(dbg_level_c*1));
241
          agent_we_out   <= '0';
242
 
243
        when others => null;
244
      end case;                         -- curr_state_r
245
 
246
    end if;                             -- rst_n/clk'event
247
  end process main;
248
 
249
end rtl;

powered by: WebSVN 2.1.0

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