简体   繁体   中英

AlwaysError when running a testbench on a synchronizer

I encountered this error when running a testbench, together with a synchronizer built on two existing D-FFs.

File "/home/runner/design.py", line 28, in Sync
    @always_seq(clk.posedge, reset=reset)
  File "/usr/share/myhdl-0.8/lib/python/myhdl/_always_seq.py", line 76, in _always_seq_decorator
    raise AlwaysSeqError(_error.ArgType)
myhdl.AlwaysError: decorated object should be a classic (non-generator) function

My testbench is outlined as follows

from myhdl import *
from random import randrange

HALF_PERIOD = delay(10)   ### This makes a 20-ns clock signal
ACTIVE_HIGH = 1
G_DELAY = delay(15)

def Main():
### Signal declaration
    clk, d, dout = [Signal(intbv(0)) for i in range(3)]
    reset = ResetSignal(1,active=ACTIVE_HIGH,async=True)


### Module Instantiation

    S1 = Sync(dout, d, clk,reset)

### Clk generator

    @always(HALF_PERIOD)
    def ClkGen():
        clk.next = not clk


### TB def
    @instance
    def Driver():
        yield(HALF_PERIOD)
        reset.next = 0
        for i in range(4):
            yield(G_DELAY)
            d.next = not d 
        raise StopSimulation 

    return ClkGen, Driver, S1

m1 = traceSignals(Main)
sim = Simulation(m1)
sim.run()

And my synchronizer is coded as follows.

from myhdl import *
from DFF import *

def Sync(dout,din,clk,reset):

    """ The module consists of two FFs with one internal signal

    External signals 

    dout : output
    din  : input
    clk  : input

    Internal signal:

    F2F : output-to-input signal that connects two FFs together

    """
### Connectivity

    F2F = Signal(intbv(0))

    F1 = DFF(F2F,din,clk,reset)  
    F2 = DFF(dout,F2F,clk,reset)

### Function

    @always_seq(clk.posedge,reset=reset)
    def SyncLogic():
        if reset:
            F2F.next = 0
            dout.next = 0
        else:
        F2F.next = din
        yield(WIRE_DELAY)
        dout.next = F2F
    return SyncLogic

and the FF prototype is coded as follows.

from myhdl import *

def DFF(dout,din,clk,reset):

    @always_seq(clk.posedge, reset=reset)
    def Flogic():
        if reset:
            dout.next = 0
        else:
            dout.next = din
    return Flogic

The testbench did work with the similar testbench I coded earlier(with slight modification), but it didn't work when combining two modules together. Please clarify. Thank you.

To model a wire delay, use the "delay" argument in the Signal.

change

@always_seq(clk.posedge,reset=reset)
def SyncLogic():
    if reset:
        F2F.next = 0
        dout.next = 0
    else:
    F2F.next = din
    yield(WIRE_DELAY)
    dout.next = F2F
return SyncLogic

to:

dout = Signal(<type>, delay=WIRE_DELAY)
# ...
@always_seq(clk.posedge, reset=reset)
def synclogic():
    dout.next = din

With the "always_seq" don't define the reset (it is automatically added). If you want to explicitly define the reset use "@always(clock.posedge, reset.negedge)".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM