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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkSatCounter.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 mkSatCounter;
2
 
3
interface SatCounter#(numeric type bits);
4
  method Action up();
5
  method Action down();
6
  method Bit#(bits) value();
7
endinterface
8
 
9
 
10
module mkSatCounter#(Bit#(bits) init) (SatCounter#(bits));
11
  Reg#(Bit#(bits)) counter <- mkReg(init);
12
  RWire#(Bit#(0)) up_called <- mkRWire();
13
  RWire#(Bit#(0)) down_called <- mkRWire();
14
 
15
  rule update;
16
    if(up_called.wget matches tagged Valid .x)
17
      begin
18
        if(down_called.wget matches tagged Invalid)
19
          if(counter != ~0)
20
            counter <= counter + 1;
21
      end
22
    else
23
        if(down_called.wget matches tagged Valid .x)
24
            if(counter != 0)
25
               counter <= counter - 1;
26
  endrule
27
 
28
  method Action up();
29
    up_called.wset(0);
30
  endmethod
31
 
32
  method Action down();
33
    down_called.wset(0);
34
  endmethod
35
 
36
  method Bit#(bits) value();
37
    return counter;
38
  endmethod
39
 
40
 
41
endmodule
42
 
43
endpackage

powered by: WebSVN 2.1.0

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