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

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))
 
datasource(line)
datasink(line)

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.

datasink(datasource)

Also chains are possible

datasink(dataprocessor(datasource))

Examples

Creating a Clock Source
class ClockGenerator(Block):
 
    output = Signal(bool())
 
    def __init__(self,period=2):
        self.period = period
        Block.__init__(self,*args,**kwargs)
 
    @instance
    def clockgen(self):
        while(1):
            yield delay(self.period//2)
            self.output = not self.output
And Gate
class And(Block):
 
    output = Signal(bool())
 
    @always_comb
    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)

Or:

and_gate = And(
               ClockGenerator(period=2),
               ToggleFF()
               )

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(...)
 
    @instance
    def do():
        ...
# See left
def A(in, out):
 
    @instance
    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
b.in  = 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()
 
a.in = b.out
b.in = c.out
...
x.in = y.out
y.in = 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

Simulator

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