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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [wishbone/] [ip/] [wb_model/] [rtl/] [verilog/] [top.8bit.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_8bit
47
 
48
#( parameter dwidth = 8,
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
 
60
  input  wire [dwidth   -1:0] din,
61
  input  wire                 ack,
62
  input  wire                 err,
63
  input  wire                 rty
64
);
65
 
66
 
67
 
68
task automatic next;
69
  input [31:0] num;
70
  repeat (num)       @ (posedge clk);
71
endtask
72
 
73
 
74
 
75
 
76
 
77
 
78
 
79
  // Internal signals
80
 
81
 
82
  reg    [dwidth   -1:0] q;
83
 
84
always@(posedge clk)
85
  if(reset)
86
    begin
87
      adr  <= {awidth{1'b0}};
88
      dout <= {dwidth{1'b0}};
89
      cyc  <= 1'b0;
90
      stb  <= 1'b0;
91
      we   <= 1'h0;
92
    end
93
 
94
  // Wishbone write cycle
95
  task wb_write;
96
    input [awidth -1:0] a;
97
    input [dwidth -1:0] d;
98
 
99
    begin
100
 
101
      $display("%t %m cycle %h %h",$realtime,a,d );
102
 
103
      // assert wishbone signal
104
      adr  <= a;
105
      dout <= d;
106
      cyc  <= 1'b1;
107
      stb  <= 1'b1;
108
      we   <= 1'b1;
109
      next(1);
110
 
111
      // wait for acknowledge from slave
112
      while(~ack) next(1);
113
 
114
      // negate wishbone signals
115
      cyc  <= 1'b0;
116
      stb  <= 1'b0;
117
      adr  <= {awidth{1'b0}};
118
      dout <= {dwidth{1'b0}};
119
      we   <= 1'h0;
120
    end
121
  endtask
122
 
123
  // Wishbone read cycle
124
  task wb_read;
125
    input   [awidth -1:0]  a;
126
    output  [dwidth -1:0]  d;
127
 
128
    begin
129
 
130
 
131
      // assert wishbone signals
132
      adr  <= a;
133
      dout <= {dwidth{1'b0}};
134
      cyc  <= 1'b1;
135
      stb  <= 1'b1;
136
      we   <= 1'b0;
137
      next(1);
138
 
139
      // wait for acknowledge from slave
140
      while(~ack) next(1);
141
 
142
      $display("%t %m  cycle %h %h",$realtime,a,din );
143
 
144
      // negate wishbone signals
145
      cyc  <= 1'b0;
146
      stb  <= 1'b0;
147
      adr  <= {awidth{1'b0}};
148
      dout <= {dwidth{1'b0}};
149
      we   <= 1'h0;
150
      d    <= din;
151
 
152
 
153
 
154
    end
155
  endtask
156
 
157
  // Wishbone compare cycle (read data from location and compare with expected data)
158
  task wb_cmp;
159
    input  [awidth-1:0] a;
160
    input  [dwidth-1:0] d_exp;
161
 
162
     begin
163
      // assert wishbone signals
164
       adr  <= a;
165
      dout <= {dwidth{1'b0}};
166
      cyc  <= 1'b1;
167
      stb  <= 1'b1;
168
      we   <= 1'b0;
169
      next(1);
170
 
171
      // wait for acknowledge from slave
172
      while(~ack) next(1);
173
 
174
      $display("%t %m   check %h %h %h",$realtime,a,din,d_exp );
175
      if (!(d_exp === din))  cg.fail(" Data compare error");
176
      // negate wishbone signals
177
      cyc  <= 1'b0;
178
      stb  <= 1'b0;
179
      adr  <= {awidth{1'b0}};
180
      dout <= {dwidth{1'b0}};
181
      we   <= 1'h0;
182
   end
183
  endtask
184
 
185
endmodule
186
 

powered by: WebSVN 2.1.0

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