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

Subversion Repositories vhdl_wb_tb

[/] [vhdl_wb_tb/] [trunk/] [bench/] [vhdl/] [wishbone_bfm_pkg.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 sinx
---------------------------------------------------------------------- 
2
----                                                              ---- 
3
----  VHDL Wishbone TESTBENCH                                     ---- 
4
----                                                              ---- 
5
----  This file is part of the vhdl_wb_tb project                 ---- 
6
----  http://www.opencores.org/cores/vhdl_wb_tb/                  ---- 
7
----                                                              ---- 
8
----  This file contains the wishbone_bfm_pkg package and defines ----
9
----  wishbone transaction processes functions for simulation.    ---- 
10
----                                                              ---- 
11
----  To Do:                                                      ---- 
12
----   -                                                          ---- 
13
----                                                              ---- 
14
----  Author(s):                                                  ---- 
15
----      - Sinx, email@opencores.org                             ---- 
16
----                                                              ---- 
17
----------------------------------------------------------------------
18
--    SVN information
19
--
20
--      $URL:  $
21
-- $Revision:  $
22
--     $Date:  $
23
--   $Author:  $
24
--       $Id:  $
25
--
26
---------------------------------------------------------------------- 
27
----                                                              ---- 
28
---- Copyright (C) 2018 Authors and OPENCORES.ORG                 ---- 
29
----                                                              ---- 
30
---- This source file may be used and distributed without         ---- 
31
---- restriction provided that this copyright statement is not    ---- 
32
---- removed from the file and that any derivative work contains  ---- 
33
---- the original copyright notice and the associated disclaimer. ---- 
34
----                                                              ---- 
35
---- This source file is free software; you can redistribute it   ---- 
36
---- and/or modify it under the terms of the GNU Lesser General   ---- 
37
---- Public License as published by the Free Software Foundation; ---- 
38
---- either version 2.1 of the License, or (at your option) any   ---- 
39
---- later version.                                               ---- 
40
----                                                              ---- 
41
---- This source is distributed in the hope that it will be       ---- 
42
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
43
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
44
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
45
---- details.                                                     ---- 
46
----                                                              ---- 
47
---- You should have received a copy of the GNU Lesser General    ---- 
48
---- Public License along with this source; if not, download it   ---- 
49
---- from http://www.opencores.org/lgpl.shtml                     ---- 
50
----                                                              ---- 
51
----------------------------------------------------------------------
52
 
53
-- library -----------------------------------------------------------
54
library ieee;
55
use ieee.std_logic_1164.all;
56
use ieee.numeric_std.all;
57
 
58
library work;
59
use work.my_project_pkg.all;
60
use work.wishbone_pkg.all;
61
use work.convert_pkg.all;
62
 
63
-- package -----------------------------------------------------------
64
package wishbone_bfm_pkg is
65
  -- defines output signals of wb bfm (simulation only)
66
  type wishbone_bfm_master_out_t is record
67
    -- 2.2.2 Signals Common to MASTER and SLAVE Interfaces 
68
    dat : wishbone_data_t; -- data []
69
    rst : std_logic; -- reset [mandatory RULE 3.40]
70
    tgd : wishbone_tag_data_t; -- data tag []
71
    -- 2.2.3 MASTER Signals
72
    adr : wishbone_address_t; -- address [optional]
73
    cyc : std_logic; -- cycle [mandatory RULE 3.40]
74
    lock: std_logic; -- lock []
75
    sel : wishbone_byte_select_t;
76
    stb : std_logic; -- strobe [mandatory RULE 3.40]
77
    tga : wishbone_tag_address_t; -- address tag []
78
    tgc : wishbone_tag_cycle_t; -- cycle tag []
79
    we  : std_logic; -- write enable []
80
  end record wishbone_bfm_master_out_t;
81
 
82
  -- defines input signals of wb bfm (simulation only)
83
  type wishbone_bfm_master_in_t is record
84
    -- 2.2.2 Signals Common to MASTER and SLAVE Interfaces 
85
    rst : std_logic; -- reset [mandatory RULE 3.40]
86
    clk : std_logic; -- clock [mandatory RULE 3.40]
87
    dat : wishbone_data_t; -- read data []
88
    tgd : wishbone_tag_data_t; -- read data tag []
89
    -- 2.2.4 SLAVE Signals 
90
    ack : std_logic; -- acknowledge [mandatory RULE 3.40]
91
    err : std_logic; -- error [optional PERMISSION 3.20]
92
    rty : std_logic; -- retry [optional PERMISSION 3.25]
93
    --stall : std_logic;
94
    int   : std_logic; -- interrupt [non WB signal]
95
  end record wishbone_bfm_master_in_t;
96
 
97
  -- define the idle state of wb bus
98
  constant wb_bfm_master_out_idle_c : wishbone_bfm_master_out_t := (
99
                                                          dat  =>  wishbone_data_of_unused_address_c,
100
                                                          rst  =>  '0',
101
                                                          tgd  =>  (others=>'0'),
102
                                                          adr  =>  (others=>'U'),
103
                                                          cyc  =>  '0',
104
                                                          lock =>  '0',
105
                                                          sel  =>  (others=>'0'),
106
                                                          stb  =>  '0',
107
                                                          tga  =>  (others=>'0'),
108
                                                          tgc  =>  (others=>'0'),
109
                                                          we   =>  '0'
110
                                                          );
111
  ---------------------------------------------------------------------- 
112
  -- BUS FUNCTIONS -----------------------------------------------------
113
  ---------------------------------------------------------------------- 
114
  -- generate single write cycle
115
  PROCEDURE wb_write(
116
    address_i                  : IN  integer; -- address to write to
117
    data_i                     : IN  integer; -- data value to be written
118
    SIGNAL i                   : IN  wishbone_bfm_master_in_t; -- incoming wb signals
119
    SIGNAL o                   : OUT wishbone_bfm_master_out_t; -- incoming wb signals
120
    display_error_message_i    : IN  integer range 0 to 2 := 1; -- verbose mode; 0=no output, 1=error only, 2= all
121
    additional_error_message_i : IN  string  := ""
122
    );
123
 
124
  -- generate single read cycle and verify read word with expected_data_i
125
  PROCEDURE wb_read(
126
    address_i                  : IN  INTEGER;
127
    expected_data_i            : IN  INTEGER;
128
    SIGNAL i                   : IN  wishbone_bfm_master_in_t;
129
    SIGNAL o                   : OUT wishbone_bfm_master_out_t;
130
    display_error_message_i    : IN  integer range 0 to 4 := 1; -- verbose mode; 0=no output, 1=error only, 2= all, 3=use expected_data_mask_i, 4=show difference read to exp.
131
    additional_error_message_i : IN  STRING  := "";
132
    expected_data_mask_i       : IN  INTEGER := 0
133
    );
134
 
135
  -- generate single read cycle and return read data via read_data_o
136
  PROCEDURE wb_read(
137
    address_i                  : IN  INTEGER;
138
    read_data_o                : OUT STD_LOGIC_VECTOR (wishbone_address_width_c-1 DOWNTO 0);
139
    SIGNAL i                   : IN  wishbone_bfm_master_in_t;
140
    SIGNAL o                   : OUT wishbone_bfm_master_out_t
141
    );
142
  ---------------------------------------------------------------------- 
143
end;
144
 
145
-- package body ------------------------------------------------------
146
package body wishbone_bfm_pkg is
147
  ---------------------------------------------------------------------- 
148
  ---------------------------------------------------------------------- 
149
  PROCEDURE wb_write(
150
    address_i                  : IN  integer;
151
    data_i                     : IN  integer;
152
    SIGNAL i                   : IN  wishbone_bfm_master_in_t;
153
    SIGNAL o                   : OUT wishbone_bfm_master_out_t;
154
    display_error_message_i    : IN  integer range 0 to 2 := 1;
155
    additional_error_message_i : IN  string  := ""
156
    ) IS
157
    ---------------------------------------------------------------------- 
158
  BEGIN
159
    o.adr       <= to_std_logic_vector(address_i, wishbone_address_width_c);
160
    o.dat       <= to_std_logic_vector(data_i, wishbone_address_width_c);
161
    o.we        <= '1';
162
    o.rst       <= '0';
163
    o.tgd       <= (others => '0');
164
    o.cyc       <= '1';
165
    o.lock      <= '1';
166
    o.sel       <= (others => '1');
167
    o.stb       <= '1';
168
    o.tga       <= (others => '0');
169
    o.tgc       <= (others => '0');
170
    IF (display_error_message_i = 2) THEN
171
      REPORT "Writing :" & to_string(data_i, 16, wishbone_address_width_c/4) & " to: " & to_string(address_i, 16, wishbone_address_width_c/4) &
172
        additional_error_message_i;
173
    END IF;
174
 
175
    WAIT UNTIL falling_edge(i.clk);
176
    -- wait for ack
177
    WHILE i.ack = '0' LOOP
178
      WAIT UNTIL falling_edge(i.clk);
179
    END LOOP;
180
    WAIT UNTIL rising_edge(i.clk);
181
    o           <= wb_bfm_master_out_idle_c; -- reset bus
182
  END wb_write;
183
  ----------------------------------------------------------------------
184
  ----------------------------------------------------------------------
185
  PROCEDURE wb_read(
186
    address_i   : IN  INTEGER;
187
    read_data_o : OUT STD_LOGIC_VECTOR (wishbone_address_width_c-1 DOWNTO 0);
188
    SIGNAL i    : IN  wishbone_bfm_master_in_t;
189
    SIGNAL o    : OUT wishbone_bfm_master_out_t
190
    ) IS
191
    ----------------------------------------------------------------------
192
  BEGIN
193
    o.adr       <= to_std_logic_vector(address_i, wishbone_address_width_c);
194
    o.dat       <= (others => 'U');
195
    o.we        <= '0';
196
    o.rst       <= '0';
197
    o.tgd       <= (others => '0');
198
    o.cyc       <= '1';
199
    o.lock      <= '1';
200
    o.sel       <= (others => '1');
201
    o.stb       <= '1';
202
    o.tga       <= (others => '0');
203
    o.tgc       <= (others => '0');
204
    WAIT UNTIL falling_edge(i.clk);
205
    -- ack handling
206
    WHILE (i.ack = '0') LOOP
207
      WAIT UNTIL falling_edge(i.clk);
208
    END LOOP;
209
    read_data_o := i.dat;
210
    WAIT UNTIL rising_edge(i.clk);
211
    o           <= wb_bfm_master_out_idle_c; -- reset bus
212
  END wb_read;
213
  ------------------------------------------------------------------------
214
  ------------------------------------------------------------------------
215
  PROCEDURE wb_read(
216
    address_i                  : IN  INTEGER;
217
    expected_data_i            : IN  INTEGER;
218
    SIGNAL i                   : IN  wishbone_bfm_master_in_t;
219
    SIGNAL o                   : OUT wishbone_bfm_master_out_t;
220
    display_error_message_i    : IN  integer range 0 to 4 := 1;
221
    additional_error_message_i : IN  STRING  := "";
222
    expected_data_mask_i       : IN  INTEGER := 0
223
    ) IS
224
    ----------------------------------------------------------------------
225
    VARIABLE readdata_v : STD_LOGIC_VECTOR (31 DOWNTO 0);
226
    VARIABLE diff_v     : INTEGER;
227
    ----------------------------------------------------------------------
228
  BEGIN
229
    wb_read(address_i,readdata_v,i,o); -- read from bus
230
 
231
    diff_v     := to_integer(readdata_v) - expected_data_i;
232
 
233
    IF (display_error_message_i = 1) THEN -- output errors only
234
      IF (readdata_v /= to_std_logic_vector(expected_data_i, wishbone_address_width_c)) THEN
235
        REPORT "ERROR" & additional_error_message_i & ": Expected data at address 0x" & to_string(address_i, 16, wishbone_address_width_c/4) &
236
          " was: 0x" & to_string(expected_data_i, 16, wishbone_address_width_c/4) & " but read: 0x" & to_string(readdata_v,16,wishbone_address_width_c/4)
237
          SEVERITY error;
238
      END IF;
239
    ELSIF (display_error_message_i = 2) THEN  -- Output all
240
      REPORT additional_error_message_i & ": Read data at address 0x" & to_string(address_i, 16, wishbone_address_width_c/4) &
241
        " was: 0x" & to_string(readdata_v, 16, wishbone_address_width_c/4)
242
        SEVERITY note;
243
    ELSIF (display_error_message_i = 3) THEN  -- Output Filter
244
      IF ((readdata_v AND to_std_logic_vector(expected_data_mask_i, wishbone_address_width_c)) /=
245
          to_std_logic_vector(expected_data_i, wishbone_address_width_c)) THEN
246
        REPORT additional_error_message_i & ": Read data at address 0x" & to_string(address_i, 16, wishbone_address_width_c/4) &
247
          " was: 0x" & to_string(readdata_v, 16, wishbone_address_width_c/4)
248
          SEVERITY note;
249
      END IF;
250
    ELSIF display_error_message_i = 4 THEN
251
      IF (readdata_v /= to_std_logic_vector(expected_data_i, wishbone_address_width_c)) THEN
252
        REPORT "ERROR" & additional_error_message_i & ": Expected data at address 0x" & to_string(address_i, 16, wishbone_address_width_c/4) &
253
          " was: 0x" & to_string(expected_data_i, 16, wishbone_address_width_c/4) & " but read: 0x" & to_string(readdata_v,16,wishbone_address_width_c/4) & " Diff: " & to_string(readdata_v,16,wishbone_address_width_c/4)
254
          SEVERITY error;
255
      END IF;
256
    END IF;
257
  END wb_read;
258
  --------------------------------------------------------------------
259
end package body;
260
----------------------------------------------------------------------
261
---- end of file                                                  ---- 
262
----------------------------------------------------------------------

powered by: WebSVN 2.1.0

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