[Haskell-cafe] ANN: clash- (Functional Hardware Descriptions)

Christiaan Baaij christiaan.baaij at gmail.com
Fri Mar 25 23:43:13 CET 2011


The 'Comp' type is an automata arrow. In version it was called
'Stat' [1], and was actually a newtype.
The definition of Comp is:

> data Comp i o = C {
>    domain :: Set.Set Clock
>  , exec     :: Clock -> i -> (o, Comp i o)
>  }

If you don't care about clock domains you can use the original lifting
function (^^^) to lift transition functions to arrows.
Below is an example that combines to multiply-accumulate circuits:

> type Int8 = Signed D8
> mac (State acc) (x,y) = (State (acc+x*y), acc)
> dualMac :: Comp (Int8, Int8, Int8, Int8) Int8
> dualMac = proc (a,b,c,d) -> do
>   x <- mac ^^^ 0 -< (a,b)
>  y <- mac ^^^ 0 -< (c,d)
>  returnA -< (x+y)

If you do care about the clockdomain a component belongs to you use
new multi-clock lifting function 'comp'.
Below is an example of a component, 'keyboard' working in the keyboard
clock domain, which is "20x slower" than the system clock. Also it
responds to the 'falling' edge of the clock.
The component that generates a sine-tone 'tonegeneration' runs at the
system clock.
There is also a synchronizing component 'synchronize' that runs at the
system clock, using a dual flipflop, to synchronize the 'newKey'
control value.

> kbclock = ClockDown 20
> sysclock = ClockUp 1
> synthesizer :: Comp Bit (Signed D16)
> synthesizer = proc kbdata -> do
>   (key,newKey) <- comp keyboard initkb kbclock               -< kbdata
>   newKS           <- comp synchronize False sysclock         -< newKey
>   tone               <- comp tonegeneration initTone sysclock -< (key,newKS)
>   returnA -< tone

At the moment you shouldn't mix components created by the 'comp'
function and the (^^^) function.
The reason is that functions lifted with (^^^) would then basically
operate in all introduced clock-domains when used in a multi-clock
You can use the simulateM function to simulate descriptions that use
multiple clock domains.
Example use of the simulateM function can be found in
'Testbench/AudioConfTest.hs' of our DATE'11 demo [2].
Available simulation statements for a simulation session can be found
in 'CLasH/HardwareTypes.hs'. [3]

As you might have figured out by now: our simulation of a multi-clock
environment is not "truely" GALS.
The clocks are certainly linked. For example, if you define:

> clk1   = ClockUp 1
> clk5   = ClockUp 5
> clk20 = ClockUp 20

You could/should interpret it that clk1 has a period of 1ns, clk5 a
period of 5 ns, etc.
So clk1 runs 5 times faster than clk5, and clk5 runs 4 times faster than clk20.
As we can't simulate the effects of meta-stability, there is no
incentive for us to also give the clocks some decimal offset at this
point in the development of CLaSH.

I hope you have a better understanding of the multiple clock domain
stuff now :-)



[1] Marco Gerards, a PhD student from our group who originally
introduced Arrows in CLaSH, called it 'Stat' for reasons I no longer
know. We recently agreed that 'Comp', an abbreviation for 'Component',
is a more sensible name.
[2] http://github.com/christiaanb/DE1-Cyclone-II-FPGA-Board-Support-Package/blob/master/Testbench/AudioConfTest.hs
[3] http://github.com/christiaanb/clash/blob/master/clash/CLasH/HardwareTypes.hs

On Fri, Mar 25, 2011 at 12:19 PM, Bin Jin <bjin1990 at gmail.com> wrote:
> Hello,
> Can you give some brief notes on the new introduced clock-related stuff like
> Comp?
> Thanks
> --Bin Jin

More information about the Haskell-Cafe mailing list