Xilinx / PYNQ

Python Productivity for ZYNQ
http://www.pynq.io/
BSD 3-Clause "New" or "Revised" License
1.98k stars 816 forks source link

Exception when an interrupt controller is in a hierarchy #1433

Closed sterin closed 8 months ago

sterin commented 11 months ago

Description

When the interrupt controller is in a hierarchy, any attempt to access a component with an interrupt that goes through the interrupt controller results in a KeyError exception.

For example, in the following block design, the interrupt controller is named Controller, inside a hierarchy called InterruptController.

image

When the following Python code is run:

overlay = pynq.Overlay('regfile.bit')
rf_0 = overlay.RegFile_0

A KeyError exception is thrown:

Traceback (most recent call last):
  File "/home/xilinx/regfile/demo.py", line 5, in <module>
    rf_0 = overlay.RegFile_0
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 363, in __getattr__
    return getattr(self._ip_map, key)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 904, in __getattr__
    driver = ipdescription["driver"](ipdescription)
  File "/home/xilinx/regfile/demo_config.py", line 79, in __init__
    super().__init__(description)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 707, in __init__
    setattr(self, interrupt, Interrupt(details["fullpath"]))
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/interrupt.py", line 65, in __init__
    parent, self.number = _InterruptController.get_parent(
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/interrupt.py", line 152, in get_parent
    return _InterruptController.get_controller(parent), number
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/interrupt.py", line 122, in get_controller
    ret = _InterruptController(name)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/interrupt.py", line 177, in __init__
    PL.interrupt_controllers[name])
KeyError: 'InterruptController/Controller'

Root cause:

As far as I can tell, the root cause of the problem is that PL.interrupt_controllers is indexed by the instance name (e.g. InterruptController_Controller, while the lookup, coming from PL.intrrupt_pins, is done by the hierarchical name (e.g. InterruptController/Controller).

As long as the interrupt controller is in a hierarchy, the instance name and hierarchical name are the same and everything works.

STFleming commented 8 months ago

Solved by #1434