1 //////////////////////////////////////////////////////////////////////
3 //// wb_master_model.v ////
5 //// This file is part of the SPI IP core project ////
6 //// http://www.opencores.org/projects/spi/ ////
9 //// - Simon Srot (simons@opencores.org) ////
12 //// - i2c/bench/verilog/wb_master_model.v ////
13 //// Copyright (C) 2001 Richard Herveille ////
15 //// All additional information is avaliable in the Readme.txt ////
18 //////////////////////////////////////////////////////////////////////
20 //// Copyright (C) 2002 Authors ////
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. ////
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. ////
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 ////
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 ////
43 //////////////////////////////////////////////////////////////////////
45 `include "timescale.v"
47 module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
49 parameter dwidth = 32;
50 parameter awidth = 32;
53 output [awidth -1:0] adr;
54 input [dwidth -1:0] din;
55 output [dwidth -1:0] dout;
58 output [dwidth/8 -1:0] sel;
62 reg [awidth -1:0] adr;
63 reg [dwidth -1:0] dout;
66 reg [dwidth/8 -1:0] sel;
74 dout = {dwidth{1'bx}};
78 sel = {dwidth/8{1'bx}};
82 // Wishbone write cycle
87 input [awidth -1:0] a;
88 input [dwidth -1:0] d;
93 repeat(delay) @(posedge clk);
95 // assert wishbone signal
102 sel = {dwidth/8{1'b1}};
105 // wait for acknowledge from slave
106 while(~ack) @(posedge clk);
108 // negate wishbone signals
112 adr = {awidth{1'bx}};
113 dout = {dwidth{1'bx}};
115 sel = {dwidth/8{1'bx}};
120 // Wishbone read cycle
125 input [awidth -1:0] a;
126 output [dwidth -1:0] d;
130 // wait initial delay
131 repeat(delay) @(posedge clk);
133 // assert wishbone signals
136 dout = {dwidth{1'bx}};
140 sel = {dwidth/8{1'b1}};
143 // wait for acknowledge from slave
144 while(~ack) @(posedge clk);
146 // negate wishbone signals
150 adr = {awidth{1'bx}};
151 dout = {dwidth{1'bx}};
153 sel = {dwidth/8{1'bx}};
159 // Wishbone compare cycle (read data from location and compare with expected data)
164 input [awidth -1:0] a;
165 input [dwidth -1:0] d_exp;
168 wb_read (delay, a, q);
171 $display("Data compare error. Received %h, expected %h at time %t", q, d_exp, $time);