Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Counter a where
- countMin :: a
- countMax :: a
- countSuccOverflow :: a -> (Bool, a)
- countPredOverflow :: a -> (Bool, a)
Documentation
>>>
import Clash.Class.Counter
>>>
import Clash.Sized.BitVector (BitVector)
>>>
import Clash.Sized.Index (Index)
>>>
import Clash.Sized.Signed (Signed)
>>>
import Clash.Sized.Unsigned (Unsigned)
class Counter a where Source #
Counter
is a class that composes multiple counters
into a single one. It is similar to odometers found in olds cars,
once all counters reach their maximum they reset to zero - i.e. odometer
rollover. See countSucc
and countPred
for API usage examples.
Example use case: when driving a monitor through VGA you would like to keep track at least two counters: one counting a horizontal position, and one vertical. Perhaps a fancy VGA driver would also like to keep track of the number of drawn frames. To do so, the three counters are setup with different types. On each round of the horizontal counter the vertical counter should be increased. On each round of the vertical counter the frame counter should be increased. With this class you could simply use the type:
(FrameCount, VerticalCount, HorizontalCount)
and have countSucc
work as described.
NB: This class exposes four functions countMin
, countMax
,
countSuccOverflow
, and countPredOverflow
. These functions are considered
an internal API. Users are encouraged to use countSucc
and countPred
.
Nothing
Value counter wraps around to on a countSuccOverflow
overflow
Value counter wraps around to on a countPredOverflow
overflow
countSuccOverflow :: a -> (Bool, a) Source #
Gets the successor of a
. If it overflows, the first part of the tuple
will be set to True and the second part wraps around to countMin
.
countPredOverflow :: a -> (Bool, a) Source #
Gets the predecessor of a
. If it underflows, the first part of the tuple
will be set to True and the second part wraps around to countMax
.
Instances
KnownNat n => Counter (BitVector n) Source # | |
(1 <= n, KnownNat n) => Counter (Index n) Source # | |
KnownNat n => Counter (Unsigned n) Source # | |
KnownNat n => Counter (Signed n) Source # | |
(Counter a, Counter b) => Counter (Either a b) Source # | Counter instance that flip-flops between
|
(Counter a0, Counter a1) => Counter (a0, a1) Source # | Counters on tuples increment from right-to-left. This makes sense from the perspective of LSB/MSB; MSB is on the left-hand-side and LSB is on the right-hand-side in other Clash types.
NB: The documentation only shows the instances up to 3-tuples. By
default, instances up to and including 12-tuples will exist. If the flag
|
Defined in Clash.Class.Counter.Internal | |
(Counter a0, Counter a1, Counter a2) => Counter (a0, a1, a2) Source # | |
Defined in Clash.Class.Counter.Internal |