clash-prelude-0.99.1: CAES Language for Synchronous Hardware - Prelude library

Copyright(C) 2013-2016 University of Twente
2017 Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell2010
Extensions
  • Cpp
  • MonoLocalBinds
  • ScopedTypeVariables
  • TypeFamilies
  • GADTs
  • GADTSyntax
  • DataKinds
  • DeriveFunctor
  • DeriveTraversable
  • DeriveFoldable
  • DeriveLift
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • MagicHash
  • KindSignatures
  • GeneralizedNewtypeDeriving
  • TypeOperators
  • ExplicitNamespaces
  • ExplicitForAll

Clash.Explicit.Signal.Delayed

Contents

Description

 
Synopsis

Delay-annotated synchronous signals

data DSignal (domain :: Domain) (delay :: Nat) a Source #

A synchronized signal with samples of type a, synchronized to clock clk, that has accumulated delay amount of samples delay along its path.

Instances
Functor (DSignal domain delay) Source # 
Instance details

Methods

fmap :: (a -> b) -> DSignal domain delay a -> DSignal domain delay b #

(<$) :: a -> DSignal domain delay b -> DSignal domain delay a #

Applicative (DSignal domain delay) Source # 
Instance details

Methods

pure :: a -> DSignal domain delay a #

(<*>) :: DSignal domain delay (a -> b) -> DSignal domain delay a -> DSignal domain delay b #

liftA2 :: (a -> b -> c) -> DSignal domain delay a -> DSignal domain delay b -> DSignal domain delay c #

(*>) :: DSignal domain delay a -> DSignal domain delay b -> DSignal domain delay b #

(<*) :: DSignal domain delay a -> DSignal domain delay b -> DSignal domain delay a #

Foldable (DSignal domain delay) Source # 
Instance details

Methods

fold :: Monoid m => DSignal domain delay m -> m #

foldMap :: Monoid m => (a -> m) -> DSignal domain delay a -> m #

foldr :: (a -> b -> b) -> b -> DSignal domain delay a -> b #

foldr' :: (a -> b -> b) -> b -> DSignal domain delay a -> b #

foldl :: (b -> a -> b) -> b -> DSignal domain delay a -> b #

foldl' :: (b -> a -> b) -> b -> DSignal domain delay a -> b #

foldr1 :: (a -> a -> a) -> DSignal domain delay a -> a #

foldl1 :: (a -> a -> a) -> DSignal domain delay a -> a #

toList :: DSignal domain delay a -> [a] #

null :: DSignal domain delay a -> Bool #

length :: DSignal domain delay a -> Int #

elem :: Eq a => a -> DSignal domain delay a -> Bool #

maximum :: Ord a => DSignal domain delay a -> a #

minimum :: Ord a => DSignal domain delay a -> a #

sum :: Num a => DSignal domain delay a -> a #

product :: Num a => DSignal domain delay a -> a #

Traversable (DSignal domain delay) Source # 
Instance details

Methods

traverse :: Applicative f => (a -> f b) -> DSignal domain delay a -> f (DSignal domain delay b) #

sequenceA :: Applicative f => DSignal domain delay (f a) -> f (DSignal domain delay a) #

mapM :: Monad m => (a -> m b) -> DSignal domain delay a -> m (DSignal domain delay b) #

sequence :: Monad m => DSignal domain delay (m a) -> m (DSignal domain delay a) #

Fractional a => Fractional (DSignal domain delay a) Source # 
Instance details

Methods

(/) :: DSignal domain delay a -> DSignal domain delay a -> DSignal domain delay a #

recip :: DSignal domain delay a -> DSignal domain delay a #

fromRational :: Rational -> DSignal domain delay a #

Num a => Num (DSignal domain delay a) Source # 
Instance details

Methods

(+) :: DSignal domain delay a -> DSignal domain delay a -> DSignal domain delay a #

(-) :: DSignal domain delay a -> DSignal domain delay a -> DSignal domain delay a #

(*) :: DSignal domain delay a -> DSignal domain delay a -> DSignal domain delay a #

negate :: DSignal domain delay a -> DSignal domain delay a #

abs :: DSignal domain delay a -> DSignal domain delay a #

signum :: DSignal domain delay a -> DSignal domain delay a #

fromInteger :: Integer -> DSignal domain delay a #

Show a => Show (DSignal domain delay a) Source # 
Instance details

Methods

