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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [bench/] [vhdl/] [axi_tb.vhd] - Blame information for rev 89

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 84 JonasDC
----------------------------------------------------------------------  
2
----  axi_tb                                                      ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    testbench for the AXI-Lite interface, functions are       ----
10
----    provided to read and write data                           ----
11
----    writes bus transfers to out/axi_output                    ----
12
----                                                              ----
13
----  Dependencies:                                               ----
14
----    - mod_sim_exp_core                                        ----
15
----                                                              ----
16
----  Authors:                                                    ----
17
----      - Geoffrey Ottoy, DraMCo research group                 ----
18
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
19
----                                                              ---- 
20
---------------------------------------------------------------------- 
21
----                                                              ---- 
22
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
23
----                                                              ---- 
24
---- This source file may be used and distributed without         ---- 
25
---- restriction provided that this copyright statement is not    ---- 
26
---- removed from the file and that any derivative work contains  ---- 
27
---- the original copyright notice and the associated disclaimer. ---- 
28
----                                                              ---- 
29
---- This source file is free software; you can redistribute it   ---- 
30
---- and/or modify it under the terms of the GNU Lesser General   ---- 
31
---- Public License as published by the Free Software Foundation; ---- 
32
---- either version 2.1 of the License, or (at your option) any   ---- 
33
---- later version.                                               ---- 
34
----                                                              ---- 
35
---- This source is distributed in the hope that it will be       ---- 
36
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
37
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
38
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
39
---- details.                                                     ---- 
40
----                                                              ---- 
41
---- You should have received a copy of the GNU Lesser General    ---- 
42
---- Public License along with this source; if not, download it   ---- 
43
---- from http://www.opencores.org/lgpl.shtml                     ---- 
44
----                                                              ---- 
45
----------------------------------------------------------------------
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_unsigned.all;
49
 
50
library std;
51
use std.textio.all;
52
 
53
library ieee;
54
use ieee.std_logic_textio.all;
55
 
56
entity axi_tb is
57
end axi_tb;
58
 
59
architecture arch of axi_tb is
60
  -- constants
61
  constant CLK_PERIOD : time := 10 ns;
62
  constant C_S_AXI_DATA_WIDTH : integer := 32;
63
  constant C_S_AXI_ADDR_WIDTH : integer := 32;
64
 
65
  file output : text open write_mode is "out/axi_output.txt";
66
 
67
  ------------------------------------------------------------------
68
  -- Core parameters
69
  ------------------------------------------------------------------
70
  constant C_NR_BITS_TOTAL   : integer := 1536;
71
  constant C_NR_STAGES_TOTAL : integer := 96;
72
  constant C_NR_STAGES_LOW   : integer := 32;
73
  constant C_SPLIT_PIPELINE  : boolean := true;
74
  constant C_FIFO_DEPTH      : integer := 32; -- set to (maximum exponent width)/16
75
  constant C_MEM_STYLE       : string  := "generic"; -- xil_prim, generic, asym are valid options
76
  constant C_FPGA_MAN        : string  := "xilinx";  -- xilinx, altera are valid options
77
  constant C_BASEADDR        : std_logic_vector(0 to 31) := x"A0000000";
78
  constant C_HIGHADDR        : std_logic_vector(0 to 31) := x"A0007FFF";
79
 
80
  -------------------------
81
  -- AXI4lite interface
82
  -------------------------
83
  --- Global signals
84
  signal S_AXI_ACLK    : std_logic;
85
  signal S_AXI_ARESETN : std_logic;
86
  --- Write address channel
87
  signal S_AXI_AWADDR  : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
88
  signal S_AXI_AWVALID : std_logic;
89
  signal S_AXI_AWREADY : std_logic;
90
  --- Write data channel
91
  signal S_AXI_WDATA  : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
92
  signal S_AXI_WVALID : std_logic;
93
  signal S_AXI_WREADY : std_logic;
94
  signal S_AXI_WSTRB  : std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
95
  --- Write response channel
96
  signal S_AXI_BVALID : std_logic;
97
  signal S_AXI_BREADY : std_logic;
98
  signal S_AXI_BRESP  : std_logic_vector(1 downto 0);
99
  --- Read address channel
100
  signal S_AXI_ARADDR  : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
101
  signal S_AXI_ARVALID : std_logic;
102
  signal S_AXI_ARREADY : std_logic;
103
  --- Read data channel
