pulkin / micropython

MicroPython implementation on Ai-Thinker GPRS module A9 (RDA8955)
https://micropython.org
MIT License
102 stars 30 forks source link

Add support for interrupts #94

Open arlucio opened 3 years ago

arlucio commented 3 years ago

I didn't added an code example because I didn't really understood how the numbering there works. But could be as follow:

from machine import Pin
from utime import sleep_ms

def callback(self):
    global irq_count
    irq_count = irq_count + 1

def callback_arg(n):
    global irq_count
    irq_count = irq_count + 1
    print(n + irq_count)

irq_count = 0
pirq = Pin(2, Pin.INT, Pin.PULL_UP)
irq = pirq.irq(trigger=Pin.IRQ_FALLING, handler=callback, debounce=200)
# irq = pirq.irq(trigger=3, handler=callback_arg, debounce=50, handler_arg=n)

while True:
    print(irq_count)
    sleep_ms(2000)
bokolob commented 3 years ago

I think that there is a possible deadlock. mp_sched_schedule enters SYS_EnterCriticalSection internally. And if you try to reenter there from the interrupt handler it will hang up the board.

So, interrupts have to be disabled when code enters critical section (as in other ports). I will try to investigate SYS_EnterCriticalSection behavior with ghidra :-) or you should make some experiments.

marcosasilvalepe commented 3 years ago

Hi! Are there any news regarding if IRQ_HIGH and IRQ_LOW might be available anytime soon??

It would be great to be able to use them on the A9G.

bokolob commented 3 years ago

I'm going to look at interrupts in February :)

marcosasilvalepe commented 3 years ago

That would be great! Interrupts are awesome and it would be great to be able to use them on the A9G.

I've been trying to compile @arlucio micropython with interrupts version but I keep getting an error when doing make.

I did make -C mpy-cross in the main directory and then make in ports/gprs_a9g and tried with Ubuntu and Parrot OS (both updated) but I keep getting the following error:

machine_pin.c:436: error: ‘machine_pin_irq_locals_dict’ undeclared here (not in a function)
make: *** [../../py/mkrules.mk:63: build/machine_pin.o] Error 1

Is there something I'm doing wrong ?

bokolob commented 3 years ago

I've fixed that issue in my fork https://github.com/bokolob/micropython/tree/interrupts