annotate modules/bluespec/Pygar/lab4/MemArb.bsv @ 22:0cfbb1e2de22 pygar svn.23

[svn r23] whoohoo! it Compiles (note with commented out stuff)
author punk
date Wed, 28 Apr 2010 00:40:15 -0400
parents 74716e9a81cc
children 3958de09a7c1
rev   line source
rlm@8 1 // The MIT License
rlm@8 2
rlm@8 3 // Copyright (c) 2009 Massachusetts Institute of Technology
rlm@8 4
rlm@8 5 // Permission is hereby granted, free of charge, to any person obtaining a copy
rlm@8 6 // of this software and associated documentation files (the "Software"), to deal
rlm@8 7 // in the Software without restriction, including without limitation the rights
rlm@8 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
rlm@8 9 // copies of the Software, and to permit persons to whom the Software is
rlm@8 10 // furnished to do so, subject to the following conditions:
rlm@8 11
rlm@8 12 // The above copyright notice and this permission notice shall be included in
rlm@8 13 // all copies or substantial portions of the Software.
rlm@8 14
rlm@8 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rlm@8 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rlm@8 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rlm@8 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rlm@8 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rlm@8 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rlm@8 21 // THE SOFTWARE.
rlm@8 22
rlm@8 23 import Connectable::*;
rlm@8 24 import GetPut::*;
rlm@8 25 import ClientServer::*;
rlm@8 26 import FIFOF::*;
rlm@8 27 import FIFO::*;
rlm@8 28
rlm@8 29 // Local includes
rlm@8 30 `include "asim/provides/processor_library.bsh"
rlm@8 31
rlm@8 32 interface MemArb;
rlm@8 33
rlm@8 34 interface Server#(MainMemReq,MainMemResp) cache0_server;
rlm@8 35 interface Server#(MainMemReq,MainMemResp) cache1_server;
rlm@8 36 interface Client#(MainMemReq,MainMemResp) mmem_client;
rlm@8 37
rlm@8 38 endinterface
rlm@8 39
rlm@8 40 typedef enum { REQ0, REQ1 } ReqPtr deriving(Eq,Bits);
rlm@8 41
rlm@8 42 module mkMemArb( MemArb );
rlm@8 43
rlm@8 44 //-----------------------------------------------------------
rlm@8 45 // State
rlm@8 46
rlm@8 47 FIFOF#(MainMemReq) req0Q <- mkBFIFOF1();
rlm@8 48 FIFO#(MainMemResp) resp0Q <- mkBFIFO1();
rlm@8 49
rlm@8 50 FIFOF#(MainMemReq) req1Q <- mkBFIFOF1();
rlm@8 51 FIFO#(MainMemResp) resp1Q <- mkBFIFO1();
rlm@8 52
rlm@8 53 FIFO#(MainMemReq) mreqQ <- mkBFIFO1();
rlm@8 54 FIFO#(MainMemResp) mrespQ <- mkBFIFO1();
rlm@8 55
rlm@8 56 Reg#(ReqPtr) nextReq <- mkReg(REQ0);
rlm@8 57
rlm@8 58 //-----------------------------------------------------------
rlm@8 59 // Some wires
rlm@8 60
rlm@8 61 let req0avail = req0Q.notEmpty();
rlm@8 62 let req1avail = req1Q.notEmpty();
rlm@8 63
rlm@8 64 //-----------------------------------------------------------
rlm@8 65 // Rules
rlm@8 66
rlm@8 67 rule chooseReq0 ( req0avail && (!req1avail || (nextReq == REQ0)) );
rlm@8 68 traceTiny("mkMemArb", "memArb req0",req0Q.first());
rlm@8 69
rlm@8 70 // Rewrite tag field if this is a load ...
rlm@8 71 MainMemReq mreq
rlm@8 72 = case ( req0Q.first() ) matches
rlm@8 73 tagged LoadReq .ld : return LoadReq { tag:0, addr:ld.addr };
rlm@8 74 tagged StoreReq .st : return req0Q.first();
rlm@8 75 endcase;
rlm@8 76
rlm@8 77 // Send out the request
rlm@8 78 mreqQ.enq(mreq);
rlm@8 79 nextReq <= REQ1;
rlm@8 80 req0Q.deq();
rlm@8 81
rlm@8 82 endrule
rlm@8 83
rlm@8 84 rule chooseReq1 ( req1avail && (!req0avail || (nextReq == REQ1)) );
rlm@8 85 traceTiny("mkMemArb", "memArb req1",req1Q.first);
rlm@8 86
rlm@8 87 // Rewrite tag field if this is a load ...
rlm@8 88 MainMemReq mreq
rlm@8 89 = case ( req1Q.first() ) matches
rlm@8 90 tagged LoadReq .ld : return LoadReq { tag:1, addr:ld.addr };
rlm@8 91 tagged StoreReq .st : return req1Q.first();
rlm@8 92 endcase;
rlm@8 93
rlm@8 94 // Send out the request
rlm@8 95 mreqQ.enq(mreq);
rlm@8 96 nextReq <= REQ0;
rlm@8 97 req1Q.deq();
rlm@8 98
rlm@8 99 endrule
rlm@8 100
rlm@8 101 rule returnResp;
rlm@8 102 traceTiny("mkMemArb", "resp",mrespQ.first());
rlm@8 103
rlm@8 104 // Use tag to figure out where to send response
rlm@8 105 mrespQ.deq();
rlm@8 106 let tag
rlm@8 107 = case ( mrespQ.first() ) matches
rlm@8 108 tagged LoadResp .ld : return ld.tag;
rlm@8 109 tagged StoreResp .st : return st.tag;
rlm@8 110 endcase;
rlm@8 111
rlm@8 112 if ( tag == 0 )
rlm@8 113 resp0Q.enq(mrespQ.first());
rlm@8 114 else
rlm@8 115 resp1Q.enq(mrespQ.first());
rlm@8 116
rlm@8 117 endrule
rlm@8 118
rlm@8 119 //-----------------------------------------------------------
rlm@8 120 // Methods
rlm@8 121
rlm@8 122 interface Server cache0_server;
rlm@8 123 interface Put request = fifofToPut(req0Q);
rlm@8 124 interface Get response = fifoToGet(resp0Q);
rlm@8 125 endinterface
rlm@8 126
rlm@8 127 interface Server cache1_server;
rlm@8 128 interface Put request = fifofToPut(req1Q);
rlm@8 129 interface Get response = fifoToGet(resp1Q);
rlm@8 130 endinterface
rlm@8 131
rlm@8 132 interface Client mmem_client;
rlm@8 133 interface Get request = fifoToGet(mreqQ);
rlm@8 134 interface Put response = fifoToPut(mrespQ);
rlm@8 135 endinterface
rlm@8 136
rlm@8 137 endmodule
rlm@8 138
rlm@8 139