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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [ExternalMemory/] [ExternalMemoryTestbench.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
/*
2
Copyright (c) 2008 MIT
3
 
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
11
conditions:
12
 
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
 
25
Author: Kermin Fleming
26
*/
27
 
28
import ExternalMemory::*;
29
import Memocode08Types::*;
30
import Types::*;
31
import Interfaces::*;
32
import Parameters::*;
33
import DebugFlags::*;
34
import PLBMasterWires::*;
35
import LFSR::*;
36
import FIFOF::*;
37
import FIFO::*;
38
import GetPut::*;
39
import PLBMasterDummy::*;
40
 
41
typedef enum {
42
  Initialize,
43
  Request,
44
  Transmit
45
} TesterState deriving(Bits,Eq);
46
 
47
 
48
 
49
 
50
module mkExternalMemoryTestbench (Empty);
51
 
52
 Reg#(Bit#(TLog#(TDiv#(TMul#(BlockSize,WordWidth),RecordWidth)))) plbMasterCount <- mkReg(0);
53
 FIFO#(PLBMasterCommand)              plbMasterCommand <- mkFIFO();
54
 FIFO#(Record)                        plbWordInput <- mkFIFO();
55
 FIFO#(Record)                        plbWordOutput <- mkFIFO();
56
 
57
 
58
 
59
 PLBMaster plbmaster;
60
 plbmaster = interface PLBMaster;
61
  interface Put wordInput;
62
    method Action put(Record wordInput) if(plbMasterCommand.first matches tagged StorePage .addr);
63
      if(zeroExtend(addr) != wordInput)
64
        begin
65
          $display("Store Value %h != %h", addr, wordInput);
66
          $finish;
67
        end
68
      plbMasterCount <= plbMasterCount + 1;
69
      if(plbMasterCount + 1 == 0)
70
        begin
71
          plbMasterCommand.deq;
72
        end
73
    endmethod
74
  endinterface
75
 
76
  interface Get wordOutput;
77
    method ActionValue#(Record) get() if(plbMasterCommand.first matches tagged LoadPage .addr);
78
      $display("PLBMaster Output");
79
      plbMasterCount <= plbMasterCount + 1;
80
      if(plbMasterCount + 1 == 0)
81
        begin
82
          $display("plbMaster load command dequed!");
83
          plbMasterCommand.deq;
84
        end
85
      return zeroExtend(addr);
86
    endmethod
87
  endinterface
88
 
89
  interface Put plbMasterCommandInput;
90
    method Action put(PLBMasterCommand command);
91
      $display("PLB Master got a command: %s", command matches tagged LoadPage .addr?"Load":"Store");
92
      plbMasterCommand.enq(command);
93
    endmethod
94
  endinterface
95
 
96
  interface plbMasterWires = ?;
97
 endinterface;
98
 
99
   ExternalMemory extMem <- mkExternalMemory(plbmaster);
100
 
101
 
102
  rule haltAll;
103
   Bit#(64) timeCount <- $time;
104
   if(timeCount > 1000000100)
105
     begin
106
       $display("PASSED");
107
       $finish;
108
     end
109
  endrule
110
 
111
 for(Integer i = 0; i < valueof(ReadPortNum); i = i + 1)
112
   begin
113
     LFSR#(Bit#(16)) lfsr <- mkLFSR_16;
114
     Reg#(TesterState) state <- mkReg(Initialize);
115
     Reg#(Bit#(32)) counter <- mkReg(0);
116
     FIFOF#(Bit#(16)) expectedVals <- mkFIFOF;
117
     Reg#(Bit#(TLog#(RecordsPerBlock))) transmitCount <- mkReg(0);
118
 
119
     rule countUp;
120
       counter <= counter + 1;
121
     endrule
122
 
123
     rule init(state == Initialize);
124
       state <= Request;
125
       lfsr.seed(fromInteger(i+1));
126
     endrule
127
 
128
     rule sendRequest((state == Request) && (counter % fromInteger(32*(i+1)) == 0));
129
       Bit#(64) timeCount <- $time;
130
       if(timeCount < 1000000000)
131
         begin
132
           extMem.read[i].readReq(zeroExtend(lfsr.value));
133
           lfsr.next();
134
           expectedVals.enq(lfsr.value);
135
         end
136
     endrule
137
 
138
     rule transmit;
139
       transmitCount <= transmitCount + 1;
140
       if(transmitCount + 1 == 0)
141
         begin
142
           expectedVals.deq;
143
         end
144
       Record valueTransmitted <- extMem.read[i].read;
145
       if(valueTransmitted != zeroExtend(expectedVals.first))
146
         begin
147
          $display("Load Value Reader[%d] %h != %h",  i, expectedVals.first, valueTransmitted);
148
          $finish;
149
         end
150
     endrule
151
 
152
     rule haltCheck (expectedVals.notEmpty);
153
       Bit#(64) timeCount <- $time;
154
       if(timeCount > 11000000000)
155
         begin
156
           $display("Writer[%d] stalled out", i);
157
            $finish;
158
         end
159
     endrule
160
 
161
   end
162
 
163
 
164
 for(Integer i = 0; i < valueof(WritePortNum); i = i + 1)
165
   begin
166
     LFSR#(Bit#(16)) lfsr <- mkLFSR_16;
167
     Reg#(TesterState) state <- mkReg(Initialize);
168
     Reg#(Bit#(32)) counter <- mkReg(0);
169
     FIFOF#(Bit#(16)) expectedVals <- mkFIFOF;
170
     Reg#(Bit#(TLog#(RecordsPerBlock))) transmitCount <- mkReg(0);
171
 
172
     rule countUp;
173
       counter <= counter + 1;
174
     endrule
175
 
176
     rule init(state == Initialize);
177
       state <= Request;
178
       lfsr.seed(fromInteger(i+1+valueof(ReadPortNum)));
179
     endrule
180
 
181
     rule sendRequest((state == Request) && (counter % fromInteger(32*(i+3)) == 0));
182
       Bit#(64) timeCount <- $time;
183
       if(timeCount < 1000000000)
184
         begin
185
           extMem.write[i].writeReq(zeroExtend(lfsr.value));
186
           lfsr.next();
187
           expectedVals.enq(lfsr.value);
188
         end
189
     endrule
190
 
191
     rule transmit;
192
       transmitCount <= transmitCount + 1;
193
       if(transmitCount + 1 == 0)
194
         begin
195
           expectedVals.deq;
196
         end
197
       extMem.write[i].write(zeroExtend(expectedVals.first));
198
     endrule
199
 
200
     rule haltCheck (expectedVals.notEmpty);
201
       Bit#(64) timeCount <- $time;
202
       if(timeCount > 11000000000)
203
         begin
204
           $display("Writer[%d] stalled out", i);
205
            $finish;
206
         end
207
     endrule
208
 
209
   end
210
 
211
endmodule

powered by: WebSVN 2.1.0

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