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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [wishbone/] [ip/] [model/] [rtl/] [verilog/] [sim/] [model_master.v] - 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                                             ////
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
module model_master
45
#( parameter dwidth = 32,
46
   parameter awidth = 32
47
 )(
48
  input wire                  clk,
49
  input wire                  reset,
50
  output reg [awidth   -1:0]  adr,
51
  output reg [dwidth   -1:0]  dout,
52
  output reg                  cyc,
53
  output reg                  stb,
54
  output reg                  we,
55
  output reg [dwidth/8 -1:0]  sel,
56
  input  wire [dwidth   -1:0] din,
57
  input  wire                 ack,
58
  input  wire                 err,
59
  input  wire                 rty
60
);
61
task automatic next;
62
  input [31:0] num;
63
  repeat (num)       @ (posedge clk);
64
endtask
65
  // Internal signals
66
  reg    [dwidth   -1:0] q;
67
always@(posedge clk)
68
  if(reset)
69
    begin
70
      adr  <= {awidth{1'b0}};
71
      dout <= {dwidth{1'b0}};
72
      cyc  <= 1'b0;
73
      stb  <= 1'b0;
74
      we   <= 1'h0;
75
      sel  <= {dwidth/8{1'b0}};
76
    end
77
  // Wishbone write cycle
78
  task wb_write;
79
    input [awidth -1:0] a;
80
    input [(dwidth/8) -1:0] s;
81
    input [dwidth -1:0] d;
82
    begin
83
      $display("%t %m cycle %h %h",$realtime,a,d );
84
      // assert wishbone signal
85
      adr  <= a;
86
      dout <= d;
87
      cyc  <= 1'b1;
88
      stb  <= 1'b1;
89
      we   <= 1'b1;
90
      sel  <= s;
91
      next(1);
92
      // wait for acknowledge from slave
93
      while(~ack) next(1);
94
      // negate wishbone signals
95
      cyc  <= 1'b0;
96
      stb  <= 1'b0;
97
      adr  <= {awidth{1'b0}};
98
      dout <= {dwidth{1'b0}};
99
      we   <= 1'h0;
100
      sel  <= {dwidth/8{1'b0}};
101
    end
102
  endtask
103
  // Wishbone read cycle
104
  task wb_read;
105
    input   [awidth -1:0]  a;
106
    output  [dwidth -1:0]  d;
107
    begin
108
      // assert wishbone signals
109
      adr  <= a;
110
      dout <= {dwidth{1'b0}};
111
      cyc  <= 1'b1;
112
      stb  <= 1'b1;
113
      we   <= 1'b0;
114
      sel  <= {dwidth/8{1'b1}};
115
      next(1);
116
      // wait for acknowledge from slave
117
      while(~ack) next(1);
118
      $display("%t %m  cycle %h %h",$realtime,a,din );
119
      // negate wishbone signals
120
      cyc  <= 1'b0;
121
      stb  <= 1'b0;
122
      adr  <= {awidth{1'b0}};
123
      dout <= {dwidth{1'b0}};
124
      we   <= 1'h0;
125
      sel  <= {dwidth/8{1'b0}};
126
      d    <= din;
127
    end
128
  endtask
129
  // Wishbone compare cycle (read data from location and compare with expected data)
130
  task wb_cmp;
131
    input  [awidth-1:0] a;
132
    input [(dwidth/8) -1:0] s;
133
    input  [dwidth-1:0] d_exp;
134
     begin
135
      // assert wishbone signals
136
       adr  <= a;
137
      dout <= {dwidth{1'b0}};
138
      cyc  <= 1'b1;
139
      stb  <= 1'b1;
140
      we   <= 1'b0;
141
      sel  <= s;
142
      next(1);
143
      // wait for acknowledge from slave
144
      while(~ack) next(1);
145
      $display("%t %m   check %h %h %h",$realtime,a,din,d_exp );
146
      if (!(d_exp === din))  cg.fail(" Data compare error");
147
      // negate wishbone signals
148
      cyc  <= 1'b0;
149
      stb  <= 1'b0;
150
      adr  <= {awidth{1'b0}};
151
      dout <= {dwidth{1'b0}};
152
      we   <= 1'h0;
153
      sel  <= {dwidth/8{1'b0}};
154
   end
155
  endtask
156
endmodule

powered by: WebSVN 2.1.0

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