1 ///////////////////////////////////////////////////////////////////////
3 //// WISHBONE rev.B2 Wishbone Master model ////
6 //// Author: Richard Herveille ////
7 //// richard@asics.ws ////
10 //// Downloaded from: http://www.opencores.org/projects/mem_ctrl ////
12 ///////////////////////////////////////////////////////////////////////
14 //// Copyright (C) 2001 Richard Herveille ////
15 //// richard@asics.ws ////
17 //// This source file may be used and distributed without ////
18 //// restriction provided that this copyright statement is not ////
19 //// removed from the file and that any derivative work contains ////
20 //// the original copyright notice and the associated disclaimer. ////
22 //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
23 //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
24 //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
25 //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
26 //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
27 //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
28 //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
29 //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
30 //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
31 //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
32 //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
33 //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
34 //// POSSIBILITY OF SUCH DAMAGE. ////
36 ///////////////////////////////////////////////////////////////////////
40 // $Id: wb_master_model.v,v 1.4 2004/02/28 15:40:42 rherveille Exp $
42 // $Date: 2004/02/28 15:40:42 $
44 // $Author: rherveille $
50 `include "timescale.v"
52 module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
54 parameter dwidth = 32;
55 parameter awidth = 32;
58 output [awidth -1:0] adr;
59 input [dwidth -1:0] din;
60 output [dwidth -1:0] dout;
63 output [dwidth/8 -1:0] sel;
66 ////////////////////////////////////////////////////////////////////
71 reg [awidth -1:0] adr;
72 reg [dwidth -1:0] dout;
75 reg [dwidth/8 -1:0] sel;
79 ////////////////////////////////////////////////////////////////////
86 //adr = 32'hxxxx_xxxx;
89 dout = {dwidth{1'bx}};
93 sel = {dwidth/8{1'bx}};
95 $display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)\n");
98 ////////////////////////////////////////////////////////////////////
100 // Wishbone write cycle
107 input [awidth -1:0] a;
108 input [dwidth -1:0] d;
112 // wait initial delay
113 repeat(delay) @(posedge clk);
115 // assert wishbone signal
122 sel = {dwidth/8{1'b1}};
125 // wait for acknowledge from slave
126 while(~ack) @(posedge clk);
128 // negate wishbone signals
132 adr = {awidth{1'bx}};
133 dout = {dwidth{1'bx}};
135 sel = {dwidth/8{1'bx}};
140 ////////////////////////////////////////////////////////////////////
142 // Wishbone read cycle
149 input [awidth -1:0] a;
150 output [dwidth -1:0] d;
154 // wait initial delay
155 repeat(delay) @(posedge clk);
157 // assert wishbone signals
160 dout = {dwidth{1'bx}};
164 sel = {dwidth/8{1'b1}};
167 // wait for acknowledge from slave
168 while(~ack) @(posedge clk);
170 // negate wishbone signals
174 adr = {awidth{1'bx}};
175 dout = {dwidth{1'bx}};
177 sel = {dwidth/8{1'bx}};
183 ////////////////////////////////////////////////////////////////////
185 // Wishbone compare cycle (read data from location and compare with expected data)
192 input [awidth -1:0] a;
193 input [dwidth -1:0] d_exp;
196 wb_read (delay, a, q);
199 $display("Data compare error. Received %h, expected %h at time %t", q, d_exp, $time);