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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [lib/] [bsv/] [BRAMFeeder/] [src/] [BRAMFeeder.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 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: Michael Pellauer, Nirav Dave
26
*/
27
 
28
import BRAM::*;
29
import BRAMInitiatorWires::*;
30
import GetPut::*;
31
import FIFO::*;
32
import FIFOF::*;
33
//import Types::*;
34
//import Interfaces::*;
35
import Debug::*;
36
 
37
import BRAMInitiator::*;
38
 
39
//A message to the PPC
40
typedef Bit#(32) PPCMessage;
41
 
42
 
43
typedef enum{
44
  FI_Initialize,
45
  FI_InIdle,
46
  FI_InStartCheckRead,
47
  FI_InStartRead,
48
  FI_InStartTake,
49
  FI_OutStartCheckWrite,
50
  FI_OutStartWrite,
51
  FI_OutStartPush,
52
  FI_CheckLoadStore,
53
  FI_Load,
54
  FI_LoadTake,
55
  FI_Store,
56
  FI_StorePush,
57
  FI_command
58
} FeederState deriving(Eq,Bits);
59
 
60
 
61
interface Feeder;
62
 
63
  interface Put#(PPCMessage) ppcMessageInput;
64
  interface Get#(PPCMessage) ppcMessageOutput;
65
  interface BRAMInitiatorWires#(Bit#(14))  bramInitiatorWires;
66
 
67
endinterface
68
 
69
Bool feederDebug = False;
70
 
71
(* synthesize *)
72
module mkBRAMFeeder(Feeder);
73
 
74
  // Data is held in 2 addr blocks. as
75
  // Addr n : 1---------22222  <- 1 valid bit (otherwise all zero)
76
  //                              2 top bits of payload
77
  //    n+1 : 333333333333333  <- 3 rest of payload
78
 
79
  //State
80
 
81
  BRAMInitiator#(Bit#(14)) bramInit <- mkBRAMInitiator;
82
  let bram = bramInit.bram;
83
 
84
  //BRAM#(Bit#(16), Bit#(32)) bram <- mkBRAM_Full();
85
 
86
  FIFOF#(PPCMessage)  ppcMesgQ <- mkFIFOF();
87
  FIFOF#(PPCMessage) ppcInstQ <- mkFIFOF();
88
 
89
  let minReadPtr  =   0;
90
  let maxReadPtr  =  31;
91
  let minWritePtr =  32;
92
  let maxWritePtr =  63;
93
 
94
  let ready = True;
95
 
96
  let debugF = debug(feederDebug);
97
 
98
  Reg#(Bit#(14))  readPtr <- mkReg(minReadPtr);
99
 
100
  Reg#(Bit#(14)) writePtr <- mkReg(minWritePtr);
101
 
102
  Reg#(FeederState) state <- mkReg(FI_InStartCheckRead);
103
 
104
  Reg#(Bit#(32)) partialRead <- mkReg(0);
105
 
106
  Reg#(Bit#(30)) heartbeat <- mkReg(0);
107
 
108
  //Every so often send a message to the PPC indicating we're still alive
109
 
110
  rule beat (True);
111
 
112
    let newheart = heartbeat + 1;
113
 
114
    heartbeat <= newheart;
115
 
116
    if (newheart == 0)
117
      ppcMesgQ.enq(0);
118
 
119
  endrule
120
 
121
  ///////////////////////////////////////////////////////////
122
  //Initialize
123
  ///////////////////////////////////////////////////////////
124
 
125
  //Reg#(Maybe#(Bit#(14))) initReg <- mkReg(Just(0));
126
 
127
  //Bool ready = !isJust(initReg);
128
 
129
  //rule initBRAM(initReg matches tagged Just .i);
130
  //  $display("Init");
131
  //  bram.write(i, 0);
132
  //  initReg <= (i == maxWritePtr) ? Nothing : Just (i + 1);
133
  //endrule
134
 
135
  ///////////////////////////////////////////////////////////
136
  // In goes to FPGA, Out goes back to PPC
137
  ///////////////////////////////////////////////////////////
138
 
139
  let state_tryread = (ppcInstQ.notFull ? FI_InStartCheckRead: FI_InIdle);
140
  let state_trywrite = (ppcMesgQ.notEmpty) ? FI_OutStartCheckWrite : FI_InIdle;
141
 
142
  rule inStartIdle(ready && state == FI_InIdle);
143
    if(state_tryread == FI_InIdle)
144
      begin
145
        state <= state_trywrite;
146
      end
147
    else
148
      begin
149
        state <= state_tryread;
150
      end
151
  endrule
152
 
153
 
154
  rule inStartCheckRead(ready && state == FI_InStartCheckRead);
155
    debugF($display("BRAM: StartCheckRead"));
156
    bram.read_req(readPtr);
157
    state <= FI_InStartRead;
158
  endrule
159
 
160
  rule inStartRead(ready && state == FI_InStartRead);
161
 
162
    let v <- bram.read_resp();
163
    Bool valid = (v[31] == 1);
164
    state <= (valid) ? FI_InStartTake : state_trywrite;
165
 
166
    debugF($display("BRAM: StartRead %h", v));
167
    if (valid)
168
      begin
169
        //$display("BRAM: read fstinst [%d] = %h",readPtr, v);
170
        partialRead <= v;
171
        bram.read_req(readPtr+1); //
172
      end
173
  endrule
174
 
175
  rule inStartTake(ready && state == FI_InStartTake);
176
    debugF($display("BRAM: StartTake"));
177
    let val <- bram.read_resp();
178
 
179
    Bit#(63) pack_i = truncate({partialRead,val});
180
 
181
    PPCMessage i = unpack(truncate(pack_i));//truncate({partialRead,val}));
182
 
183
    ppcInstQ.enq(i);
184
//    $display("BRAM: read sndinst [%d] = %h",readPtr+1, val);
185
//    $display("BRAM: got PPCMessage %h",pack_i);
186
//    $display("Getting Inst: %h %h => %h",partialRead, val, {partialRead,val});
187
    bram.write(readPtr, 0);
188
    readPtr <= (readPtr + 2 > maxReadPtr) ? minReadPtr : (readPtr + 2);
189
    state <= state_trywrite;
190
  endrule
191
 
192
  rule inStartCheckWrite(ready && state == FI_OutStartCheckWrite);
193
    debugF($display("BRAM: StartCheckWrite"));
194
    bram.read_req(writePtr);
195
    state <= FI_OutStartWrite;
196
  endrule
197
 
198
  rule inStartWrite(ready && state == FI_OutStartWrite);
199
    debugF($display("BRAM: StartWrite"));
200
    let v <- bram.read_resp();
201
    Bool valid = (v[31] == 0);
202
    state <= (valid) ? FI_OutStartPush : state_tryread;
203
    if (valid) begin
204
      $display("BRAM: write [%d] = %h",writePtr+1, ppcMesgQ.first);
205
      bram.write(writePtr+1, ppcMesgQ.first());
206
      ppcMesgQ.deq();
207
    end
208
  endrule
209
 
210
  rule inStartPush(ready && state == FI_OutStartPush);
211
    debugF($display("BRAM: StartPush"));
212
      $display("BRAM: write [%d] = %h",writePtr, 32'hFFFFFFFF);
213
    bram.write(writePtr, 32'hFFFFFFFF);//all 1s
214
    writePtr <= (writePtr + 2 > maxWritePtr) ? minWritePtr : (writePtr + 2);
215
    state <= state_tryread;
216
  endrule
217
 
218
  //Interface
219
 
220
  interface ppcMessageInput      = fifoToPut(fifofToFifo(ppcMesgQ));
221
  interface ppcMessageOutput = fifoToGet(fifofToFifo(ppcInstQ));
222
 
223
  interface bramInitiatorWires = bramInit.bramInitiatorWires;
224
 
225
endmodule
226
 

powered by: WebSVN 2.1.0

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