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

Copyright (C) 2013-2016 University of Twente2017 Google Inc. BSD2 (see the file LICENSE) Christiaan Baaij Safe Haskell2010

Clash.Prelude.Mealy

Description

Whereas the output of a Moore machine depends on the previous state, the output of a Mealy machine depends on current transition.

Mealy machines are strictly more expressive, but may impose stricter timing requirements.

Synopsis

# Mealy machine synchronised to the system clock

Arguments

 :: HiddenClockReset domain gated synchronous => (s -> i -> (s, o)) Transfer function in mealy machine form: state -> input -> (newstate,output) -> s Initial state -> Signal domain i -> Signal domain 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

macT
:: Int        -- Current state
-> (Int,Int)  -- Input
-> (Int,Int)  -- (Updated state, output)
macT s (x,y) = (s',s)
where
s' = x * y + s

mac :: HiddenClockReset domain gated synchronous => Signal domain (Int, Int) -> Signal domain Int
mac = mealy macT 0

>>> simulate mac [(1,1),(2,2),(3,3),(4,4)]
[0,1,5,14...
...


Synchronous sequential functions can be composed just like their combinational counterpart:

dualMac
:: HiddenClockReset domain gated synchronous
=> (Signal domain Int, Signal domain Int)
-> (Signal domain Int, Signal domain Int)
-> Signal domain Int
dualMac (a,b) (x,y) = s1 + s2
where
s1 = mealy mac 0 (bundle (a,x))
s2 = mealy mac 0 (bundle (b,y))


Arguments

 :: (Bundle i, Bundle o, HiddenClockReset domain gated synchronous) => (s -> i -> (s, o)) Transfer function in mealy machine form: state -> input -> (newstate,output) -> s Initial state -> Unbundled domain i -> Unbundled domain o Synchronous sequential function with input and output matching that of the mealy machine

A version of mealy that does automatic Bundleing

Given a function f of type:

f :: Int -> (Bool, Int) -> (Int, (Int, Bool))


When we want to make compositions of f in g using mealy, we have to write:

g a b c = (b1,b2,i2)
where
(i1,b1) = unbundle (mealy f 0 (bundle (a,b)))
(i2,b2) = unbundle (mealy f 3 (bundle (i1,c)))


Using mealyB however we can write:

g a b c = (b1,b2,i2)
where
(i1,b1) = mealyB f 0 (a,b)
(i2,b2) = mealyB f 3 (i1,c)


Arguments

 :: (Bundle i, Bundle o, HiddenClockReset domain gated synchronous) => (s -> i -> (s, o)) Transfer function in mealy machine form: state -> input -> (newstate,output) -> s Initial state -> Unbundled domain i -> Unbundled domain o Synchronous sequential function with input and output matching that of the mealy machine

Infix version of mealyB
{"ft_lang_label":"__label__en","ft_lang_prob":0.69047827,"math_prob":0.94085574,"size":2916,"snap":"2021-21-2021-25","text_gpt3_token_len":864,"char_repetition_ratio":0.16517857,"word_repetition_ratio":0.38429752,"special_character_ratio":0.3069273,"punctuation_ratio":0.16849817,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9795158,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-14T15:16:33Z\",\"WARC-Record-ID\":\"<urn:uuid:70cbc86f-e2e4-4b73-be0c-67948771eabb>\",\"Content-Length\":\"11973\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3a29e6c2-3b54-410d-8fe7-a819ac50dabc>\",\"WARC-Concurrent-To\":\"<urn:uuid:168144f7-16a4-4ef2-a225-e8b3ba62dde0>\",\"WARC-IP-Address\":\"151.101.248.68\",\"WARC-Target-URI\":\"https://hackage.haskell.org/package/clash-prelude-0.99.1/docs/Clash-Prelude-Mealy.html\",\"WARC-Payload-Digest\":\"sha1:24TVS2RJ35DWYWDHHXD2LCI7RIA4IXDM\",\"WARC-Block-Digest\":\"sha1:PEVL67V6D3ON3SXNQT44OQWJ2DQBLGIJ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623487612537.23_warc_CC-MAIN-20210614135913-20210614165913-00567.warc.gz\"}"}