Safe Haskell | None |
---|---|
Language | Haskell2010 |
- (<^>) :: (Pack i, Pack o) => (s -> i -> (s, o)) -> s -> SignalP i -> SignalP o
- registerP :: Pack a => a -> SignalP a -> SignalP a
- newtype Comp a b = C {
- asFunction :: Signal a -> Signal b
- (^^^) :: (s -> i -> (s, o)) -> s -> Comp i o
- registerC :: a -> Comp a a
- simulateC :: Comp a b -> [a] -> [b]
- blockRam :: forall n m a. (KnownNat n, KnownNat m, Pack a) => SNat n -> Signal (Unsigned m) -> Signal (Unsigned m) -> Signal Bool -> Signal a -> Signal a
- blockRamPow2 :: (KnownNat n, KnownNat (2 ^ n), Pack a) => SNat (2 ^ n :: Nat) -> Signal (Unsigned n) -> Signal (Unsigned n) -> Signal Bool -> Signal a -> Signal a
- blockRamC :: (KnownNat n, KnownNat m, Pack a) => SNat n -> Comp (Unsigned m, Unsigned m, Bool, a) a
- blockRamPow2C :: (KnownNat n, KnownNat (2 ^ n), Pack a) => SNat (2 ^ n :: Nat) -> Comp (Unsigned n, Unsigned n, Bool, a) a
- window :: (KnownNat (n + 1), Default a) => Signal a -> Vec ((n + 1) + 1) (Signal a)
- windowD :: (KnownNat (n + 1), Default a) => Signal a -> Vec (n + 1) (Signal a)
Creating synchronous sequential circuits
:: (Pack i, Pack o) | |
=> (s -> i -> (s, o)) | Transfer function in mealy machine form: |
-> s | Initial state |
-> SignalP i -> SignalP o | Synchronous sequential function with input and output matching that of the mealy machine |
Create a synchronous function from a combinational function describing a mealy machine
mac :: Int -- Current state -> (Int,Int) -- Input -> (Int,Int) -- (Updated state, output) mac s (x,y) = (s',s) where s' = x * y + s topEntity :: (Signal Int, Signal Int) -> Signal Int topEntity = mac <^> 0 simulateP topEntity [(1,1),(2,2),(3,3),(4,4),... == [0,1,5,14,30,...
Synchronous sequential functions can be composed just like their combinational counterpart:
dualMac :: (Signal Int, Signal Int) -> (Signal Int, Signal Int) -> Signal Int dualMac (a,b) (x,y) = s1 + s2 where s1 = (mac <^> 0) (a,b) s2 = (mac <^> 0) (x,y)
registerP :: Pack a => a -> SignalP a -> SignalP a Source
Create a register
function for product-type like signals (e.g. '(Signal a, Signal b)')
rP :: (Signal Int,Signal Int) -> (Signal Int, Signal Int) rP = registerP (8,8) simulateP rP [(1,1),(2,2),(3,3),... == [(8,8),(1,1),(2,2),(3,3),...
Arrow
interface for synchronous sequential circuits
C | |
|
:: (s -> i -> (s, o)) | Transfer function in mealy machine form: |
-> s | Initial state |
-> Comp i o | Synchronous sequential |
Create a synchronous Comp
onent from a combinational function describing
a mealy machine
mac :: Int -- Current state -> (Int,Int) -- Input -> (Int,Int) -- (Updated state, output) mac s (x,y) = (s',s) where s' = x * y + s topEntity :: Comp (Int,Int) Int topEntity = mac ^^^ 0 simulateC topEntity [(1,1),(2,2),(3,3),(4,4),... == [0,1,5,14,30,...
Synchronous sequential must be composed using the Arrow
syntax
dualMac :: Comp (Int,Int,Int,Int) Int dualMac = proc (a,b,x,y) -> do rec s1 <- mac ^^^ 0 -< (a,b) s2 <- mac ^^^ 0 -< (x,y) returnA -< (s1 + s2)
simulateC :: Comp a b -> [a] -> [b] Source
Simulate a Comp
onent given a list of samples
simulateC (registerC 8) [1, 2, 3, ... == [8, 1, 2, 3, ...
BlockRAM primitives
:: forall n m a . (KnownNat n, KnownNat m, Pack a) | |
=> SNat n | Size |
-> Signal (Unsigned m) | Write address |
-> Signal (Unsigned m) | Read address |
-> Signal Bool | Write enable |
-> Signal a | Value to write (at address |
-> Signal a | Value of the |
Create a blockRAM with space for n
elements
bram40 :: Signal (Unsigned 6) -> Signal (Unsigned 6) -> Signal Bool -> Signal a -> Signal a bram40 = blockRam d50
:: (KnownNat n, KnownNat (2 ^ n), Pack a) | |
=> SNat (2 ^ n :: Nat) | Size |
-> Signal (Unsigned n) | Write address |
-> Signal (Unsigned n) | Read address |
-> Signal Bool | Write enable |
-> Signal a | Value to write (at address |
-> Signal a | Value of the |
Create a blockRAM with space for 2^n
elements
bram32 :: Signal (Unsigned 5) -> Signal (Unsigned 5) -> Signal Bool -> Signal a -> Signal a bram32 = blockRamPow2 d32
:: (KnownNat n, KnownNat m, Pack a) | |
=> SNat n | Size |
-> Comp (Unsigned m, Unsigned m, Bool, a) a |
Create a blockRAM with space for n
elements
bramC40 :: Comp (Unsigned 6, Unsigned 6, Bool, a) a bramC40 = blockRamC d50
:: (KnownNat n, KnownNat (2 ^ n), Pack a) | |
=> SNat (2 ^ n :: Nat) | Size |
-> Comp (Unsigned n, Unsigned n, Bool, a) a |
Create a blockRAM with space for 2^n
elements
bramC32 :: Comp (Unsigned 5, Unsigned 5, Bool, a) a bramC32 = blockRamPow2C d32
Utility functions
window :: (KnownNat (n + 1), Default a) => Signal a -> Vec ((n + 1) + 1) (Signal a) Source
Give a window over a Signal
window4 :: Signal Int -> Vec 4 (Signal Int) window4 = window simulateP window4 [1,2,3,4,5,... == [1:>0:>0:>0:>Nil, 2:>1:>0:>0:>Nil, 3:>2:>1:>0:>Nil, 4:>3:>2:>1:>Nil, 5:>4:>3:>2:>Nil,...