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

Subversion Repositories xgate

[/] [xgate/] [trunk/] [bench/] [verilog/] [wb_master_model.v] - Blame information for rev 90

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

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

powered by: WebSVN 2.1.0

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