OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkSizedFIFO_fpga.bsv] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jamey.hick
package mkSizedFIFO_fpga;
2
 
3
import FIFO::*;
4
import RWire::*;
5
import RegFile::*;
6
import IFPGA_FIFO::*;
7
 
8
module mkSizedFIFO_fpga (IFPGA_FIFO#(f_type, size))
9
  provisos(
10
            Bits#(f_type, f_type_length),
11
            Add#(TLog#(size), 0, lg_size),
12
            Add#(TLog#(size), 1, lg_size_plus),
13
            Add#(2, TLog#(size),lg_size_plus_plus),
14
            Add#(1, lg_size_plus, lg_size_plus_plus)
15
          );
16
 
17
  RegFile#(Bit#(TLog#(size)), f_type) data <- mkRegFile(0, fromInteger(valueof(TSub#(size,1))));
18
  Reg#(Bit#(lg_size_plus)) number_enqueued <- mkReg(0);
19
  Reg#(Bit#(TLog#(size))) base_ptr <- mkReg(0);
20
  RWire#(Bit#(0)) deque_pending <- mkRWire();
21
  RWire#(Bit#(0)) clear_pending <- mkRWire();
22
  RWire#(f_type) enque_pending <- mkRWire();
23
 
24
  // We'll have problems with non-saturating additions, so we ought to add some checks
25
  // Strongly Recommend power of 2 sizes to simpilfy logic.
26
 
27
  rule update;
28
    if(clear_pending.wget() matches tagged Valid .v)
29
      begin
30
        //clear is occuring, we drop a pending enqueue on the floor.
31
        number_enqueued <= 0;
32
        base_ptr <= 0;
33
      end
34
    else
35
      begin
36
       if(enque_pending.wget() matches tagged Valid .new_data)
37
         begin
38
           if(deque_pending.wget() matches tagged Valid .dp)
39
             begin
40
               // enque and deque occuring.. no change to net.
41
               base_ptr <= (zeroExtend(base_ptr) == fromInteger(valueof(size)-1))? 0:base_ptr + 1;
42
               Bit#(lg_size_plus_plus) offset = zeroExtend((zeroExtend(base_ptr) + number_enqueued));
43
               data.upd((offset >= fromInteger(valueof(size)))?
44
                           truncate(offset - truncate(fromInteger(valueof(size)))):
45
                          truncate(offset),
46
                       new_data);
47
             end
48
           else
49
             begin
50
               number_enqueued <= number_enqueued + 1;
51
               Bit#(lg_size_plus_plus) offset = zeroExtend((zeroExtend(base_ptr) + number_enqueued));
52
               data.upd((offset >= fromInteger(valueof(size)))?
53
                           truncate(offset - truncate(fromInteger(valueof(size)))):
54
                           truncate(offset),
55
                        new_data);
56
             end
57
         end
58
       else
59
         begin
60
           if(deque_pending.wget() matches tagged Valid .dp)
61
             begin
62
               //enque and deque occuring.. no change to net.
63
               base_ptr <= (zeroExtend(base_ptr) == truncate(fromInteger(valueof(size)-1)))? 0:base_ptr + 1;
64
               number_enqueued <= number_enqueued - 1;
65
             end
66
         end
67
      end
68
  endrule
69
 
70
  interface FIFO fifo;
71
 
72
    method Action enq (f_type value) if(number_enqueued < fromInteger(valueof(size)));
73
      enque_pending.wset(value);
74
    endmethod
75
 
76
    method Action deq()  if(number_enqueued > 0);
77
      deque_pending.wset(0);
78
    endmethod
79
 
80
    method f_type first() if(number_enqueued > 0);
81
      return data.sub(base_ptr);
82
    endmethod
83
 
84
    method Action clear();
85
      clear_pending.wset(0);
86
    endmethod
87
 
88
  endinterface
89
 
90
endmodule
91
endpackage

powered by: WebSVN 2.1.0

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