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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [ExternalMemory/] [ExternalMemoryTester.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 Vector::*;
40
 
41
import BRAMInitiatorWires::*;
42
import PLBMaster::*;
43
import BRAMFeeder::*;
44
 
45
 
46
 
47
 
48
typedef enum {
49
  Initialize,
50
  Request,
51
  Transmit
52
} TesterState deriving(Bits,Eq);
53
 
54
interface ExternalMemoryTester;
55
  interface PLBMasterWires                  plbMasterWires;
56
  interface BRAMInitiatorWires#(Bit#(14))   bramInitiatorWires;
57
endinterface
58
 
59
 
60
 
61
module mkExternalMemoryTester (ExternalMemoryTester);
62
 
63
 
64
  Feeder feeder <- mkBRAMFeeder();
65
  PLBMaster     plbmaster <- mkPLBMaster;
66
  ExternalMemory extMem <- mkExternalMemory(plbmaster);
67
 
68
  Vector#(ReadPortNum,FIFO#(Bit#(16))) readTargets <- replicateM(mkFIFO);
69
 
70
  Reg#(Bit#(28)) busCounter <-mkReg(0); // Need to lay off the bus for a bit
71
  Reg#(Bool) error <- mkReg(False);
72
 
73
  rule countUp;
74
    busCounter <= busCounter + 1;
75
  endrule
76
 
77
  rule sendBackResp (busCounter == 0);
78
   if(error)
79
     begin
80
       feeder.ppcMessageInput.put(1);
81
     end
82
   error <= False;
83
  endrule
84
 
85
  for(Integer i = 0; i < valueof(ReadPortNum); i = i + 1)
86
   begin
87
     Reg#(TesterState) state <- mkReg(Initialize);
88
     FIFOF#(Bit#(16)) expectedVals <- mkFIFOF;
89
     Reg#(Bit#(TLog#(RecordsPerBlock))) transmitCount <- mkReg(0);
90
 
91
 
92
     rule init(state == Initialize);
93
       state <= Request;
94
     endrule
95
 
96
     rule sendRequest;
97
       extMem.read[i].readReq(zeroExtend(readTargets[i].first) << 4);
98
       readTargets[i].deq();
99
       expectedVals.enq(readTargets[i].first);
100
     endrule
101
 
102
     rule transmit;
103
       transmitCount <= transmitCount + 1;
104
       if(transmitCount + 1 == 0)
105
         begin
106
           expectedVals.deq;
107
         end
108
       Record valueTransmitted <- extMem.read[i].read;
109
       if(valueTransmitted != zeroExtend(expectedVals.first))
110
         begin
111
           error <= True;
112
         end
113
     endrule
114
 
115
   end
116
 
117
 
118
 for(Integer i = 0; i < valueof(WritePortNum); i = i + 1)
119
   begin
120
     LFSR#(Bit#(16)) lfsr <- mkLFSR_16;
121
     Reg#(TesterState) state <- mkReg(Initialize);
122
     FIFOF#(Bit#(16)) expectedVals <- mkFIFOF;
123
     Reg#(Bit#(TLog#(RecordsPerBlock))) transmitCount <- mkReg(0);
124
 
125
 
126
     rule init(state == Initialize);
127
       state <= Request;
128
       lfsr.seed(fromInteger(i+1+valueof(ReadPortNum)));
129
     endrule
130
 
131
     rule sendRequest (busCounter[27:25] == 0);
132
           extMem.write[i].writeReq(zeroExtend(lfsr.value)<<4); // Shift over for 16 byte alignment
133
           lfsr.next();
134
           expectedVals.enq(lfsr.value);
135
     endrule
136
 
137
     rule transmit;
138
       transmitCount <= transmitCount + 1;
139
       if(transmitCount + 1 == 0)
140
         begin
141
           expectedVals.deq;
142
           readTargets[i].enq(expectedVals.first);
143
         end
144
       extMem.write[i].write(zeroExtend(expectedVals.first));
145
     endrule
146
 
147
 
148
 
149
   end
150
 
151
 
152
  interface plbMasterWires = plbmaster.plbMasterWires;
153
  interface bramInitiatorWires = feeder.bramInitiatorWires;
154
 
155
 
156
endmodule

powered by: WebSVN 2.1.0

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