wzab/agwb

Python backend support vor variants

Closed this issue · 3 comments

wzab commented

Up to now the Python backend always produces the maximum version
It seems reasonable to provide the variants support.
The easiest implementation may be the addition of variant argument to the constructor of the Block class.
It is then used by other objects.
If variant is None, the maximum version is implemented. Otherwise it must be a valid variant number.
Availability of subblocks and registers will be then dependent on the number of the variant.

wzab commented

Regardig handling of variants in Python, I have somehow mixed feelings.
I have a few Micropython-based projects, where the FPGA is connected via SPI
to a microcontroller, running Micropython.
So the WB bus is controlled by the SPI-controlled master, and the memory
footprint of the Python code is significant (I don't want to use any complex
and memory-consuming functions).
Having everything in a single file is a very nice option.
However, there are two reasons to generate separate files instead.

  • For those minimalistic projects the overhead related to handling of variants inside the code is significant
  • I tried to implement passing the variant number and adjusting the presence of fields and/or sizes of vector in the generated code. It seems that it is not easy to do it in a clean way. Therefore we will have separate Python top level files: MAIN.py, MAIN_v0.py, MAIN_v1.py
wzab commented

OK. Variants are working. It is implemented with commit 9e6e2a4
The demo design "test" shows how to use them:

# Use variant 0:

# Use variant 0:
from agwb import MAIN_v0 as MAIN
# Use the maximum version:
from agwb import MAIN
wzab commented

There is yet another (maybe more Pythonic) possibility to import all variants and use in the software:

import importlib
MAIN=[]
for mn in ("MAIN_v0", "MAIN_v1", "MAIN"):
     mx = importlib.import_module("agwb."+ mn)
     MAIN.append(mx)

After that we have the variant 0 as MAIN[0], variant 1 as MAIN[1], and full version as MAIN[-1]
It is perfectly OK to call then:

a=MAIN[variant](iface,base)