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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [wishbone/] [ip/] [wb_model/] [rtl/] [verilog/] [top.sim] - Blame information for rev 131

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 jt_eaton
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  wb_master_model.v                                           ////
4
////                                                              ////
5
////  This file is part of the SPI IP core project                ////
6
////  http://www.opencores.org/projects/spi/                      ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Simon Srot (simons@opencores.org)                     ////
10
////                                                              ////
11
////  Based on:                                                   ////
12
////      - i2c/bench/verilog/wb_master_model.v                   ////
13
////        Copyright (C) 2001 Richard Herveille                  ////
14
////                                                              ////
15
////  All additional information is avaliable in the Readme.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2002 Authors                                   ////
21
////                                                              ////
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. ////
26
////                                                              ////
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.                                               ////
32
////                                                              ////
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 ////
37
//// details.                                                     ////
38
////                                                              ////
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                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
 
45
 
46
module wb_master_model_def
47
 
48
#( parameter dwidth = 32,
49
   parameter awidth = 32
50
 )(
51
  input wire                  clk,
52
  input wire                  reset,
53
 
54
  output reg [awidth   -1:0]  adr,
55
  output reg [dwidth   -1:0]  dout,
56
  output reg                  cyc,
57
  output reg                  stb,
58
  output reg                  we,
59
  output reg [dwidth/8 -1:0]  sel,
60
 
61
  input  wire [dwidth   -1:0] din,
62
  input  wire                 ack,
63
  input  wire                 err,
64
  input  wire                 rty
65
);
66
 
67
 
68
 
69
task automatic next;
70
  input [31:0] num;
71
  repeat (num)       @ (posedge clk);
72
endtask
73
 
74
 
75
 
76
 
77
 
78
 
79
 
80
  // Internal signals
81
 
82
 
83
  reg    [dwidth   -1:0] q;
84
 
85
always@(posedge clk)
86
  if(reset)
87
    begin
88
      adr  <= {awidth{1'b0}};
89
      dout <= {dwidth{1'b0}};
90
      cyc  <= 1'b0;
91
      stb  <= 1'b0;
92
      we   <= 1'h0;
93
      sel  <= {dwidth/8{1'b0}};
94
    end
95
 
96
  // Wishbone write cycle
97
  task wb_write;
98
    input [awidth -1:0] a;
99
    input [(dwidth/8) -1:0] s;
100
    input [dwidth -1:0] d;
101
 
102
    begin
103
 
104
      $display("%t %m cycle %h %h",$realtime,a,d );
105
 
106
      // assert wishbone signal
107
      adr  <= a;
108
      dout <= d;
109
      cyc  <= 1'b1;
110
      stb  <= 1'b1;
111
      we   <= 1'b1;
112
      sel  <= s;
113
      next(1);
114
 
115
      // wait for acknowledge from slave
116
      while(~ack) next(1);
117
 
118
      // negate wishbone signals
119
      cyc  <= 1'b0;
120
      stb  <= 1'b0;
121
      adr  <= {awidth{1'b0}};
122
      dout <= {dwidth{1'b0}};
123
      we   <= 1'h0;
124
      sel  <= {dwidth/8{1'b0}};
125
 
126
    end
127
  endtask
128
 
129
  // Wishbone read cycle
130
  task wb_read;
131
    input   [awidth -1:0]  a;
132
    output  [dwidth -1:0]  d;
133
 
134
    begin
135
 
136
 
137
      // assert wishbone signals
138
      adr  <= a;
139
      dout <= {dwidth{1'b0}};
140
      cyc  <= 1'b1;
141
      stb  <= 1'b1;
142
      we   <= 1'b0;
143
      sel  <= {dwidth/8{1'b1}};
144
      next(1);
145
 
146
      // wait for acknowledge from slave
147
      while(~ack) next(1);
148
 
149
      $display("%t %m  cycle %h %h",$realtime,a,din );
150
 
151
      // negate wishbone signals
152
      cyc  <= 1'b0;
153
      stb  <= 1'b0;
154
      adr  <= {awidth{1'b0}};
155
      dout <= {dwidth{1'b0}};
156
      we   <= 1'h0;
157
      sel  <= {dwidth/8{1'b0}};
158
      d    <= din;
159
 
160
 
161
 
162
    end
163
  endtask
164
 
165
  // Wishbone compare cycle (read data from location and compare with expected data)
166
  task wb_cmp;
167
    input  [awidth-1:0] a;
168
    input [(dwidth/8) -1:0] s;
169
    input  [dwidth-1:0] d_exp;
170
 
171
     begin
172
      // assert wishbone signals
173
       adr  <= a;
174
      dout <= {dwidth{1'b0}};
175
      cyc  <= 1'b1;
176
      stb  <= 1'b1;
177
      we   <= 1'b0;
178
      sel  <= s;
179
      next(1);
180
 
181
      // wait for acknowledge from slave
182
      while(~ack) next(1);
183
 
184
      $display("%t %m   check %h %h %h",$realtime,a,din,d_exp );
185
      if (!(d_exp === din))  cg.fail(" Data compare error");
186
      // negate wishbone signals
187
      cyc  <= 1'b0;
188
      stb  <= 1'b0;
189
      adr  <= {awidth{1'b0}};
190
      dout <= {dwidth{1'b0}};
191
      we   <= 1'h0;
192
      sel  <= {dwidth/8{1'b0}};
193
   end
194
  endtask
195
 
196
endmodule
197
 

powered by: WebSVN 2.1.0

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