Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for interrupts #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

arlucio
Copy link

@arlucio arlucio commented Oct 21, 2020

  • Interrupts are working normally. Only IRQ types IRQ_RISING (2), IRQ_FALLING (3) and IRQ_RISING_FALLING (4) are working, IRQ_HIGH and IRQ_LOW in my tests halts the module and it stops working until reset. Did not test if it is counting the interrupts correctly, but seems right.

  • Also added on() and off() to Pin.

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
Copy link

bokolob commented Oct 24, 2020

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
Copy link

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
Copy link

bokolob commented Dec 27, 2020

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

@marcosasilvalepe
Copy link

marcosasilvalepe commented Jan 4, 2021

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
Copy link

bokolob commented Mar 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants