wzab / agwb

Support for automatic address map generation and address decoding logic for Wishbone connected hierachical systems
12 stars 6 forks source link

Python backend support vor variants #56

Closed wzab closed 3 years ago

wzab commented 3 years ago

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 3 years ago

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.

wzab commented 3 years ago

OK. Variants are working. It is implemented with commit https://github.com/wzab/agwb/commit/9e6e2a48e613269897c58f41fee34d6bb90ca7ad The demo design "test" shows how to use them: https://github.com/wzab/agwb/blob/9e6e2a48e613269897c58f41fee34d6bb90ca7ad/tests/test/python_raw/wb_test.py#L3

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

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)