showsPrec :: Int -> DSignal domain delay a -> ShowS #

show :: DSignal domain delay a -> String #

showList :: [DSignal domain delay a] -> ShowS #

Lift a => Lift (DSignal domain delay a) Source # 
Instance details

Methods

lift :: DSignal domain delay a -> Q Exp #

Default a => Default (DSignal domain delay a) Source # 
Instance details

Methods

def :: DSignal domain delay a

Arbitrary a => Arbitrary (DSignal domain delay a) Source # 
Instance details

Methods

arbitrary :: Gen (DSignal domain delay a)

shrink :: DSignal domain delay a -> [DSignal domain delay a]

CoArbitrary a => CoArbitrary (DSignal domain delay a) Source # 
Instance details

Methods

coarbitrary :: DSignal domain delay a -> Gen b -> Gen b

delayed :: forall domain gated synchronous a n d. KnownNat d => Clock domain gated -> Reset domain synchronous -> Vec d a -> DSignal domain n a -> DSignal domain (n + d) a Source #

Delay a DSignal for d periods.

delay3 :: Clock domain gated -> Reset domain synchronous
       -> DSignal domain n Int -> DSignal domain (n + 3) Int
delay3 clk rst = delayed clk rst (0 :> 0 :> 0 :> Nil)
>>> sampleN 6 (delay3 systemClockGen systemResetGen (dfromList [1..]))
[0,0,0,1,2,3]

delayedI :: (Default a, KnownNat d) => Clock domain gated -> Reset domain synchronous -> DSignal domain n a -> DSignal domain (n + d) a Source #

Delay a DSignal for m periods, where m is derived from the context.

delay2 :: Clock domain gated -> Reset domain synchronous
       -> DSignal domain n Int -> DSignal domain (n + 2) Int
delay2 = delayI
>>> sampleN 6 (delay2 systemClockGen systemResetGen (dfromList [1..]))
[0,0,1,2,3,4]

feedback :: (DSignal domain n a -> (DSignal domain n a, DSignal domain ((n + m) + 1) a)) -> DSignal domain n a Source #

Feed the delayed result of a function back to its input:

mac :: Clock domain gated -> Reset domain synchronous
    -> DSignal domain 0 Int -> DSignal domain 0 Int -> DSignal domain 0 Int
mac clk rst x y = feedback (mac' x y)
  where
    mac' :: DSignal domain 0 Int -> DSignal domain 0 Int -> DSignal domain 0 Int
         -> (DSignal domain 0 Int, DSignal domain 1 Int)
    mac' a b acc = let acc' = a * b + acc
                   in  (acc, delay clk rst (singleton 0) acc')
>>> sampleN 6 (mac systemClockGen systemResetGen (dfromList [1..]) (dfromList [1..]))
[0,1,5,14,30,55]

Signal <-> DSignal conversion

fromSignal :: Signal domain a -> DSignal domain 0 a Source #

Signals are not delayed

sample s == dsample (fromSignal s)

toSignal :: DSignal domain delay a -> Signal domain a Source #

Strip a DSignal from its delay information.

List <-> DSignal conversion (not synthesisable)

dfromList :: NFData a => [a] -> DSignal domain 0 a Source #

Create a DSignal from a list

Every element in the list will correspond to a value of the signal for one clock cycle.

>>> sampleN 2 (dfromList [1,2,3,4,5])
[1,2]

NB: This function is not synthesisable

lazy versions

dfromList_lazy :: [a] -> DSignal domain 0 a Source #

Create a DSignal from a list

Every element in the list will correspond to a value of the signal for one clock cycle.

>>> sampleN 2 (dfromList [1,2,3,4,5])
[1,2]

NB: This function is not synthesisable

Experimental

unsafeFromSignal :: Signal domain a -> DSignal domain n a Source #

EXPERIMENTAL

Unsafely convert a Signal to any DSignal clk'.

NB: Should only be used to interface with functions specified in terms of Signal.

antiDelay :: SNat d -> DSignal domain (n + d) a -> DSignal domain n a Source #

EXPERIMENTAL

Access a delayed signal in the present.

mac :: Clock domain gated -> Reset domain synchronous
    -> DSignal domain 0 Int -> DSignal domain 0 Int -> DSignal domain 0 Int
mac clk rst x y = acc'
  where
    acc' = (x * y) + antiDelay d1 acc
    acc  = delay clk rst (singleton 0) acc'