MyHDL decorator

The decorators that appear in MyHDL have been organized from Reference.

instance() The most common decorator. Create a generator automatically.

def ClkDriver(clk, period=20):
    
    lowTime = int(period/2)
    highTime = period - lowTime

    @instance
    def driveClk():
        while True:
            yield delay(lowTime)
            clk.next = 1
            yield delay(highTime)
            clk.next = 0

    return driveClk

always() A decorator used in a fixed pattern. An example of a circuit that operates at the rising edge of a clock

    @always(clk.posedge)
    def write():
        if we:
            mem[addr].next = din

always_comb() A decorator that describes a combinational circuit.

    @always_comb
    def read():
        dout.next = mem[addr]

always_seq() A decorator that describes a sequential circuit.

def Inc(count, enable, clock, reset):
    @always_seq(clock.posedge, reset=reset)
    def incLogic():
        if enable:
            count.next = count + 1

    return incLogic

Recommended Posts

MyHDL decorator
Decorator 1
Decorator 2
Decorator
Decorator
Note: Python Decorator
Decorator to retry
Python function decorator