Copyright | (C) 2021 QBayLogic B.V. |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | QBayLogic B.V. <devops@qbaylogic.com> |
Safe Haskell | None |
Language | Haskell2010 |
Utilities for wrapping counters consisting of multiple individual counters
Documentation
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.
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
Counter Bool Source # | Since: 1.8.2 |
Counter Int Source # | Since: 1.8.2 |
Counter Int8 Source # | Since: 1.8.2 |
Counter Int16 Source # | Since: 1.8.2 |
Counter Int32 Source # | Since: 1.8.2 |
Counter Int64 Source # | Since: 1.8.2 |
Counter Word Source # | Since: 1.8.2 |
Counter Word8 Source # | Since: 1.8.2 |
Counter Word16 Source # | Since: 1.8.2 |
Counter Word32 Source # | Since: 1.8.2 |
Counter Word64 Source # | Since: 1.8.2 |
Counter Bit Source # | Since: 1.8.2 |
Counter a => Counter (Maybe a) Source # |
Since: 1.8.2 |
Counter a => Counter (Identity a) Source # | Since: 1.8.2 |
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 | |
(Counter a0, Counter a1, Counter a2, Counter a3) => Counter (a0, a1, a2, a3) Source # | |
Defined in Clash.Class.Counter.Internal | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4) => Counter (a0, a1, a2, a3, a4) Source # | |
Defined in Clash.Class.Counter.Internal | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5) => Counter (a0, a1, a2, a3, a4, a5) Source # | |
Defined in Clash.Class.Counter.Internal | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6) => Counter (a0, a1, a2, a3, a4, a5, a6) Source # | |
Defined in Clash.Class.Counter.Internal | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7) => Counter (a0, a1, a2, a3, a4, a5, a6, a7) Source # | |
Defined in Clash.Class.Counter.Internal countMin :: (a0, a1, a2, a3, a4, a5, a6, a7) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7)) Source # | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source # | |
Defined in Clash.Class.Counter.Internal countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8)) Source # | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # | |
Defined in Clash.Class.Counter.Internal countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)) Source # | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9, Counter a10) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # | |
Defined in Clash.Class.Counter.Internal countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)) Source # | |
(Counter a0, Counter a1, Counter a2, Counter a3, Counter a4, Counter a5, Counter a6, Counter a7, Counter a8, Counter a9, Counter a10, Counter a11) => Counter (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # | |
Defined in Clash.Class.Counter.Internal countMin :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # countMax :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # countSuccOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)) Source # countPredOverflow :: (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) -> (Bool, (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)) Source # |
countSucc :: Counter a => a -> a Source #
Successor of a counter.
Examples:
>>>
type T = (Unsigned 2, Unsigned 2)
>>>
countSucc @T (1, 1)
(1,2)>>>
countSucc @T (1, 2)
(1,3)>>>
countSucc @T (1, 3)
(2,0)>>>
countSucc @T (3, 3)
(0,0)>>>
countSucc @(Index 9, Index 2) (0, 1)
(1,0)>>>
countSucc @(Either (Index 9) (Index 9)) (Left 8)
Right 0
countPred :: Counter a => a -> a Source #
Predecessor of a counter
Examples:
>>>
type T = (Unsigned 2, Unsigned 2)
>>>
countPred @T (1, 2)
(1,1)>>>
countPred @T (1, 3)
(1,2)>>>
countPred @T (2, 0)
(1,3)>>>
countPred @T (0, 0)
(3,3)>>>
countPred @(Index 9, Index 2) (1, 0)
(0,1)>>>
countPred @(Either (Index 9) (Index 9)) (Right 0)
Left 8