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

Subversion Repositories cop

[/] [cop/] [trunk/] [bench/] [verilog/] [wb_master_model.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 rehayes
///////////////////////////////////////////////////////////////////////
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
//
40
//  $Id: wb_master_model.v,v 1.4 2004/02/28 15:40:42 rherveille Exp $
41
//
42
//  $Date: 2004/02/28 15:40:42 $
43
//  $Revision: 1.4 $
44
//  $Author: rherveille $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//
50
`include "timescale.v"
51
 
52
module wb_master_model  #(parameter dwidth = 32,
53
                          parameter awidth = 32)
54
(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
55
 
56
 
57
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
 
66
////////////////////////////////////////////////////////////////////
67
//
68
// Local Wires
69
//
70
 
71
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
 
77
reg [dwidth   -1:0] q;
78
 
79
event test_command_start;
80
event test_command_mid;
81
event test_command_end;
82
 
83
////////////////////////////////////////////////////////////////////
84
//
85
// Memory Logic
86
//
87
 
88
initial
89
        begin
90
                //adr = 32'hxxxx_xxxx;
91
                //adr = 0;
92
                adr  = {awidth{1'bx}};
93
                dout = {dwidth{1'bx}};
94
                cyc  = 1'b0;
95
                stb  = 1'bx;
96
                we   = 1'hx;
97
                sel  = {dwidth/8{1'bx}};
98
                #1;
99
                $display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)");
100
        end
101
 
102
////////////////////////////////////////////////////////////////////
103
//
104
// Wishbone write cycle
105
//
106
 
107
task wb_write;
108
        input   delay;
109
        integer delay;
110
 
111
        input   [awidth -1:0]   a;
112
        input   [dwidth -1:0]   d;
113
 
114
        begin
115
                -> test_command_start;
116
                // wait initial delay
117
                repeat(delay) @(posedge clk);
118
 
119
                // assert wishbone signal
120
                #1;
121
                adr  = a;
122
                dout = d;
123
                cyc  = 1'b1;
124
                stb  = 1'b1;
125
                we   = 1'b1;
126
                sel  = {dwidth/8{1'b1}};
127
                @(posedge clk);
128
                -> test_command_mid;
129
 
130
                // wait for acknowledge from slave
131
                while(~ack)     @(posedge clk);
132
                -> test_command_mid;
133
 
134
                // negate wishbone signals
135
                #1;
136
                cyc  = 1'b0;
137
                stb  = 1'bx;
138
                adr  = {awidth{1'bx}};
139
                dout = {dwidth{1'bx}};
140
                we   = 1'hx;
141
                sel  = {dwidth/8{1'bx}};
142
                -> test_command_end;
143
 
144
        end
145
endtask
146
 
147
////////////////////////////////////////////////////////////////////
148
//
149
// Wishbone read cycle
150
//
151
 
152
task wb_read;
153
        input   delay;
154
        integer delay;
155
 
156
        input   [awidth -1:0]  a;
157
        output  [dwidth -1:0]  d;
158
 
159
        begin
160
 
161
                // wait initial delay
162
                repeat(delay) @(posedge clk);
163
 
164
                // assert wishbone signals
165
                #1;
166
                adr  = a;
167
                dout = {dwidth{1'bx}};
168
                cyc  = 1'b1;
169
                stb  = 1'b1;
170
                we   = 1'b0;
171
                sel  = {dwidth/8{1'b1}};
172
                @(posedge clk);
173
 
174
                // wait for acknowledge from slave
175
                while(~ack)     @(posedge clk);
176
 
177
                // negate wishbone signals
178
                d    = din; // Grab the data on the posedge of clock
179
                #1;         // Delay the clearing (hold time of the control signals
180
                cyc  = 1'b0;
181
                stb  = 1'bx;
182
                adr  = {awidth{1'bx}};
183
                dout = {dwidth{1'bx}};
184
                we   = 1'hx;
185
                sel  = {dwidth/8{1'bx}};
186
 
187
        end
188
endtask
189
 
190
////////////////////////////////////////////////////////////////////
191
//
192
// Wishbone compare cycle (read data from location and compare with expected data)
193
//
194
 
195
task wb_cmp;
196
        input   delay;
197
        integer delay;
198
 
199
        input [awidth -1:0]     a;
200
        input [dwidth -1:0]     d_exp;
201
 
202
        begin
203
                wb_read (delay, a, q);
204
 
205
                if (d_exp !== q)
206
                        $display("Data compare error at address %h. Received %h, expected %h at time %t", a, q, d_exp, $time);
207
        end
208
endtask
209
 
210
endmodule
211
 
212
 

powered by: WebSVN 2.1.0

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