104
  signal S_AXI_RDATA  : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
105
  signal S_AXI_RVALID : std_logic;
106
  signal S_AXI_RREADY : std_logic;
107
  signal S_AXI_RRESP  : std_logic_vector(1 downto 0);
108
 
109
begin
110
 
111
  ------------------------------------------
112
  -- Generate clk
113
  ------------------------------------------
114
  clk_process : process
115
  begin
116
    while (true) loop
117
      S_AXI_ACLK <= '0';
118
      wait for CLK_PERIOD/2;
119
      S_AXI_ACLK <= '1';
120
      wait for CLK_PERIOD/2;
121
    end loop;
122
  end process;
123
 
124
 
125
  stim_proc : process
126
 
127
    variable Lw : line;
128
 
129
    procedure waitclk(n : natural := 1) is
130
    begin
131
      for i in 1 to n loop
132
        wait until rising_edge(S_AXI_ACLK);
133
      end loop;
134
    end waitclk;
135
 
136
    procedure axi_write( address : std_logic_vector(31 downto 0);
137
                         data    : std_logic_vector(31 downto 0) ) is
138
      variable counter : integer := 0;
139
    begin
140
      -- place address on the bus
141
      wait until rising_edge(S_AXI_ACLK);
142
      S_AXI_AWADDR <= address;
143
      S_AXI_AWVALID <= '1';
144
      S_AXI_WDATA <= data;
145
      S_AXI_WVALID <= '1';
146
      S_AXI_WSTRB <= "1111";
147
      while (counter /= 2) loop -- wait for slave response
148
        wait until rising_edge(S_AXI_ACLK);
149
        if (S_AXI_AWREADY='1') then
150
          S_AXI_AWVALID <= '0';
151
          counter := counter+1;
152
        end if;
153
        if (S_AXI_WREADY='1') then
154
          S_AXI_WVALID <= '0';
155
          counter := counter+1;
156
        end if;
157
      end loop;
158
      S_AXI_BREADY <= '1';
159
      if S_AXI_BVALID/='1' then
160
        wait until S_AXI_BVALID='1';
161
      end if;
162
 
