Skip to content

esp32c3 interrupt implementation #2170

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 10 commits into from
Closed

Conversation

zdima
Copy link
Contributor

@zdima zdima commented Oct 12, 2021

@aykevl this is only interrupt implementation for esp32c3.
No exported APIs except enum values of HandlerID type to initialize chip's modules.
Tested with pin src/examples/pininterrupt/pininterrupt.go (not checked in)

the mpie must be set before mret.
remove memory allocation from interrupt code.
Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this PR and how to implement interrupts correctly on the ESP32-C3.
I think it would actually make more sense to make the Interrupt type be the 31 interrupt vectors. It would then work as follows:

  • Code that wants to use an interrupt can do so using interrupt.New, for example interrupt.New(5, func(interrupt.Interrupt) { ... }).
  • It will have to manually map the interrupt source to the interrupt vector, for example esp.INTERRUPT_CORE0.GPIO_INTERRUPT_PRO_MAP.Set(5).
  • The handleInterrupt logic now becomes a lot simpler. It can now directly call callInterruptHandler with the interrupt number from mcause.

It is still possible to map multiple interrupt sources to a single interrupt vector: interrupt.New can be used for multiple handlers on a single interrupt number. For example:

// configuring GPIO:
intr := interrupt.New(5, func(interrupt.Interrupt) {
    status := esp.GPIO.STATUS.Get()
    if status != 0 {
        // handle GPIO interrupt
    }
})
intr.Enable()
esp.INTERRUPT_CORE0.GPIO_INTERRUPT_PRO_MAP.Set(5)

// configuring UART:
intr := interrupt.New(5, func(i interrupt.Interrupt) {
    flag := esp.UART0.INT_ST.Get()
    if flag != 0 {
        // handle UART interrupt
    }
})
intr.Enable()
esp.INTERRUPT_CORE0.UART0_INTERRUPT_PRO_MAP.Set(5)

(These two don't need to be on the same interrupt vector, I'm only showing that it is possible).

What do you think?

@zdima
Copy link
Contributor Author

zdima commented Oct 21, 2021

I didn't know you can call interrupt.New with the same id. I never get response from you on how does it work in the slack PM :(. If I knew, perhaps the implementation will be much simpler.
So how does it work if make a call interrupt.New(5, func(interrupt.Interrupt) {}) twice?

@zdima
Copy link
Contributor Author

zdima commented Oct 21, 2021

@aykevl not sure if you get notification on my comments above

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for all the work!

@aykevl
Copy link
Member

aykevl commented Oct 22, 2021

CI is failing, but I think that's an unrelated issue.

@aykevl
Copy link
Member

aykevl commented Oct 22, 2021

Oh now I see. You have made the PR against the espnet branch. Can you rebase it against the dev branch?

@zdima
Copy link
Contributor Author

zdima commented Oct 22, 2021 via email

@aykevl
Copy link
Member

aykevl commented Oct 23, 2021

I could, but don’t we need other changes you made like stdio, pico lib and FreeRTOS?

Yes, but by merging this in the dev branch it will become available to everybody, not just those working from the espnet branch. That's why I also made a few other PRs like #2135, #2136, and #2143. In general I prefer working as much as possible directly from the dev branch for independent features.
After the PR is merged, it can easily be added to the espnet branch too.

@zdima zdima closed this Oct 23, 2021
@zdima
Copy link
Contributor Author

zdima commented Oct 23, 2021

this is merged with PR #2200

@zdima zdima deleted the espnet-intr branch January 29, 2022 15:49
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants