Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DividedFIFO has added #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/DividedFIFO.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* This module helps create a large FIFO with no timing issues. */

package DividedFIFO;
import FIFO::*;
import Vector::*;
import BRAM::*;
import BRAMFIFO::*;

interface DividedBRAMFIFOIfc#(type t, numeric type srcSz, numeric type steps);
method Action enq(t d);
method t first;
method Action deq;
endinterface

interface DividedFIFOIfc#(type t, numeric type srcSz, numeric type steps);
method Action enq(t d);
method t first;
method Action deq;
endinterface


module mkDividedBRAMFIFO (DividedBRAMFIFOIfc#(t, srcSz, steps))
provisos (
Bits#(t , a__),
Add#(1, b__, a__),
Div#(srcSz, steps, dstSz)
);
FIFO#(t) inQ <- mkFIFO;
FIFO#(t) outQ <- mkFIFO;

Vector#(steps, FIFO#(t)) fifos <- replicateM(mkSizedBRAMFIFO(valueOf(dstSz)));

for (Integer i = 0; i < valueOf(steps) - 1; i = i + 1) begin
rule relay;
fifos[i].deq;
fifos[i+1].enq(fifos[i].first);
endrule
end

rule in_queue;
inQ.deq;
fifos[0].enq(inQ.first);
endrule

rule de_queue;
fifos[valueOf(steps) - 1].deq;
outQ.enq(fifos[valueOf(steps) - 1].first);
endrule

method Action enq(t d);
inQ.enq(d);
endmethod
method t first;
return outQ.first;
endmethod
method Action deq;
outQ.deq;
endmethod
endmodule

module mkDividedFIFO (DividedFIFOIfc#(t, srcSz, steps))
provisos (
Bits#(t , a__),
Add#(1, b__, a__),
Div#(srcSz, steps, dstSz)
);
FIFO#(t) inQ <- mkFIFO;
FIFO#(t) outQ <- mkFIFO;

Vector#(steps, FIFO#(t)) fifos <- replicateM(mkSizedFIFO(valueOf(dstSz)));

for (Integer i = 0; i < valueOf(steps) - 1; i = i + 1) begin
rule relay;
fifos[i].deq;
fifos[i+1].enq(fifos[i].first);
endrule
end

rule in_queue;
inQ.deq;
fifos[0].enq(inQ.first);
endrule

rule de_queue;
fifos[valueOf(steps) - 1].deq;
outQ.enq(fifos[valueOf(steps) - 1].first);
endrule

method Action enq(t d);
inQ.enq(d);
endmethod
method t first;
return outQ.first;
endmethod
method Action deq;
outQ.deq;
endmethod
endmodule

endpackage: DividedFIFO