163
      write(Lw, string'("Wrote "));
164
      hwrite(Lw, data);
165
      write(Lw, string'(" to   "));
166
      hwrite(Lw, address);
167
 
168
      if (S_AXI_BRESP /= "00") then
169
        write(Lw, string'("   --> Error! Status: "));
170
        write(Lw, S_AXI_BRESP);
171
      end if;
172
      writeline(output, Lw);
173
 
174
      wait until rising_edge(S_AXI_ACLK);
175
      S_AXI_BREADY <= '0';
176
    end axi_write;
177
 
178
    procedure axi_read( address  : std_logic_vector(31 downto 0) ) is
179
    begin
180
      -- place address on the bus
181
      wait until rising_edge(S_AXI_ACLK);
182
      S_AXI_ARADDR <= address;
183
      S_AXI_ARVALID <= '1';
184
      wait until S_AXI_ARREADY='1';
185
      wait until rising_edge(S_AXI_ACLK);
186
      S_AXI_ARVALID <= '0';
187
      -- wait for read data
188
      S_AXI_RREADY <= '1';
189
      wait until S_AXI_RVALID='1';
190
      wait until rising_edge(S_AXI_ACLK);
191
 
192
      write(Lw, string'("Read  "));
193
      hwrite(Lw, S_AXI_RDATA);
194
      write(Lw, string'(" from "));
195
      hwrite(Lw, address);
196
 
197
      if (S_AXI_RRESP /= "00") then
198
        write(Lw, string'("   --> Error! Status: "));
199
        write(Lw, S_AXI_RRESP);
200
      end if;
201
      writeline(output, Lw);
202
      S_AXI_RREADY <= '0';
203
 
204
      --assert false report "Wrote " & " to " & " Status=" & to_string(S_AXI_BRESP) severity note;
205
    end axi_read;
206
 
207
 
208
  begin
209
 
210
    write(Lw, string'("----------------------------------------------"));
211
    writeline(output, Lw);
212
    write(Lw, string'("--            AXI BUS SIMULATION            --"));
213
    writeline(output, Lw);
214
    write(Lw, string'("----------------------------------------------"));
215
    writeline(output, Lw);
216
    S_AXI_AWADDR <= (others=>'0');
217
    S_AXI_AWVALID <= '0';
218
    S_AXI_WDATA <= (others=>'0');
219
    S_AXI_WVALID <= '0';
220
    S_AXI_WSTRB <= (others=>'0');
221
    S_AXI_BREADY <= '0';
222
    S_AXI_ARADDR <= (others=>'0');
223
    S_AXI_ARVALID <= '0';
224
    S_AXI_RREADY <= '0';
225
 
226
    S_AXI_ARESETN <= '0';
227
    waitclk(10);
228
    S_AXI_ARESETN <= '1';
229
    waitclk(20);
230
 
231
    axi_write(x"A0000000", x"11111111");
232
    axi_read(x"A0000000");
233
    axi_write(x"A0001000", x"01234567");
234
    axi_read(x"A0001000");
235
    axi_write(x"A0002000", x"AAAAAAAA");
236
    axi_read(x"A0002000");
237
    axi_write(x"A0003000", x"BBBBBBBB");
238
    axi_read(x"A0003000");
239
    axi_write(x"A0004000", x"CCCCCCCC");
240
    axi_read(x"A0004000");
241
    axi_write(x"A0005000", x"DDDDDDDD");
242
    axi_read(x"A0005000");
243
    axi_write(x"A0006000", x"EEEEEEEE");
244
    axi_read(x"A0006000");
245
    axi_write(x"A0007000", x"FFFFFFFF");
246
    axi_read(x"A0007000");
247
    axi_write(x"A0008000", x"22222222");
248
    axi_read(x"A0008000");
249
    axi_write(x"A0009000", x"33333333");
250
    axi_read(x"A0009000");
251
    axi_write(x"A000A000", x"44444444");
252
    axi_read(x"A000A000");
253
    waitclk(100);
254
 
255
    assert false report "End of simulation" severity failure;
256
 
257
  end process;
258
 
259
 
260
  -------------------------
261
  -- Unit Under Test
262
  -------------------------
263
  uut : entity work.msec_ipcore_axilite
264
  generic map(
265
    C_NR_BITS_TOTAL   => C_NR_BITS_TOTAL,
266
    C_NR_STAGES_TOTAL => C_NR_STAGES_TOTAL,
267
    C_NR_STAGES_LOW   => C_NR_STAGES_LOW,
268
    C_SPLIT_PIPELINE  => C_SPLIT_PIPELINE,
269
    C_FIFO_DEPTH      => C_FIFO_DEPTH,
270
    C_MEM_STYLE       => C_MEM_STYLE, -- xil_prim, generic, asym are valid options
271
    C_FPGA_MAN        => C_FPGA_MAN,   -- xilinx, altera are valid options
272
    C_BASEADDR        => C_BASEADDR,
273
    C_HIGHADDR        => C_HIGHADDR
274
  )
275
  port map(
276
    --USER ports
277
 
278
    -------------------------
279
    -- AXI4lite interface
280
    -------------------------
281
    --- Global signals
282
    S_AXI_ACLK    => S_AXI_ACLK,
283
    S_AXI_ARESETN => S_AXI_ARESETN,
284
    --- Write address channel
285
    S_AXI_AWADDR  => S_AXI_AWADDR,
286
    S_AXI_AWVALID => S_AXI_AWVALID,
287
    S_AXI_AWREADY => S_AXI_AWREADY,
288
    --- Write data channel
289
    S_AXI_WDATA  => S_AXI_WDATA,
290
    S_AXI_WVALID => S_AXI_WVALID,
291
    S_AXI_WREADY => S_AXI_WREADY,
292
    S_AXI_WSTRB  => S_AXI_WSTRB,
293
    --- Write response channel
294
    S_AXI_BVALID => S_AXI_BVALID,
295
    S_AXI_BREADY => S_AXI_BREADY,
296
    S_AXI_BRESP  => S_AXI_BRESP,
297
    --- Read address channel
298
    S_AXI_ARADDR  => S_AXI_ARADDR,
299
    S_AXI_ARVALID => S_AXI_ARVALID,
300
    S_AXI_ARREADY => S_AXI_ARREADY,
301
    --- Read data channel
302
    S_AXI_RDATA  => S_AXI_RDATA,
303
    S_AXI_RVALID => S_AXI_RVALID,
304
    S_AXI_RREADY => S_AXI_RREADY,
305
    S_AXI_RRESP  => S_AXI_RRESP
306
  );
307
 
308
end arch;
309
 

powered by: WebSVN 2.1.0

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