OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpWishbone/] [unitWishboneBFM/] [src/] [WishboneBFM.sv] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 164 rkastl
// SDHC-SC-Core
2
// Secure Digital High Capacity Self Configuring Core
3
//
4 170 rkastl
// (C) Copyright 2010, Rainer Kastl
5
// All rights reserved.
6 164 rkastl
//
7 170 rkastl
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are met:
9
//     * Redistributions of source code must retain the above copyright
10
//       notice, this list of conditions and the following disclaimer.
11
//     * Redistributions in binary form must reproduce the above copyright
12
//       notice, this list of conditions and the following disclaimer in the
13
//       documentation and/or other materials provided with the distribution.
14
//     * Neither the name of the  nor the
15
//       names of its contributors may be used to endorse or promote products
16
//       derived from this software without specific prior written permission.
17 164 rkastl
//
18 170 rkastl
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  "AS IS" AND
19
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
// DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY
22
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 164 rkastl
//
29
// File        : WishboneBFM.sv
30
// Owner       : Rainer Kastl
31
// Description : Wishbone BFM
32
// Links       : Wishbone Spec B.3
33
//
34 120 rkastl
 
35 135 rkastl
`ifndef WISHBONE
36
`define WISHBONE
37
 
38 153 rkastl
`include "IWishboneBus.sv";
39
`include "WbTransaction.sv";
40 157 rkastl
`include "Logger.sv";
41 135 rkastl
 
42 151 rkastl
class WbBFM;
43 120 rkastl
 
44 153 rkastl
        virtual IWishboneBus.Master Bus;
45
        WbTransMb TransInMb;
46
        WbTransMb TransOutMb;
47 157 rkastl
        int StopAfter = -1;
48
        Logger Log = new();
49 120 rkastl
 
50 153 rkastl
        function new(virtual IWishboneBus.Master Bus);
51 120 rkastl
                this.Bus = Bus;
52
        endfunction
53
 
54 157 rkastl
        task start();
55
                fork
56
                        this.run();
57
                join_none;
58
        endtask
59 153 rkastl
 
60 157 rkastl
        task run();
61
                Idle();
62
 
63
                while (StopAfter != 0) begin
64
                        WbTransaction transaction;
65
 
66
                        TransInMb.get(transaction);
67
 
68
                        case (transaction.Type)
69
                        WbTransaction::Classic: begin
70
                                case (transaction.Kind)
71
                                WbTransaction::Read: begin
72
                                        Read(transaction.Addr, transaction.Data);
73
                                end
74
                                WbTransaction::Write: begin
75
                                        Write(transaction.Addr, transaction.Data);
76
                                end
77
                                endcase
78
                        end
79
 
80
                        default: begin
81
                                string msg;
82
                                $swrite(msg, "Transaction.Type %s not handled.", transaction.Type.name());
83
                                Log.error(msg);
84
                        end
85
                        endcase
86 158 rkastl
 
87
                        TransOutMb.put(transaction);
88 157 rkastl
                        if (StopAfter > 0) StopAfter--;
89
                end
90
        endtask
91
 
92 120 rkastl
        task Idle();
93
                @(posedge this.Bus.CLK_I)
94
                this.Bus.cbMaster.CYC_O  <= cNegated;
95
                this.Bus.cbMaster.ADR_O  <= '{default: cDontCare};
96
                this.Bus.cbMaster.DAT_O  <= '{default: cDontCare};
97
                this.Bus.cbMaster.SEL_O  <= '{default: cDontCare};
98
                this.Bus.cbMaster.STB_O  <= cNegated;
99
                this.Bus.cbMaster.TGA_O  <= '{default: cDontCare};
100
                this.Bus.cbMaster.TGC_O  <= '{default: cDontCare};
101
                this.Bus.cbMaster.TGD_O  <= cDontCare;
102
                this.Bus.cbMaster.WE_O   <= cDontCare;
103
                this.Bus.cbMaster.LOCK_O <= cNegated;
104
                this.Bus.cbMaster.CTI_O  <= '{default: cDontCare};
105 157 rkastl
                Log.note("WbBus idle");
106 120 rkastl
        endtask;
107
 
108
        function void checkResponse();
109
 
110
                // Analyse slave response
111
                if (this.Bus.cbMaster.ERR_I == cAsserted) begin
112 157 rkastl
                        Log.error("MasterWrite: ERR_I asserted; Slave encountered an error.");
113 120 rkastl
                end
114
                if (this.Bus.cbMaster.RTY_I == cAsserted) begin
115 157 rkastl
                        Log.note("MasterWrite: RTY_I asserted; Retry requested.");
116 120 rkastl
                end
117
 
118
        endfunction;
119
 
120
        task Read(logic [`cWishboneWidth-1 : 0] Address,
