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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [sort/] [BRAM_v/] [NewBRAMFIFO.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
//----------------------------------------------------------------------//
2
//                          Qualcomm Proprietary                        //
3
//                     Copyright (c) 2006 Qualcomm Inc.                 //
4
//                          All rights reserved.                        //
5
//----------------------------------------------------------------------//
6
//        File: $RCSfile: NewBRAMFIFO.bsv,v $
7
//      Author: Alfred Man Cheuk Ng, Abhinav Agarwal
8
//     Created: 2007-07-13
9
// Description: FIFO and FIFOF implemented using BRAM, default 4 elements
10
//
11
//----------------------------------------------------------------------//
12
// $Id: NewBRAMFIFO.bsv,v 1.1 2008-06-30 16:02:10 kfleming Exp $
13
//----------------------------------------------------------------------//
14
 
15
import BRAM::*;
16
import EHRReg::*;
17
import FIFO::*;
18
import FIFOF::*;
19
 
20
// schedule = (notEmpty = first < deq < notFull < enq) C clear
21
module mkNewBRAMFIFOF(FIFOF#(a))
22
   provisos (Bits#(a,asz));
23
 
24
   // state elements
25
   UGBRAM#(Bit#(8), a) bram  <- mkBypassUGBRAM_Full; // 256 elements memory storage
26
   EHRReg#(2,Bit#(8))  head  <- mkEHRReg(0);         // head pointer
27
   EHRReg#(2,Bit#(8))  tail  <- mkEHRReg(0);         // tail pointer
28
   EHRReg#(2,Bool)     over  <- mkEHRReg(False);     // negate everytime either head or tail overthrow
29
   Wire#(a)            resp  <- mkDWire(?);          //
30
 
31
   // signals
32
   let canDeq = head[0] != tail[0] || over[0];
33
   let canEnq = head[0] != tail[0] || !over[0];      // cannot enq and deq simutaneously when full
34
 
35
   // rules
36
   rule prefetchHead(True);
37
      bram.read_req(head[1]);
38
   endrule
39
 
40
   rule getReadresp(True);
41
      resp <= bram.read_resp;
42
   endrule
43
 
44
   // interface methods
45
   method Action enq(a x) if (canEnq);
46
      bram.write(tail[1],x);
47
      if (tail[1] == maxBound) // max idx, wrap around ptr
48
         begin
49
            tail[1] <= 0;
50
            over[1] <= !over[1];
51
         end
52
      else
53
         tail[1] <= tail[1] + 1;
54
   endmethod
55
 
56
   method a first() if (canDeq);
57
      return resp;
58
   endmethod
59
 
60
   method Action deq() if (canDeq);
61
      if (head[0] == maxBound)
62
         begin
63
            head[0] <= 0;
64
            over[0] <= !over[0];
65
         end
66
      else
67
         head[0] <= head[0] + 1;
68
   endmethod
69
 
70
   method Bool notEmpty();
71
      return canDeq;
72
   endmethod
73
 
74
   method Bool notFull();
75
      return canEnq;
76
   endmethod
77
 
78
   method Action clear();
79
      head[0] <= 0;
80
      tail[1] <= 0;
81
      over[1] <= False;
82
   endmethod
83
 
84
endmodule
85
 
86
// schedule = (first < deq < enq) C clear
87
module mkNewBRAMFIFO(FIFO#(a))
88
   provisos (Bits#(a,asz));
89
 
90
   // state elements
91
   FIFOF#(a) fifo <- mkNewBRAMFIFOF;
92
 
93
   // interface methods
94
   method Action enq(a x) = fifo.enq(x);
95
   method a      first()  = fifo.first;
96
   method Action deq()    = fifo.deq;
97
   method Action clear()  = fifo.clear;
98
 
99
endmodule

powered by: WebSVN 2.1.0

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