| MEP: | 104 |
|---|---|
| Author: | Thomas Traber |
| Status: | Draft |
| Created: | June 11, 2008 |
| MyHDL-Version: |
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))
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
class And(Block): output = Signal(bool()) @always_comb def logic(self): self.output = self.a and self.b
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
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()
| 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) |