From Python to silicon
MEP: 104
Author: Thomas Traber
Status: Draft
Created: June 11, 2008

Get rid of the Signal

Often Signals as seperate entities are not needed.

Assume we have a functional block datasource and a block datasink.

line = Signal(bool(0))

In classic myhdl you don't know about the signal direction without inspecting the source codes of datassource and datasink. In more complex designs it is also difficult to follow the signal path itself.

The following is an object oriented approach which avoids the signal definition in the top level code.

datasink.input = datasource.output

In case of only one output of the source block the syntax will be even simpler.


Also chains are possible



Creating a Clock Source
class ClockGenerator(Block):
    output = Signal(bool())
    def __init__(self,period=2):
        self.period = period
    def clockgen(self):
            yield delay(self.period//2)
            self.output = not self.output
And Gate
class And(Block):
    output = Signal(bool())
    def logic(self):
        self.output = self.a and self.b
Toggle Flip Flop
class ToggleFF(Block):
    q = Signal(bool(0))
    output = q
                           # Input a is not defined at the time we are instantiating the class. 
    @always("a.posedge")   # Therefore we use the string.
    def toggleff(self):
        self.q = not self.q
Connecting the Blocks
clockgen = ClockGenerator(2)
tff = ToggleFF()
and_gate = And(clockgen, tff)


and_gate = And(

Or even:

and_gate = ClockGenerator(period=2) & ToggleFF()

Comparison of Classic MyHDL to Proposed Extension

Feature Extended Syntax - formal Extended Syntax - simple Classical Syntax
Definition of Functional Blocks
class A(Block):
    out = Signal(...)
    def do():
# See left
def A(in, out):
    def do():
    return do()
Instantiation of Functional Blocks
a = A()
b = B()
a = A()
b = B(a)
a = A(com)
b = B(com)           
Connecting Ports  = a.out
b = B(a)   # see above
com = Signal(...)
a = A(com)
b = B(com)
Top Level Design
from lib import A,B,..,Z
a = A()
b = B()
y = Y()
z = Z() = b.out = c.out
... = y.out = z.out
from lib import A,B,..,Z
a = A(B(C(..(Y(Z()))..)))
from lib import A,B,...Z
com_a = Signal(..)
com_b = Signal(..)
com_y = Signal(..)
com_z = Signal(..)
a = A(com_a)
b = B(com_a,com_b)
y = Y(com_x, com_y)
z = Z(com_y, com_z)

Advantages of Extended Syntax

  • No signal definition neccessary in top level design
  • Every signal of the functional subblock can be accessed from top level without source code modification of the subblock

Experimental Implementation

Basic Block Object


meps/mep-104.txt · Last modified: 2008/07/10 07:23 by thomastraber
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki