1 |
2 |
amulcock |
-------------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
10 |
amulcock |
---- WISHBONE Wishbone_BFM IP Core ----
|
4 |
2 |
amulcock |
---- ----
|
5 |
10 |
amulcock |
---- This file is part of the Wishbone_BFM project ----
|
6 |
|
|
---- http://www.opencores.org/cores/Wishbone_BFM/ ----
|
7 |
2 |
amulcock |
---- ----
|
8 |
|
|
---- Description ----
|
9 |
10 |
amulcock |
---- Implementation of Wishbone_BFM IP core according to ----
|
10 |
|
|
---- Wishbone_BFM IP core specification document. ----
|
11 |
2 |
amulcock |
---- ----
|
12 |
|
|
---- To Do: ----
|
13 |
|
|
---- NA ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- Author(s): ----
|
16 |
|
|
---- Andrew Mulcock, amulcock@opencores.org ----
|
17 |
|
|
---- ----
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
---- ----
|
20 |
|
|
---- Copyright (C) 2008 Authors and OPENCORES.ORG ----
|
21 |
|
|
---- ----
|
22 |
|
|
---- This source file may be used and distributed without ----
|
23 |
|
|
---- restriction provided that this copyright statement is not ----
|
24 |
|
|
---- removed from the file and that any derivative work contains ----
|
25 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- This source file is free software; you can redistribute it ----
|
28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
29 |
|
|
---- Public License as published by the Free Software Foundation ----
|
30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
31 |
|
|
---- later version. ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This source is distributed in the hope that it will be ----
|
34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
36 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
37 |
|
|
---- details. ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
40 |
|
|
---- Public License along with this source; if not, download it ----
|
41 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
42 |
|
|
---- ----
|
43 |
|
|
-------------------------------------------------------------------------------
|
44 |
|
|
---- ----
|
45 |
|
|
-- CVS Revision History ----
|
46 |
|
|
---- ----
|
47 |
|
|
-- $Log: not supported by cvs2svn $ ----
|
48 |
|
|
---- ----
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
-- file to 'exercise' the Wishbone bus.
|
52 |
|
|
--
|
53 |
|
|
-- Idea is to look like a wishbone master,
|
54 |
|
|
-- and provide procedures to exercise the bus.
|
55 |
|
|
--
|
56 |
|
|
-- syscon is an external module that provides the reset and clocks
|
57 |
|
|
-- to all the other modules in the design.
|
58 |
|
|
--
|
59 |
|
|
-- to enable the test script in this master to control
|
60 |
|
|
-- the syscon reset and clock stop,
|
61 |
|
|
-- this master provides tow 'extra' outputs
|
62 |
|
|
-- rst_i and clk_stop
|
63 |
|
|
--
|
64 |
|
|
-- when rst_sys is high, then syscon will issue a reset
|
65 |
|
|
-- when clk_stop is high, then syscon will stop the clock
|
66 |
|
|
-- on the next low transition. i.e. stopped clock is low.
|
67 |
|
|
|
68 |
|
|
use work.io_pack.all;
|
69 |
|
|
|
70 |
|
|
library ieee;
|
71 |
|
|
use ieee.std_logic_1164.all;
|
72 |
8 |
amulcock |
use ieee.std_logic_textio.all;
|
73 |
|
|
|
74 |
2 |
amulcock |
-- --------------------------------------------------------------------
|
75 |
|
|
-- --------------------------------------------------------------------
|
76 |
|
|
|
77 |
|
|
entity wb_master is
|
78 |
|
|
port(
|
79 |
|
|
-- sys_con control ports
|
80 |
|
|
RST_sys : out std_logic;
|
81 |
|
|
CLK_stop : out std_logic;
|
82 |
|
|
|
83 |
|
|
-- WISHBONE master interface:
|
84 |
|
|
RST_I : in std_logic;
|
85 |
|
|
CLK_I : in std_logic;
|
86 |
|
|
|
87 |
|
|
ADR_O : out std_logic_vector( 31 downto 0 );
|
88 |
|
|
DAT_I : in std_logic_vector( 31 downto 0 );
|
89 |
|
|
DAT_O : out std_logic_vector( 31 downto 0 );
|
90 |
|
|
WE_O : out std_logic;
|
91 |
|
|
|
92 |
|
|
STB_O : out std_logic;
|
93 |
|
|
CYC_O : out std_logic;
|
94 |
|
|
ACK_I : in std_logic;
|
95 |
|
|
ERR_I : in std_logic;
|
96 |
|
|
RTY_I : in std_logic;
|
97 |
|
|
|
98 |
|
|
LOCK_O : out std_logic;
|
99 |
|
|
SEL_O : out std_logic_vector( 3 downto 0 );
|
100 |
|
|
|
101 |
|
|
CYCLE_IS : out cycle_type
|
102 |
|
|
);
|
103 |
|
|
end entity wb_master;
|
104 |
|
|
|
105 |
|
|
-- --------------------------------------------------------------------
|
106 |
|
|
architecture Behavioral of wb_master is
|
107 |
|
|
-- --------------------------------------------------------------------
|
108 |
|
|
|
109 |
|
|
signal reset_int : std_logic;
|
110 |
|
|
|
111 |
|
|
-- --------------------------------------------------------------------
|
112 |
|
|
begin
|
113 |
|
|
-- --------------------------------------------------------------------
|
114 |
|
|
|
115 |
|
|
-- concurrent assignemente to map record to the wishbone bus
|
116 |
|
|
|
117 |
|
|
ADR_O <= bus_c.add_o; -- address bus out of master
|
118 |
|
|
DAT_O <= bus_c.dat_o; -- data bus out of master
|
119 |
|
|
WE_O <= bus_c.we; -- wite enable out of master
|
120 |
|
|
STB_O <= bus_c.stb; -- wishbone strobe out of master
|
121 |
|
|
CYC_O <= bus_c.cyc; -- wishbone cycle out of master
|
122 |
|
|
LOCK_O <= bus_c.lock; -- wishbone Lock out of master
|
123 |
|
|
SEL_O <= bus_c.sel; -- slelects which of the 4 bytes to use for 32 bit
|
124 |
|
|
CYCLE_IS <= bus_c.c_type; -- monitor output, to know what master is up to
|
125 |
|
|
|
126 |
|
|
bus_c.dat_i <= DAT_I;
|
127 |
|
|
bus_c.ack <= ACK_I;
|
128 |
|
|
bus_c.err <= ERR_I;
|
129 |
|
|
bus_c.rty <= RTY_I;
|
130 |
|
|
bus_c.clk <= CLK_I;
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
-- concurent signal as can't pass out port to procedure ?
|
134 |
|
|
RST_sys <= reset_int;
|
135 |
|
|
|
136 |
|
|
-- --------------------------------------------------------------------
|
137 |
|
|
test_loop : process
|
138 |
8 |
amulcock |
|
139 |
|
|
-- need to use variables to get 'data' down from the procedures,
|
140 |
|
|
-- if we used a signal, then we get the value after the clock edge,
|
141 |
|
|
-- which is not what we want, we need the value at the clock edge.
|
142 |
|
|
--
|
143 |
|
|
variable slv_32 : std_logic_vector( 31 downto 0);
|
144 |
|
|
|
145 |
|
|
|
146 |
2 |
amulcock |
begin
|
147 |
|
|
|
148 |
|
|
-- Wait 100 ns for global reset to finish
|
149 |
|
|
wait for 100 ns;
|
150 |
|
|
|
151 |
|
|
--clock_wait( 2, bus_c );
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
wb_init( bus_c); -- initalise wishbone bus
|
155 |
|
|
wb_rst( 2, reset_int, bus_c ); -- reset system for 2 clocks
|
156 |
|
|
|
157 |
|
|
|
158 |
8 |
amulcock |
wr_32( x"8000_0004", x"5555_5555", bus_c); -- write 32 bits address of 32 bit data
|
159 |
2 |
amulcock |
|
160 |
|
|
rd_32( x"8000_0004", slv_32, bus_c); -- read 32 bits address of 32 bit data
|
161 |
8 |
amulcock |
report to_hex( slv_32);
|
162 |
2 |
amulcock |
|
163 |
10 |
amulcock |
clock_wait( 2, bus_c );
|
164 |
|
|
|
165 |
|
|
rmw_32( x"8000_0004", slv_32, x"ABCD_EF01", bus_c );
|
166 |
|
|
report to_hex( slv_32);
|
167 |
|
|
|
168 |
|
|
clock_wait( 2, bus_c );
|
169 |
|
|
|
170 |
|
|
rmw_32( x"8000_0004", slv_32, x"01CD_EFAB", bus_c );
|
171 |
|
|
report to_hex( slv_32);
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
6 |
amulcock |
clock_wait( 1, bus_c );
|
176 |
2 |
amulcock |
wb_rst( 2, reset_int, bus_c ); -- reset system for 2 clocks
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
-- --------------------------------------------------------------------
|
184 |
|
|
-- and stop the test running
|
185 |
|
|
-- --------------------------------------------------------------------
|
186 |
|
|
|
187 |
|
|
CLK_stop <= '1';
|
188 |
|
|
wait;
|
189 |
|
|
|
190 |
|
|
end process test_loop;
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
-- --------------------------------------------------------------------
|
197 |
|
|
end architecture Behavioral;
|
198 |
|
|
-- --------------------------------------------------------------------
|