{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Safe #-}
{-# OPTIONS_HADDOCK show-extensions, not-home #-}
module Clash.Explicit.Prelude.Safe
(
mealy
, mealyB
, moore
, mooreB
, registerB
, dualFlipFlopSynchronizer
, asyncFIFOSynchronizer
, asyncRom
, asyncRomPow2
, rom
, romPow2
, asyncRomBlob
, asyncRomBlobPow2
, romBlob
, romBlobPow2
, asyncRam
, asyncRamPow2
, blockRam
, blockRamPow2
, blockRamBlob
, blockRamBlobPow2
, MemBlob
, createMemBlob
, memBlobTH
, unpackMemBlob
, readNew
, trueDualPortBlockRam
, RamOp(..)
, isRising
, isFalling
, riseEvery
, oscillate
, module Clash.Explicit.Signal
, module Clash.Explicit.Signal.Delayed
, module Clash.Sized.BitVector
, module Clash.Sized.Signed
, module Clash.Sized.Unsigned
, module Clash.Sized.Index
, module Clash.Sized.Fixed
, module Clash.Sized.Vector
, module Clash.Sized.RTree
, module Clash.Annotations.TopEntity
, Generic
, Generic1
, module GHC.TypeLits
, module GHC.TypeLits.Extra
, module Clash.Promoted.Nat
, module Clash.Promoted.Nat.Literals
, module Clash.Promoted.Nat.TH
, module Clash.Promoted.Symbol
, module Clash.Class.BitPack
, module Clash.Class.Num
, module Clash.Class.Resize
, module Control.Applicative
, module Data.Bits
, module Clash.XException
, module Clash.NamedTypes
, module Clash.HaskellPrelude
)
where
import Control.Applicative
import Data.Bits
import GHC.Generics (Generic, Generic1)
import GHC.TypeLits
#if MIN_VERSION_base(4,18,0)
hiding (SNat, SSymbol, fromSNat)
#endif
import GHC.TypeLits.Extra
import Clash.HaskellPrelude
import qualified Prelude
import Clash.Annotations.TopEntity
import Clash.Class.BitPack
import Clash.Class.Num
import Clash.Class.Resize
import Clash.NamedTypes
import Clash.Explicit.BlockRam
import Clash.Explicit.BlockRam.Blob
import Clash.Explicit.Mealy
import Clash.Explicit.Moore
import Clash.Explicit.RAM
import Clash.Explicit.ROM
import Clash.Explicit.ROM.Blob
import Clash.Explicit.Signal
import Clash.Explicit.Signal.Delayed
import Clash.Explicit.Synchronizer
(dualFlipFlopSynchronizer, asyncFIFOSynchronizer)
import Clash.Prelude.ROM.Blob (asyncRomBlob, asyncRomBlobPow2)
import Clash.Prelude.ROM (asyncRom, asyncRomPow2)
import Clash.Promoted.Nat
import Clash.Promoted.Nat.TH
import Clash.Promoted.Nat.Literals
import Clash.Promoted.Symbol
import Clash.Sized.BitVector
import Clash.Sized.Fixed
import Clash.Sized.Index
import Clash.Sized.RTree
import Clash.Sized.Signed
import Clash.Sized.Unsigned
import Clash.Sized.Vector hiding (fromList, unsafeFromList)
import Clash.XException
registerB
:: ( KnownDomain dom
, NFDataX a
, Bundle a )
=> Clock dom
-> Reset dom
-> Enable dom
-> a
-> Unbundled dom a
-> Unbundled dom a
registerB clk rst en i =
unbundle Prelude.. register clk rst en i Prelude.. bundle
{-# INLINE registerB #-}
isRising
:: ( KnownDomain dom
, NFDataX a
, Bounded a
, Eq a )
=> Clock dom
-> Reset dom
-> Enable dom
-> a
-> Signal dom a
-> Signal dom Bool
isRising clk rst en is s = liftA2 edgeDetect prev s
where
prev = register clk rst en is s
edgeDetect old new = old == minBound && new == maxBound
{-# INLINABLE isRising #-}
isFalling
:: ( KnownDomain dom
, NFDataX a
, Bounded a
, Eq a )
=> Clock dom
-> Reset dom
-> Enable dom
-> a
-> Signal dom a
-> Signal dom Bool
isFalling clk rst en is s = liftA2 edgeDetect prev s
where
prev = register clk rst en is s
edgeDetect old new = old == maxBound && new == minBound
{-# INLINABLE isFalling #-}
riseEvery
:: forall dom n
. KnownDomain dom
=> Clock dom
-> Reset dom
-> Enable dom
-> SNat n
-> Signal dom Bool
riseEvery clk rst en SNat = moore clk rst en transfer output 0 (pure ())
where
output :: Index n -> Bool
output = (== maxBound)
transfer :: Index n -> () -> Index n
transfer s _ = if (s == maxBound) then 0 else s+1
{-# INLINEABLE riseEvery #-}
oscillate
:: forall dom n
. KnownDomain dom
=> Clock dom
-> Reset dom
-> Enable dom
-> Bool
-> SNat n
-> Signal dom Bool
oscillate clk rst en begin SNat =
moore clk rst en transfer snd (0, begin) (pure ())
where
transfer :: (Index n, Bool) -> () -> (Index n, Bool)
transfer (s, i) _ =
if s == maxBound
then (0, not i)
else (s+1, i)
{-# INLINEABLE oscillate #-}