URL
https://opencores.org/ocsvn/cryptosorter/cryptosorter/trunk
Subversion Repositories cryptosorter
[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [Sort/] [SortTester.bsv] - Rev 6
Compare with Previous | Blame | View Log
/*Copyright (c) 2008 MITPermission is hereby granted, free of charge, to any personobtaining a copy of this software and associated documentationfiles (the "Software"), to deal in the Software withoutrestriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the followingconditions:The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIESOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Author: Kermin Fleming*/import PLBMasterWires::*;import BRAMInitiatorWires::*;import PLBMaster::*;import BRAMFeeder::*;import Interfaces::*;import Parameters::*;import FIFO::*;import FIFOF::*;import BRAMFIFO::*;import GetPut::*;import Types::*;import Memocode08Types::*;import Sort::*;import SortTree64::*;import Vector::*;interface SortTester;interface PLBMasterWires plbMasterWires;interface BRAMInitiatorWires#(Bit#(14)) bramInitiatorWires;endinterfacetypedef enum{Idle,Running,Inputing,Outputing} TesterState deriving (Bits,Eq);module mkSortTester (SortTester);Feeder feeder <- mkBRAMFeeder();PLBMaster plbMaster <- mkPLBMaster;Reg#(TesterState) state <- mkReg(Idle);Reg#(BlockAddr) baseRegStore <- mkRegU();Reg#(Bit#(64)) timer <- mkRegU();Reg#(Bit#(20)) resCount <- mkRegU();Reg#(Bit#(20)) writeCount <- mkRegU();Reg#(Bool) eos <- mkRegU();FIFO#(Bit#(20)) resQ <- mkFIFO();FIFOF#(Maybe#(Record)) writeQ <- mkSizedFIFOF(8);let sortTree <- mkSortTree64();let tok_info = sortTree.inStream.getTokInfo();rule grab_instruction(state == Idle);PPCMessage inst <- feeder.ppcMessageOutput.get;Bit#(5) size = truncate(pack(inst));baseRegStore <= 0;timer <= 0;resCount <= (1<<size)<<1;writeCount <= 1<<size; // half res are for eosstate <= Running;eos <= False;endrulerule read_reserve (state == Running &&resCount > 0 &&tok_info[resCount[5:0]] > 0);resQ.enq(resCount);resCount <= resCount - 1;endrulerule read_request (True);Bit#(20) val = resQ.first();Bit#(6) idx = truncate(val);resQ.deq();sortTree.inStream.putDeqTok(idx,1);if (idx == 1)eos <= !eos;if (!eos) // enq datasortTree.inStream.putRecord(idx,tagged Valid zeroExtend({val[19:7],val[5:0]}));else // eossortTree.inStream.putRecord(idx,tagged Invalid);endrulerule sync_out_stream (state == Running);Vector#(1,Bit#(5)) tok = replicate(zeroExtend(pack(writeQ.notFull())));sortTree.outStream.putTokInfo(tok);endrulerule drain_sorter_finish (True);match {.*,.data} = sortTree.outStream.getRecord();writeQ.enq(data);endrulerule write_to_mem (True);writeQ.deq();if (isValid(writeQ.first()))beginlet data = fromMaybe(?,writeQ.first());writeCount <= writeCount - 1;plbMaster.wordInput.put(data);if (writeCount[1:0] == 1)beginbaseRegStore <= baseRegStore + fromInteger(valueof(BlockSize));plbMaster.plbMasterCommandInput.put(tagged StorePage (baseRegStore));endendendrulerule incrTimer (state == Running);timer <= timer + 1;endrulerule finishSort(state == Running && resCount == 0 && writeCount == 0);state <= Idle;feeder.ppcMessageInput.put(truncate(timer));endrulerule heart_beat(state == Running && timer[19:0] == 1000000);feeder.ppcMessageInput.put(0);endruleinterface plbMasterWires = plbMaster.plbMasterWires;interface bramInitiatorWires = feeder.bramInitiatorWires;endmodule
