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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [PLBMaster/] [PLBMasterBackup.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
/*
2
Copyright (c) 2007 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 BRAM::*;
29
import BRAMInitiatorWires::*;
30
import GetPut::*;
31
import FIFO::*;
32
import FIFOF::*;
33
 
34
import Types::*;
35
import Interfaces::*;
36
import Parameters::*;
37
import DebugFlags::*;
38
 
39
import BRAMInitiator::*;
40
typedef 128 DataSize;
41
 
42
(* synthesize *)
43
module mkPLBMasterBackup( PLBMasterBackup );
44
   FIFO#(ComplexWord) wordOutfifo <- mkFIFO;
45
   FIFO#(ComplexWord) wordInfifo <- mkFIFO;
46
   FIFO#(PLBMasterCommand)  plbMasterCommandInfifo <- mkFIFO();
47
 
48
 
49
  let bufferSize = 129; // use extra space for a flag
50
  let minLoadPtrA = 0;
51
  let maxLoadPtrA = minLoadPtrA + bufferSize;
52
  let minLoadPtrB = maxLoadPtrA + bufferSize;
53
  let maxLoadPtrB = minLoadPtrB + bufferSize;
54
  let minStorePtrA = maxLoadPtrB + bufferSize;
55
  let maxStorePtrA = minStorePtrA + bufferSize;
56
  let minStorePtrB = maxStorePtrA + bufferSize;
57
  let maxStorePtrB = minStorePtrB + bufferSize;
58
 
59
  let ready = True;
60
 
61
  let debugF = debug(feederDebug);
62
 
63
  Reg#(Bit#(14))  readPtr <- mkReg(minLoadPtrA);
64
 
65
  Reg#(Bit#(14)) writePtr <- mkReg(minStorePtrA);
66
 
67
  Reg#(FeederState) state <- mkReg(FI_InStartCheckRead);
68
 
69
  Reg#(Bit#(32)) partialRead <- mkReg(0);
70
  Reg#(Bool)     doingLoad <- mkReg(False);
71
  Reg#(Bool)     doingStore <- mkReg(False);
72
  Reg#(Bool)     loadBufferA <- mkReg(True);
73
  Reg#(Bool)     storeBufferA <- mkReg(True);
74
  Reg#(Bit#(TLog#(DataSize))) count <- mkReg(0);
75
  Reg#(Bit#(TSub#(LogBlockElements,(TLog#(DataSize))))) rotations <- mkReg(0);
76
 
77
  BRAMInitiator#(Bit#(14)) bramInit <- mkBRAMInitiator;
78
  let bram = bramInit.bram;
79
 
80
  rule inWaitCommand(ready && state == FI_command);
81
      begin
82
      rotations <= 0;
83
      case (plbMasterCommandInfifo.first()) matches
84
        tagged RowSize .rs:
85
           begin
86
             plbMasterCommandInfifo.deq();
87
           end
88
        tagged LoadPage .ba:
89
           begin
90
             plbMasterCommandInfifo.deq();
91
             state <= FI_InStartCheckRead;
92
             readPtr <= 0;
93
             if(loadBufferA)
94
               begin
95
                 bram.read_req(minLoadPtrA);
96
               end
97
             else
98
               begin
99
                 bram.read_req(minLoadPtrB);
100
               end
101
           end
102
        tagged StorePage .ba:
103
           begin
104
             plbMasterCommandInfifo.deq();
105
             doingStore <= True;
106
             state <= FI_OutStartCheckWrite;
107
             writePtr <= 0;
108
             if(storeBufferA)
109
               begin
110
                 bram.read_req(minStorePtrA);
111
               end
112
             else
113
               begin
114
                 bram.read_req(minStorePtrB);
115
               end
116
           end
117
        default: $display("Illegal command for PLB Master");
118
      endcase
119
    end
120
  endrule
121
 
122
 
123
  rule inStartCheckRead(ready && state == FI_InStartCheckRead);
124
    debugF($display("BRAM: StartCheckRead"));
125
    let v <- bram.read_resp();
126
    if(v != 0)
127
      begin
128
        state <= FI_InStartRead;
129
        if(loadBufferA)
130
          begin
131
            readPtr <= 2;
132
            bram.read_req(minLoadPtrA + 1);
133
          end
134
        else
135
          begin
136
            readPtr <= 2;
137
            bram.read_req(minLoadPtrB + 1);
138
          end
139
      end
140
    else
141
      begin
142
        if(loadBufferA)
143
          begin
144
            bram.read_req(minLoadPtrA);
145
          end
146
        else
147
          begin
148
            bram.read_req(minLoadPtrB);
149
          end
150
      end
151
  endrule
152
 
153
  rule inStartRead(ready && state == FI_InStartRead);
154
 
155
    let v <- bram.read_resp();
156
    wordOutfifo.enq(unpack(v));
157
    readPtr <= readPtr + 1;
158
    count <= count + 1;
159
    if(count+1 ==  0)
160
      begin
161
        rotations <= rotations + 1;
162
        if(rotations + 1 == 0)
163
          begin
164
            state <= FI_command;
165
            loadBufferA <= True;
166
          end
167
        else
168
          begin
169
            loadBufferA <= !loadBufferA;
170
          end
171
 
172
        if(loadBufferA)
173
          begin
174
            bram.write(minLoadPtrA,0);
175
          end
176
        else
177
          begin
178
            bram.write(minLoadPtrB,0);
179
          end
180
      end
181
    else if(loadBufferA)
182
      begin
183
        bram.read_req(minLoadPtrA + readPtr);
184
      end
185
    else
186
      begin
187
        bram.read_req(minLoadPtrB + readPtr);
188
      end
189
 
190
    debugF($display("BRAM: StartRead %h", v));
191
 
192
  endrule
193
 
194
 
195
  rule inStartCheckWrite(ready && state == FI_OutStartCheckWrite);
196
    debugF($display("BRAM: StartCheckWrite"));
197
    let v <- bram.read_resp();
198
    if(v == 0)
199
      begin
200
        state <= FI_OutStartWrite;
201
        writePtr <= 1;
202
      end
203
    else
204
      begin
205
        if(storeBufferA)
206
          begin
207
            bram.read_req(minStorePtrA);
208
          end
209
        else
210
          begin
211
            bram.read_req(minStorePtrB);
212
          end
213
      end
214
  endrule
215
 
216
  rule inStartWrite(ready && state == FI_OutStartWrite);
217
    debugF($display("BRAM: StartWrite"));
218
     $display("BRAM: write [%d] = %h",writePtr+1, wordInfifo.first);
219
    writePtr <= writePtr + 1;
220
    count <= count + 1;
221
    if(count+1 ==  0)
222
      begin
223
        rotations <= rotations + 1;
224
        if(rotations + 1 == 0)
225
          begin
226
            state <= FI_OutStartPush;
227
          end
228
        else
229
          begin
230
            storeBufferA <= !storeBufferA;
231
          end
232
      if(storeBufferA)
233
        begin
234
          bram.write(writePtr+minStorePtrA, truncate(pack(wordInfifo.first())));
235
        end
236
      else
237
        begin
238
          bram.write(writePtr+minStorePtrB, truncate(pack(wordInfifo.first())));
239
        end
240
      wordInfifo.deq();
241
    end
242
  endrule
243
 
244
  rule inStartPush(ready && state == FI_OutStartPush);
245
    storeBufferA <= True;
246
    if(storeBufferA)
247
      begin
248
        bram.write(minStorePtrA, ~0);
249
      end
250
    else
251
      begin
252
        bram.write(minStorePtrB, ~0);
253
      end
254
    state <= FI_command;
255
  endrule
256
 
257
  interface Put wordInput = interface Put;
258
    method Action put(x);
259
      wordInfifo.enq(x);
260
      //$display("PLB: got val %h", x);
261
    endmethod
262
  endinterface;
263
 
264
  interface Get wordOutput = interface Get;
265
        method get();
266
          actionvalue
267
            //$display("PLB: sending val %h", wordOutfifo.first());
268
            wordOutfifo.deq();
269
            return wordOutfifo.first();
270
          endactionvalue
271
        endmethod
272
      endinterface;
273
  interface Put plbMasterCommandInput = fifoToPut(plbMasterCommandInfifo);
274
 
275
  interface plbBRAMWires = bramInit.bramInitiatorWires;
276
 
277
endmodule
278
 

powered by: WebSVN 2.1.0

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