121 157 rkastl
                           ref bit [`cWishboneWidth-1 : 0] Data,
122 120 rkastl
                           input logic [`cWishboneWidth-1 : 0] TGA = '{default: cDontCare},
123
                           input logic [`cWishboneWidth-1 : 0] BankSelect = '{default: 1});
124
 
125
                @(posedge this.Bus.CLK_I);
126
                this.Bus.cbMaster.ADR_O <= Address;
127
                this.Bus.cbMaster.TGA_O <= TGA;
128
                this.Bus.cbMaster.WE_O <= cNegated;
129
                this.Bus.cbMaster.SEL_O <= BankSelect;
130
                this.Bus.cbMaster.CYC_O <= cAsserted;
131
                this.Bus.cbMaster.TGC_O <= cAsserted;
132
                this.Bus.cbMaster.STB_O <= cAsserted;
133
                this.Bus.cbMaster.CTI_O <= ClassicCycle;
134
 
135
                //$display("%t : MasterRead: Waiting for slave resonse", $time);
136
                // Wait until slave responds
137
                wait ((this.Bus.cbMaster.ACK_I == cAsserted)
138
                ||  (this.Bus.cbMaster.ERR_I == cAsserted)
139
                ||  (this.Bus.cbMaster.RTY_I == cAsserted));
140
 
141
                checkResponse();
142
 
143
                Data = this.Bus.cbMaster.DAT_I; // latch it before the CLOCK???
144 158 rkastl
 
145 120 rkastl
                this.Bus.cbMaster.STB_O <= cNegated;
146
                this.Bus.cbMaster.CYC_O <= cNegated;
147
                @(posedge this.Bus.CLK_I);
148
 
149
        endtask;
150
 
151
        task BlockRead(logic [`cWishboneWidth-1 : 0] Address,
152
                                        ref logic [`cWishboneWidth-1 : 0] Data[],
153
                                        input logic [`cWishboneWidth-1 : 0] TGA = '{default: cDontCare},
154
                                        input logic [`cWishboneWidth-1 : 0] BankSelect = '{default: 1});
155
 
156
                foreach(Data[i]) begin
157
                        this.Bus.cbMaster.WE_O <= cNegated;
158
                        this.Bus.cbMaster.CYC_O <= cAsserted;
159
                        this.Bus.cbMaster.TGC_O <= cAsserted;
160
                        this.Bus.cbMaster.STB_O <= cAsserted;
161
                        this.Bus.cbMaster.LOCK_O <= cAsserted;
162
                        this.Bus.cbMaster.ADR_O <= Address+i;
163
                        this.Bus.cbMaster.TGA_O <= TGA;
164
                        this.Bus.cbMaster.SEL_O <= BankSelect;
165
                        this.Bus.cbMaster.CTI_O <= ClassicCycle;
166
                        @(posedge this.Bus.CLK_I);
167
 
168
                        //$display("%t : MasterRead: Waiting for slave response.", $time);
169
                        // Wait until slave responds
170
                        wait ((this.Bus.cbMaster.ACK_I == cAsserted)
171
                        ||  (this.Bus.cbMaster.ERR_I == cAsserted)
172
                        ||  (this.Bus.cbMaster.RTY_I == cAsserted));
173
 
174
                        checkResponse();
175
                        Data[i] = this.Bus.cbMaster.DAT_I;
176
                        //$display("%t : Reading %h", $time, Data[i]);
177
                end
178
 
179
                this.Bus.cbMaster.STB_O <= cNegated;
180
                this.Bus.cbMaster.CYC_O <= cNegated;
181
                this.Bus.cbMaster.LOCK_O <= cNegated;
182
                @(posedge this.Bus.CLK_I);
183
 
184
        endtask;
185
 
186
        task Write(logic [`cWishboneWidth-1 : 0] Address,
187
                   logic [`cWishboneWidth-1 : 0] Data,
188
                   logic [`cWishboneWidth-1 : 0] TGA = '{default: cDontCare},
189
                   logic [`cWishboneWidth-1 : 0] TGD = cDontCare,
190
                   logic [`cWishboneWidth-1 : 0] BankSelect = '{default: 1});
191
 
192
                @(posedge this.Bus.CLK_I)
193
                // CLOCK EDGE 0
194
                this.Bus.cbMaster.ADR_O <= Address;
195
                this.Bus.cbMaster.TGA_O <= TGA;
196
                this.Bus.cbMaster.DAT_O <= Data;
197
                this.Bus.cbMaster.TGD_O <= TGD;
198
                this.Bus.cbMaster.WE_O  <= cAsserted;
