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

Copyright(C) 2015-2016 University of Twente
2016-2017 Myrtle Software Ltd
2017 Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <>
Safe HaskellSafe
  • Cpp
  • MonoLocalBinds
  • ScopedTypeVariables
  • TypeFamilies
  • DataKinds
  • KindSignatures
  • TypeOperators
  • ExplicitNamespaces
  • ExplicitForAll
  • TypeApplications




Synchronizer circuits for safe clock domain crossings



dualFlipFlopSynchronizer Source #


:: Clock domain1 gated1

Clock to which the incoming data is synchronised

-> Clock domain2 gated2

Clock to which the outgoing data is synchronised

-> Reset domain2 synchronous

Reset for registers on the outgoing domain

-> a

Initial value of the two synchronisation registers

-> Signal domain1 a

Incoming data

-> Signal domain2 a

Outgoing, synchronised, data

Synchroniser based on two sequentially connected flip-flops.

  • NB: This synchroniser can be used for bit-synchronization.
  • NB: Although this synchroniser does reduce metastability, it does not guarantee the proper synchronisation of a whole word. For example, given that the output is sampled twice as fast as the input is running, and we have two samples in the input stream that look like:


    But the circuit driving the input stream has a longer propagation delay on msb compared to the lsbs. What can happen is an output stream that looks like this:


    Where the level-change of the msb was not captured, but the level change of the lsbs were.

    If you want to have safe word-synchronisation use asyncFIFOSynchronizer.


asyncFIFOSynchronizer Source #


:: 2 <= addrSize 
=> SNat addrSize

Size of the internally used addresses, the FIFO contains 2^addrSize elements.

-> Clock wdomain wgated

Clock to which the write port is synchronised

-> Clock rdomain rgated

Clock to which the read port is synchronised

-> Reset wdomain synchronous 
-> Reset rdomain synchronous 
-> Signal rdomain Bool

Read request

-> Signal wdomain (Maybe a)

Element to insert

-> (Signal rdomain a, Signal rdomain Bool, Signal wdomain Bool)

(Oldest element in the FIFO, empty flag, full flag)

Synchroniser implemented as a FIFO around an asynchronous RAM. Based on the design described in Clash.Tutorial, which is itself based on the design described in

NB: This synchroniser can be used for word-synchronization.