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

Low latency (direct) interrupt handlers #1394

Merged
merged 12 commits into from
Dec 13, 2017

Conversation

avtolstoy
Copy link
Member

@avtolstoy avtolstoy commented Sep 25, 2017

submission notes
**Important:** Please sanitize/remove any confidential info like usernames, passwords, org names, product names/ids, access tokens, client ids/secrets, or anything else you don't wish to share.

Please Read and Sign the Contributor License Agreement ([Info here](https://github.com/spark/firmware/blob/develop/CONTRIBUTING.md)).

You may also delete this submission notes header if you'd like. Thank you for contributing!

Problem

See #1168 #1333

Solution

This PR adds two wiring functions attachInterruptDirect() and detachInterruptDirect() that allow the user code to directly insert interrupt handlers into the interrupt vector table.

Steps to Test

  • wiring/no_fixture: INTERRUPTS_04_attachInterruptDirect

Example App

void pvd_irqn_handler() {
    // Do something
}

void setup() {
    attachInterruptDirect(PVD_IRQn, pvd_irqn_handler);
}

void loop() {

}

References

  • Closes #1168
  • Closes #1333
  • [CH7827]

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • TODO: Add documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@pkourany
Copy link
Contributor

Reminder to review!

@m-mcgowan
Copy link
Contributor

Are you psychic...I was literally reviewing this when you commented!

@pkourany
Copy link
Contributor

pkourany commented Nov 9, 2017

I'll try and test with SparkIntervalTimer and a scope. This is an important one to release as soon as its ready IMO.

@pkourany
Copy link
Contributor

I tried this feature branch with my SparkIntervalTimer library coupled with my RGBPongClock and I get a hard fault. I will test with a more basic app (blink LED) along with the SparkIntervalTimer library next.

@pkourany
Copy link
Contributor

I tried a simple app with SparkIntervalTimer (using attachInterruptDirect()) and I get hard fault immediately after flashing over the code. If I compile with regular attachInterrupt() the code works fine.

To test, I simply change the original code using attachInterrupt() such as this line:
attachSystemInterrupt(SysInterrupt_TIM3_Update, Wiring_TIM3_Interrupt_Handler_override)
to:
attachInterruptDirect(TIM3_IRQn, Wiring_TIM3_Interrupt_Handler_override)

@avtolstoy
Copy link
Member Author

avtolstoy commented Nov 15, 2017

@pkourany I've just built SparkIntervalTimer with minimal changes:

        if (!attachInterruptDirect(TIM3_IRQn, Wiring_TIM3_Interrupt_Handler_override)) ; //error
        if (!attachInterruptDirect(TIM4_IRQn, Wiring_TIM4_Interrupt_Handler_override)) ; //error
        if (!attachInterruptDirect(TIM5_IRQn, Wiring_TIM5_Interrupt_Handler_override)) ; //error
        if (!attachInterruptDirect(TIM6_DAC_IRQn, Wiring_TIM6_Interrupt_Handler_override));  //error
        if (!attachInterruptDirect(TIM7_IRQn, Wiring_TIM7_Interrupt_Handler_override));  //error

and used the example provided with it, and it does not crash. Don't have a scope at hand, but at the very least D7 is flashing as intended.

EDIT:
Tested on both Electron and Photon.

@pkourany
Copy link
Contributor

@avtolstoy, as I read your post I realized that with all my testing, I failed to update the system firmware parts! I'll test again just to confirm. Thanks!

@pkourany
Copy link
Contributor

@avtolstoy, I must be missing something. I checked out the branch, go to the firmware/modules directory and build/flash the system firmware and app using:

make clean all PLATFORM=photon APP=rgbpcFastInt program-dfu

Everything compiles and flashes but same hard fault. What am I missing?

@pkourany
Copy link
Contributor

Tested with SparkIntervalTimer (with some overdue mods) and it works. Good to go!

Copy link
Contributor

@pkourany pkourany left a comment

Choose a reason for hiding this comment

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

Tested successfully with SparkIntervalTimer library.

@m-mcgowan
Copy link
Contributor

Paul, what was the cause of the hard fault? Anything we need to look into?

@m-mcgowan m-mcgowan added this to the 0.8.0-rc.1 milestone Nov 24, 2017
@m-mcgowan m-mcgowan self-requested a review December 13, 2017 14:06
@m-mcgowan m-mcgowan merged commit dc24e0c into develop Dec 13, 2017
@m-mcgowan
Copy link
Contributor

m-mcgowan commented Dec 13, 2017

Who's going to write up the docs for this? We need to make clear the interplay between the normal wiring interrupts and the direct interrupts, and provide guidance on when to use which.

@ScruffR
Copy link
Contributor

ScruffR commented Mar 21, 2018

Will there be a version of attachInterruptDirect() that also allows to provide a priority parameter as attachInterrupt() already does?

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