Minimal simple Interrupt handling with UIO device in Pynq

The UioController class bridges the asyncio and UIO worlds and works by waiting on the UIO file and setting asyncio events when an interrupt is received.

controller = UioController("/dev/uio0")
event = asyncio.Event()
async def interrupt_test():
   while True:
       event.clear()
       controller.add_event(event, 0) # Number is a dummy variable
       await event
       print("Interrupt Triggered")

loop = asyncio.get_event_loop()
loop.run_until_complete(interrupt_test())

This should print the message each time that the interrupt is triggered. You can create other asyncio coroutines to generate the interrupts if you want to test everything in process. If you’re using a GPIO controller to driver the interrupt line then something along the lines of:

async def drive_interrupts():
    while True:
         gpio.write(0, 0x1)
         gpio.write(0, 0x0)
         await asyncio.sleep(1)

driver_task = asyncio.ensure_future(drive_interrupts())

In a full program, you should ensure that the interrupt line is cleared before calling add_event otherwise you might end up with interrupts being duplicated.

Hope this makes some kind of sense - the underlying asyncio code can be fairly messy which is why we tried to abstract as much as possible of this away with the Interrupt class. That assumes a tree structure of AXI interrupts controllers connected to interrupt line 0 and a UIO device with the name “fabric”.

Peter

3 Likes