-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Functional Interrupts #2745
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
Functional Interrupts #2745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <FunctionalInterrupt.h> | ||
|
||
|
||
// Duplicate typedefs from core_esp8266_wiring_digital_c | ||
typedef void (*voidFuncPtr)(void); | ||
|
||
// Helper functions for Functional interrupt routines | ||
extern "C" void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFunc, void*fp , int mode); | ||
|
||
// Structure for communication | ||
struct ArgStructure { | ||
std::function<void(void)> reqFunction; | ||
}; | ||
|
||
void interruptFunctional(void* arg) | ||
{ | ||
((ArgStructure*)arg)->reqFunction(); | ||
} | ||
|
||
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @igrr what about here? should this be std::function<void ICACHE_RAM_ATTR (void)> ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more tricky. You can't add attributes to function prototypes like that, and furthermore the invoke method of std::function (which gets called when you use operator() on the function object) is not placed into IRAM either (it's a part of libstdc++). I think the only way to work around this issue is to implement interrupt masking for the duration of SPI flash operation (#3579), then IRAM_ATTRs will not be needed at all. |
||
{ | ||
// use the local interrupt routine which takes the ArgStructure as argument | ||
__attachInterruptArg (pin, (voidFuncPtr)interruptFunctional, new ArgStructure{intRoutine}, mode); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef FUNCTIONALINTERRUPT_H | ||
#define FUNCTIONALINTERRUPT_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <functional> | ||
|
||
extern "C" { | ||
#include "c_types.h" | ||
#include "ets_sys.h" | ||
} | ||
|
||
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode); | ||
|
||
#endif //INTERRUPTS_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igrr it's a bit late, but shouldn't this have the ICACHE_RAM_ATTR tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, under the current model it should have ICACHE_RAM_ATTR.