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

RP2040 interrupt example #1

Open
wants to merge 2 commits into
base: rp2040-interrupts
Choose a base branch
from

Conversation

ysoldak
Copy link

@ysoldak ysoldak commented Nov 5, 2021

Hey, I've tested interrupt API.
It works!

Here is how I've changed default "pininterrupt" example to test with RP2040.
Thought you probably want to have this in your PR for completeness.

Note: mentioned "debouncing" was intentionally left out to avoid risk of merge delays caused by it.

@soypat soypat force-pushed the rp2040-interrupts branch from 6ace5d7 to 7bc7a42 Compare November 8, 2021 17:05
soypat pushed a commit that referenced this pull request Nov 9, 2021
Instead of doing everything in the interrupt lowering pass, generate
some more code in gen-device to declare interrupt handler functions and
do some work in the compiler so that interrupt lowering becomes a lot
simpler.

This has several benefits:

  - Overall code is smaller, in particular the interrupt lowering pass.
  - The code should be a bit less "magical" and instead a bit easier to
    read. In particular, instead of having a magic
    runtime.callInterruptHandler (that is fully written by the interrupt
    lowering pass), the runtime calls a generated function like
    device/sifive.InterruptHandler where this switch already exists in
    code.
  - Debug information is improved. This can be helpful during actual
    debugging but is also useful for other uses of DWARF debug
    information.

For an example on debug information improvement, this is what a
backtrace might look like before this commit:

    Breakpoint 1, 0x00000b46 in UART0_IRQHandler ()
    (gdb) bt
    #0  0x00000b46 in UART0_IRQHandler ()
    #1  <signal handler called>
    [..etc]

Notice that the debugger doesn't see the source code location where it
has stopped.

After this commit, breaking at the same line might look like this:

    Breakpoint 1, (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200
    200			uart.Receive(byte(nrf.UART0.RXD.Get()))
    (gdb) bt
    #0  (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200
    #1  UART0_IRQHandler () at /home/ayke/src/github.com/tinygo-org/tinygo/src/device/nrf/nrf51.go:176
    tinygo-org#2  <signal handler called>
    [..etc]

By now, the debugger sees an actual source location for UART0_IRQHandler
(in the generated file) and an inlined function.
@soypat
Copy link
Owner

soypat commented Nov 17, 2021

Whoops, totally missed this PR
I believe you already PRed this one though recently to tinygo/tinygo, right?

@ysoldak
Copy link
Author

ysoldak commented Nov 17, 2021

No, I that was different. It was about debounce.
tinygo-org#2233

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.

2 participants