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

Subversion Repositories i2c

[/] [i2c/] [trunk/] [bench/] [verilog/] [wb_master_model.v] - Blame information for rev 72

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

Line No. Rev Author Line
1 19 rherveille
///////////////////////////////////////////////////////////////////////
2
////                                                               ////
3
////  WISHBONE rev.B2 Wishbone Master model                        ////
4
////                                                               ////
5
////                                                               ////
6
////  Author: Richard Herveille                                    ////
7
////          richard@asics.ws                                     ////
8
////          www.asics.ws                                         ////
9
////                                                               ////
10
////  Downloaded from: http://www.opencores.org/projects/mem_ctrl  ////
11
////                                                               ////
12
///////////////////////////////////////////////////////////////////////
13
////                                                               ////
14
//// Copyright (C) 2001 Richard Herveille                          ////
15
////                    richard@asics.ws                           ////
16
////                                                               ////
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.  ////
21
////                                                               ////
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.                                   ////
35
////                                                               ////
36
///////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39 10 rherveille
//
40 50 rherveille
//  $Id: wb_master_model.v,v 1.4 2004-02-28 15:40:42 rherveille Exp $
41 10 rherveille
//
42 50 rherveille
//  $Date: 2004-02-28 15:40:42 $
43
//  $Revision: 1.4 $
44 19 rherveille
//  $Author: rherveille $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//
50 10 rherveille
`include "timescale.v"
51
 
52 19 rherveille
module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
53 10 rherveille
 
54 19 rherveille
parameter dwidth = 32;
55
parameter awidth = 32;
56 10 rherveille
 
57 50 rherveille
input                  clk, rst;
58
output [awidth   -1:0]   adr;
59
input  [dwidth   -1:0]   din;
60
output [dwidth   -1:0]   dout;
61
output                 cyc, stb;
62
output                          we;
63
output [dwidth/8 -1:0] sel;
64
input                           ack, err, rty;
65 19 rherveille
 
66 10 rherveille
////////////////////////////////////////////////////////////////////
67
//
68
// Local Wires
69
//
70
 
71 50 rherveille
reg     [awidth   -1:0]  adr;
72
reg     [dwidth   -1:0]  dout;
73
reg                            cyc, stb;
74
reg                            we;
75
reg [dwidth/8 -1:0] sel;
76 10 rherveille
 
77 50 rherveille
reg [dwidth   -1:0] q;
78 19 rherveille
 
79 10 rherveille
////////////////////////////////////////////////////////////////////
80
//
81
// Memory Logic
82
//
83
 
84
initial
85
        begin
86
                //adr = 32'hxxxx_xxxx;
87
                //adr = 0;
88 19 rherveille
                adr  = {awidth{1'bx}};
89
                dout = {dwidth{1'bx}};
90 10 rherveille
                cyc  = 1'b0;
91
                stb  = 1'bx;
92
                we   = 1'hx;
93 19 rherveille
                sel  = {dwidth/8{1'bx}};
94 10 rherveille
                #1;
95
                $display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)\n");
96
        end
97
 
98
////////////////////////////////////////////////////////////////////
99
//
100
// Wishbone write cycle
101
//
102
 
103
task wb_write;
104 19 rherveille
        input   delay;
105 10 rherveille
        integer delay;
106
 
107 50 rherveille
        input   [awidth -1:0]    a;
108
        input   [dwidth -1:0]    d;
109 10 rherveille
 
110
        begin
111
 
112 19 rherveille
                // wait initial delay
113 10 rherveille
                repeat(delay) @(posedge clk);
114 19 rherveille
 
115
                // assert wishbone signal
116 10 rherveille
                #1;
117
                adr  = a;
118
                dout = d;
119
                cyc  = 1'b1;
120
                stb  = 1'b1;
121
                we   = 1'b1;
122 19 rherveille
                sel  = {dwidth/8{1'b1}};
123
                @(posedge clk);
124 10 rherveille
 
125 19 rherveille
                // wait for acknowledge from slave
126 50 rherveille
                while(~ack)     @(posedge clk);
127 19 rherveille
 
128
                // negate wishbone signals
129 10 rherveille
                #1;
130
                cyc  = 1'b0;
131
                stb  = 1'bx;
132 19 rherveille
                adr  = {awidth{1'bx}};
133
                dout = {dwidth{1'bx}};
134 10 rherveille
                we   = 1'hx;
135 19 rherveille
                sel  = {dwidth/8{1'bx}};
136 10 rherveille
 
137
        end
138
endtask
139
 
140
////////////////////////////////////////////////////////////////////
141
//
142
// Wishbone read cycle
143
//
144
 
145
task wb_read;
146 19 rherveille
        input   delay;
147 10 rherveille
        integer delay;
148
 
149 50 rherveille
        input    [awidth -1:0]   a;
150
        output  [dwidth -1:0]    d;
151 10 rherveille
 
152
        begin
153
 
154 19 rherveille
                // wait initial delay
155 10 rherveille
                repeat(delay) @(posedge clk);
156 19 rherveille
 
157
                // assert wishbone signals
158 10 rherveille
                #1;
159
                adr  = a;
160 19 rherveille
                dout = {dwidth{1'bx}};
161 10 rherveille
                cyc  = 1'b1;
162
                stb  = 1'b1;
163
                we   = 1'b0;
164 19 rherveille
                sel  = {dwidth/8{1'b1}};
165
                @(posedge clk);
166 10 rherveille
 
167 19 rherveille
                // wait for acknowledge from slave
168 50 rherveille
                while(~ack)     @(posedge clk);
169 19 rherveille
 
170
                // negate wishbone signals
171 10 rherveille
                #1;
172
                cyc  = 1'b0;
173
                stb  = 1'bx;
174 19 rherveille
                adr  = {awidth{1'bx}};
175
                dout = {dwidth{1'bx}};
176 10 rherveille
                we   = 1'hx;
177 19 rherveille
                sel  = {dwidth/8{1'bx}};
178 10 rherveille
                d    = din;
179
 
180
        end
181
endtask
182
 
183 19 rherveille
////////////////////////////////////////////////////////////////////
184
//
185
// Wishbone compare cycle (read data from location and compare with expected data)
186
//
187
 
188
task wb_cmp;
189
        input   delay;
190
        integer delay;
191
 
192 50 rherveille
        input [awidth -1:0]      a;
193
        input   [dwidth -1:0]    d_exp;
194 19 rherveille
 
195
        begin
196 50 rherveille
                wb_read (delay, a, q);
197 19 rherveille
 
198 50 rherveille
                if (d_exp !== q)
199
                        $display("Data compare error. Received %h, expected %h at time %t", q, d_exp, $time);
200 19 rherveille
        end
201
endtask
202
 
203 10 rherveille
endmodule
204 19 rherveille
 
205
 

powered by: WebSVN 2.1.0

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