kansas-lava-0.2.4.2: Kansas Lava is a hardware simulator and VHDL generator.

Language.KansasLava.Signal

Description

The Signal module serves as a representation for the combined shallow and deep embeddings of sequential circuits. The shallow portion is reprented as a stream, the deep portion as a (typed) entity. To allow for multiple clock domains, the Signal type includes an extra type parameter. The type alias `Seq` is for sequential logic in some implicit global clock domain.

Synopsis

# Documentation

data Signal c a Source

These are sequences of values over time. We assume edge triggered logic (checked at (typically) rising edge of clock) This clock is assumed known, based on who is consuming the list. Right now, it is global, but we think we can support multiple clocks with a bit of work.

Constructors

 Signal (Stream (X a)) (D a)

Instances

 (Bounded a, Rep a) => Bounded (Signal i a) (Rep a, Enum a) => Enum (Signal i a) (Rep a, Eq a) => Eq (Signal c a) (Eq a, Show a, Fractional a, Rep a) => Fractional (Signal i a) (Rep a, Integral a) => Integral (Signal i a) (Num a, Rep a) => Num (Signal i a) (Ord a, Rep a) => Ord (Signal i a) (Rep a, Real a) => Real (Signal i a) Rep a => Show (Signal c a) (Show a, Bits a, Rep a) => Bits (Signal i a) Dual (Signal c a)

type Seq a = Signal CLK a Source

Signal in some implicit clock domain.

shallowS :: Signal c a -> Stream (X a) Source

Extract the shallow portion of a `Signal`.

deepS :: Signal c a -> D a Source

Extract the deep portion of a `Signal`.

deepMapS :: (D a -> D a) -> Signal c a -> Signal c a Source

shallowMapS :: (Stream (X a) -> Stream (X a)) -> Signal c a -> Signal c a Source

pureS :: Rep a => a -> Signal i a Source

A pure `Signal`.

witnessS :: Rep a => Witness a -> Signal i a -> Signal i a Source

A `Signal` witness identity function. Useful when typing things.

mkDeepS :: D a -> Signal c a Source

Inject a deep value into a Signal. The shallow portion of the Signal will be an error, if it is every used.

mkShallowS :: Clock c => Stream (X a) -> Signal c a Source

Inject a shallow value into a Signal. The deep portion of the Signal will be an Error if it is ever used.

undefinedS :: forall a sig clk. (Rep a, sig ~ Signal clk) => sig a Source

Create a Signal with undefined for both the deep and shallow elements.

commentS :: forall a sig clk. (Rep a, sig ~ Signal clk) => String -> sig a -> sig a Source

Attach a comment to a `Signal`.

idS :: forall a sig clk. (Rep a, sig ~ Signal clk) => Id -> sig a -> sig a Source

`idS` create an identity function, with a given `Id` tag.

primXS :: Rep a => X a -> String -> Signal i a Source

create a zero-arity Signal value from an `X` value.

primXS1 :: forall a b i. (Rep a, Rep b) => (X a -> X b) -> String -> Signal i a -> Signal i b Source

create an arity-1 Signal function from an `X` function.

primXS2 :: forall a b c i. (Rep a, Rep b, Rep c) => (X a -> X b -> X c) -> String -> Signal i a -> Signal i b -> Signal i c Source

create an arity-2 Signal function from an `X` function.

primXS3 :: forall a b c d i. (Rep a, Rep b, Rep c, Rep d) => (X a -> X b -> X c -> X d) -> String -> Signal i a -> Signal i b -> Signal i c -> Signal i d Source

create an arity-3 Signal function from an `X` function.

primS :: Rep a => a -> String -> Signal i a Source

create a zero-arity Signal value from a value.

primS1 :: (Rep a, Rep b) => (a -> b) -> String -> Signal i a -> Signal i b Source

create an arity-1 Signal function from a function.

primS2 :: (Rep a, Rep b, Rep c) => (a -> b -> c) -> String -> Signal i a -> Signal i b -> Signal i c Source

create an arity-2 Signal function from a function.

primS3 :: (Rep a, Rep b, Rep c, Rep d) => (a -> b -> c -> d) -> String -> Signal i a -> Signal i b -> Signal i c -> Signal i d Source

