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

Safe HaskellNone
LanguageHaskell2010

CLaSH.Signal.Implicit

Contents

Synopsis

Implicitly clocked synchronous signal

data Signal a Source

A synchronized signal with samples of type a, implicitly synchronized to an unnamed global clock

Instances

Basic circuit functions

signal :: a -> Signal a Source

Create a constant Signal from a combinational value

>>> sample (signal 4)
[4, 4, 4, 4, ...

register :: a -> Signal a -> Signal a Source

register i s delays the values in Signal s for one cycle, and sets the value at time 0 to i

>>> sampleN 3 (register 8 (fromList [1,2,3,4]))
[8,1,2]

class Pack a where Source

Isomorphism between a Signal of a product type (e.g. a tuple) and a product type of Signals.

Instances of Pack must satisfy the following laws:

pack . unpack = id
unpack . pack = id

Associated Types

type SignalP a Source

Methods

pack :: SignalP a -> Signal a Source

Example:

pack :: (Signal a, Signal b) -> Signal (a,b)

However:

pack :: Signal Bit -> Signal Bit

unpack :: Signal a -> SignalP a Source

Example:

unpack :: Signal (a,b) -> (Signal a, Signal b)

However:

unpack :: Signal Bit -> Signal Bit

Instances

Pack Bool 
Pack Double 
Pack Float 
Pack Int 
Pack Integer 
Pack () 
Pack Bit 
Pack (Signed n) 
Pack (Unsigned n) 
Pack (a, b) 
Pack (Vec n a) 
Pack (a, b, c) 
Pack (a, b, c, d) 
Pack (a, b, c, d, e) 
Pack (a, b, c, d, e, f) 
Pack (a, b, c, d, e, f, g) 
Pack (a, b, c, d, e, f, g, h) 

(<^) :: Applicative f => f a -> (a -> b -> c) -> f b -> f c Source

Operator lifting, use in conjunction with (^>)

add2 :: Signal Int -> Signal Int
add2 x = x <^(+)^> (signal 2)
>>> simulate add2 [1,2,3,...
[3,4,5,...

(^>) :: Applicative f => (f a -> f b) -> f a -> f b Source

Operator lifting, use in conjunction with (<^)

add2 :: Signal Int -> Signal Int
add2 x = x <^(+)^> (signal 2)
>>> simulate add2 [1,2,3,...
[3,4,5,...

Simulation functions

simulate :: (Signal a -> Signal b) -> [a] -> [b] Source

Simulate a (Signal a -> Signal b) function given a list of samples of type a

>>> simulate (register 8) [1, 2, 3, ...
[8, 1, 2, 3, ...

simulateP :: (Pack a, Pack b) => (SignalP a -> SignalP b) -> [a] -> [b] Source

Simulate a (SignalP a -> SignalP b) function given a list of samples of type a

>>> simulateP (unpack . register (8,8) . pack) [(1,1), (2,2), (3,3), ...
[(8,8), (1,1), (2,2), (3,3), ...

List <-> Signal conversion

sample :: Signal a -> [a] Source

Get an infinite list of samples from a Signal

The elements in the list correspond to the values of the Signal at consecutive clock cycles

sample s == [s0, s1, s2, s3, ...

sampleN :: Int -> Signal a -> [a] Source

Get a list of n samples from a Signal

The elements in the list correspond to the values of the Signal at consecutive clock cycles

sampleN 3 s == [s0, s1, s2]

fromList :: [a] -> Signal a Source

Create a Signal from a list

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

NB: Simulation only!

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