[myhdl-list] Re: Cosimulation signal name definitions
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2004-03-10 22:12:13
|
Terry Brown wrote: > From an email conversation, Jan Decaluwe wrote: > > >- Often the signal names in myhdl and Verilog will be the same. You > >can save some typing by letting the Cosimulation class do the lookup > >in some predefined dictionary such as globals() or locals(), e.g.: > > > >cosim = Cosimulation("cver -q > +loadvpi=../myhdl.so:vpi_compat_bootstrap >tb.v matrix3x3.v", **globals()) > > > > > I don't know Python well enough to understand this. I built a > dictionary globals, but the reference to **globals() doesn't work. Is > globals in this case a function that returns a string which is the > contents of the dictionary? You shouldn't define 'globals' (or 'locals'), it's a predefined function that returns the global (or local) namespace as a dictionary. 'globals' refers to a module-level namespace, 'locals' to the namespace inside a function. Here's the background. An issue with cosimulation is that the signals at the Verilog side need to mapped to the other side. MyHDL solves this by using keyword arguments in the Cosimulation constructor. Each keyword refers to a Verilog signal name, and the argument is the MyHDL signal. To support arbitrary Verilog names, the constructor parameter list looks as follows: class Cosimulation(object): def __init__(self, exe="", **kwargs): .... The constructor sets up communication with the Verilog simulator, and receives the names of the participating Verilog signals (regs) from the $from_myhdl and $to_myhdl calls. It looks up each name in the kwargs dictionary to find the matching MyHDL signal. Conversely, it is possible to *call* the constructor using a dictionary instead of a number of keyword arguments, using the ** syntax in the call (this is just a Python feature). Therefore, when you use the same signal names in MyHDL as in Verilog (which is advisable), then you can use the predefined globals() or locals() dictionary in the call and let the Cosimulation constructor find the signals. Regards, Jan -- Jan Decaluwe - Resources bvba - http://jandecaluwe.com Losbergenlaan 16, B-3010 Leuven, Belgium Python is fun, and now you can design hardware with it: http://jandecaluwe.com/Tools/MyHDL/Overview.html |