199
                this.Bus.cbMaster.SEL_O <= BankSelect;
200
                this.Bus.cbMaster.CYC_O <= cAsserted;
201
                this.Bus.cbMaster.TGC_O <= cAsserted; // Assert all?
202
                this.Bus.cbMaster.STB_O <= cAsserted;
203
                this.Bus.cbMaster.CTI_O <= ClassicCycle;
204
                //$display("%t : MasterWrite: Waiting for slave response.", $time);
205
                // Wait until slave responds
206
 
207
                wait ((this.Bus.cbMaster.ACK_I == cAsserted)
208
                        ||  (this.Bus.cbMaster.ERR_I == cAsserted)
209
                        ||  (this.Bus.cbMaster.RTY_I == cAsserted));
210
                checkResponse();
211
                this.Bus.cbMaster.STB_O <= cNegated;
212
                this.Bus.cbMaster.CYC_O <= cNegated;
213
 
214
                @(posedge this.Bus.CLK_I);
215
                // CLOCK EDGE 1
216
                //$display("%t : MasterWrite completed.", $time);
217
        endtask;
218
 
219
        task BlockWrite (logic [`cWishboneWidth-1 : 0] Address,
220
                         logic [`cWishboneWidth-1 : 0] Data [],
221
                         logic [`cWishboneWidth-1 : 0] TGA = '{default: cDontCare},
222
                         logic [`cWishboneWidth-1 : 0] TGD = cDontCare,
223
                         logic [`cWishboneWidth-1 : 0] BankSelect = '{default: 1}
224
        );
225
 
226
                foreach(Data[i]) begin
227
 
228
                        @(posedge this.Bus.CLK_I)
229
                        // CLOCK EDGE 0
230
                        this.Bus.cbMaster.ADR_O <= Address + i;
231
                        this.Bus.cbMaster.TGA_O <= TGA;
232
                        this.Bus.cbMaster.DAT_O <= Data[i];
233
                        this.Bus.cbMaster.TGD_O <= TGD;
234
                        this.Bus.cbMaster.WE_O  <= cAsserted;
235
                        this.Bus.cbMaster.SEL_O <= BankSelect;
236
                        this.Bus.cbMaster.CYC_O <= cAsserted;
237
                        this.Bus.cbMaster.TGC_O <= cAsserted; // Assert all?
238
                        this.Bus.cbMaster.STB_O <= cAsserted;
239
                        this.Bus.cbMaster.LOCK_O <= cAsserted;
240
                        this.Bus.cbMaster.CTI_O <= ClassicCycle;
241
 
242
                        // Wait until slave responds
243
                        wait ((this.Bus.cbMaster.ACK_I == cAsserted)
244
                        ||  (this.Bus.cbMaster.ERR_I == cAsserted)
245
                        ||  (this.Bus.cbMaster.RTY_I == cAsserted));
246
                        checkResponse();
247
                        //$display("%t : MasterBlockWrite phase %d completed.", $time, i);
248
                end
249
 
250
                this.Bus.cbMaster.STB_O <= cNegated;
251
                this.Bus.cbMaster.CYC_O <= cNegated;
252
                this.Bus.cbMaster.LOCK_O <= cNegated;
253
                @(posedge this.Bus.CLK_I);
254
                // CLOCK EDGE 1
255
                //$display("%t : MasterBlockWrite completed.", $time);
256
        endtask;
257
 
258
        task TestSingleOps (logic [`cWishboneWidth-1 : 0] Address,
259
                                           logic [`cWishboneWidth-1 : 0] Data);
260
 
261 157 rkastl
                bit [`cWishboneWidth-1 : 0] rd;
262 120 rkastl
 
263
                this.Write(Address, Data);
264
                this.Read(Address, rd);
265
 
266
                $display("%t : %h (read) == %h (written)", $time, rd, Data);
267
                assert (rd == Data);
268
        endtask;
269
 
270
        task TestBlockOps (logic [`cWishboneWidth-1 : 0] Address,
271
                                                logic [`cWishboneWidth-1 : 0] Data []);
272
 
273
                logic [`cWishboneWidth-1 : 0] blockData [];
274
 
275
                blockData = new [Data.size()];
276
 
277
                this.BlockWrite(Address, Data);
278
                this.BlockRead(Address, blockData);
279
 
280
                foreach(blockData[i]) begin
281
                        $display("%t : %h (read) == %h (written)", $time, blockData[i], Data[i]);
282
                        assert (Data[i] == blockData[i]);
283
                end
284
 
285
                blockData.delete();
286
 
287
        endtask;
288
 
289
endclass
290
 
291 135 rkastl
`endif
292
 

powered by: WebSVN 2.1.0

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