create an arity-3 Signal function from a function.

toS :: (Clock c, Rep a) => [a] -> Signal c a Source

Convert a list of values into a Signal. The shallow portion of the resulting Signal will begin with the input list, then an infinite stream of X unknowns.

toS' :: (Clock c, Rep a) => [Maybe a] -> Signal c a Source

Convert a list of values into a Signal. The input list is wrapped with a Maybe, and any Nothing elements are mapped to X's unknowns.

toSX :: forall a c. (Clock c, Rep a) => [X a] -> Signal c a Source

Convert a list of X values to a Signal. Pad the end with an infinite list of X unknowns.

fromS :: Rep a => Signal c a -> [Maybe a] Source

Convert a Signal of values into a list of Maybe values.

fromSX :: Rep a => Signal c a -> [X a] Source

Convret a Signal of values into a list of representable values.

takeS :: (Rep a, Clock c) => Int -> Signal c a -> Signal c a Source

take the first n elements of a `Signal`; the rest is undefined.

cmpSignalRep :: forall a c. Rep a => Int -> Signal c a -> Signal c a -> Bool Source

Compare the first depth elements of two Signals.

typeOfS :: forall w clk sig. (Rep w, sig ~ Signal clk) => sig w -> Type Source

Return the Lava type of a representable signal.

class Pack clk a where Source

The Pack class allows us to move between signals containing compound data and signals containing the elements of the compound data. This is done by commuting the signal type constructor with the type constructor representing the compound data. For example, if we have a value x :: Signal sig => sig (a,b), then 'unpack x' converts this to a (sig a, sig b). Dually, pack takes (sig a,sig b) to sig (a,b).

Associated Types

type Unpacked clk a Source

Pull the sig type *out* of the compound data type.

Methods

pack :: Unpacked clk a -> Signal clk a Source

Push the sign type *into* the compound data type.

unpack :: Signal clk a -> Unpacked clk a Source

Instances

 Rep a => Pack i (Maybe a) (Rep a, Size ix) => Pack clk (Matrix ix a) (Rep a, Rep b) => Pack i (a, b) (Rep a, Rep b, Rep c) => Pack i (a, b, c)

mapPacked :: (Pack i a, Pack i b, sig ~ Signal i) => (Unpacked i a -> Unpacked i b) -> sig a -> sig b Source

Given a function over unpacked (composite) signals, turn it into a function over packed signals.

zipPacked :: (Pack i a, Pack i b, Pack i c, sig ~ Signal i) => (Unpacked i a -> Unpacked i b -> Unpacked i c) -> sig a -> sig b -> sig c Source

Lift a binary function operating over unpacked signals into a function over a pair of packed signals.

unpackMatrix :: (Rep a, Size x, sig ~ Signal clk) => sig (Matrix x a) -> Matrix x (sig a) Source

packMatrix :: (Rep a, Size x, sig ~ Signal clk) => Matrix x (sig a) -> sig (Matrix x a) Source

delay :: forall a clk. (Rep a, Clock clk) => Signal clk a -> Signal clk a Source

a delay is a register with no defined default / initial value.

delays :: forall a clk. (Rep a, Clock clk) => Int -> Signal clk a -> Signal clk a Source

delays generates a serial sequence of n delays.

register :: forall a clk. (Rep a, Clock clk) => a -> Signal clk a -> Signal clk a Source

A register is a state element with a reset. The reset is supplied by the clock domain in the Signal.

registers :: forall a clk. (Rep a, Clock clk) => Int -> a -> Signal clk a -> Signal clk a Source

registers generates a serial sequence of n registers, all with the same initial value.

entityD :: forall a. Rep a => String -> D a Source

entityD1 :: forall a1 a. (Rep a, Rep a1) => String -> D a1 -> D a Source

entityD2 :: forall a1 a2 a. (Rep a, Rep a1, Rep a2) => String -> D a1 -> D a2 -> D a Source

entityD3 :: forall a1 a2 a3 a. (Rep a, Rep a1, Rep a2, Rep a3) => String -> D a1 -> D a2 -> D a3 -> D a Source

pureD :: Rep a => a -> D a Source

pureXD :: Rep a => X a -> D a Source