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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [Sort/] [SortTester.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 PLBMasterWires::*;
29
 
30
import BRAMInitiatorWires::*;
31
import PLBMaster::*;
32
import BRAMFeeder::*;
33
 
34
import Interfaces::*;
35
import Parameters::*;
36
import FIFO::*;
37
import FIFOF::*;
38
import BRAMFIFO::*;
39
import GetPut::*;
40
import Types::*;
41
import Memocode08Types::*;
42
import Sort::*;
43
import SortTree64::*;
44
import Vector::*;
45
 
46
interface SortTester;
47
  interface PLBMasterWires                  plbMasterWires;
48
  interface BRAMInitiatorWires#(Bit#(14))   bramInitiatorWires;
49
endinterface
50
 
51
typedef enum{
52
  Idle,
53
  Running,
54
  Inputing,
55
  Outputing
56
} TesterState deriving (Bits,Eq);
57
 
58
 
59
module mkSortTester (SortTester);
60
   Feeder            feeder       <- mkBRAMFeeder();
61
   PLBMaster         plbMaster    <- mkPLBMaster;
62
 
63
   Reg#(TesterState)      state        <- mkReg(Idle);
64
   Reg#(BlockAddr)        baseRegStore <- mkRegU();
65
   Reg#(Bit#(64))         timer        <- mkRegU();
66
   Reg#(Bit#(20))         resCount     <- mkRegU();
67
   Reg#(Bit#(20))         writeCount   <- mkRegU();
68
   Reg#(Bool)             eos          <- mkRegU();
69
   FIFO#(Bit#(20))        resQ         <- mkFIFO();
70
   FIFOF#(Maybe#(Record)) writeQ       <- mkSizedFIFOF(8);
71
   let                    sortTree     <- mkSortTree64();
72
   let                    tok_info      = sortTree.inStream.getTokInfo();
73
 
74
   rule grab_instruction(state == Idle);
75
      PPCMessage inst <- feeder.ppcMessageOutput.get;
76
      Bit#(5) size  = truncate(pack(inst));
77
      baseRegStore <= 0;
78
      timer        <= 0;
79
      resCount     <= (1<
80
      writeCount   <= 1<
81
      state        <= Running;
82
      eos          <= False;
83
   endrule
84
 
85
   rule read_reserve (state == Running &&
86
                      resCount > 0 &&
87
                      tok_info[resCount[5:0]] > 0);
88
      resQ.enq(resCount);
89
      resCount <= resCount - 1;
90
   endrule
91
 
92
   rule read_request (True);
93
      Bit#(20) val = resQ.first();
94
      Bit#(6)  idx = truncate(val);
95
      resQ.deq();
96
      sortTree.inStream.putDeqTok(idx,1);
97
      if (idx == 1)
98
         eos <= !eos;
99
 
100
      if (!eos) // enq data
101
         sortTree.inStream.putRecord(idx,tagged Valid zeroExtend({val[19:7],val[5:0]}));
102
      else // eos
103
         sortTree.inStream.putRecord(idx,tagged Invalid);
104
   endrule
105
 
106
   rule sync_out_stream (state == Running);
107
      Vector#(1,Bit#(5)) tok = replicate(zeroExtend(pack(writeQ.notFull())));
108
      sortTree.outStream.putTokInfo(tok);
109
   endrule
110
 
111
   rule drain_sorter_finish (True);
112
      match {.*,.data} = sortTree.outStream.getRecord();
113
      writeQ.enq(data);
114
   endrule
115
 
116
   rule write_to_mem (True);
117
      writeQ.deq();
118
      if (isValid(writeQ.first()))
119
         begin
120
            let data = fromMaybe(?,writeQ.first());
121
            writeCount <= writeCount - 1;
122
            plbMaster.wordInput.put(data);
123
            if (writeCount[1:0] == 1)
124
               begin
125
                  baseRegStore <= baseRegStore + fromInteger(valueof(BlockSize));
126
                  plbMaster.plbMasterCommandInput.put(tagged StorePage (baseRegStore));
127
               end
128
         end
129
   endrule
130
 
131
   rule incrTimer (state == Running);
132
      timer <= timer + 1;
133
   endrule
134
 
135
   rule finishSort(state == Running && resCount == 0 && writeCount == 0);
136
      state <= Idle;
137
      feeder.ppcMessageInput.put(truncate(timer));
138
   endrule
139
 
140
   rule heart_beat(state == Running && timer[19:0] == 1000000);
141
      feeder.ppcMessageInput.put(0);
142
   endrule
143
 
144
   interface plbMasterWires = plbMaster.plbMasterWires;
145
   interface bramInitiatorWires = feeder.bramInitiatorWires;
146
 
147
endmodule

powered by: WebSVN 2.1.0

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