Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
Feature request: Argument to interrupt handler
Hi:
Possible to update InterruptIn class to include argument to interrupt handler? Instead of
void rise(void (*fptr)(void));
I propose this
void rise(void (*fptr)(void *arg = NULL), void *arg);
The new rise()
will assign pointer to the function to its internal rise interrupt handler, and also assign the address or arg
into it.
For example,
#include "mbed.h" InterruptIn button(p5); DigitalOut Leds[] = { (LED1), (LED2), (LED3)}; DigitalOut flash(LED4); int i = 0; // LED1 .. LED4 will be lighted up in sequence at each press of the button void flip(void *argv) { int n = (int) *argv; Leds[n] = !leds[n]; n = ++n % 3; (int) (*argv) = n; } int main() { button.rise(&flip, &i); while(1) { // wait around, interrupts will interrupt this! flash = !flash; wait(0.25); } }
Suggestion?
Question relating to:
2 Answers
11 years, 4 months ago.
I think it again, when an interrupt is trigger, no one is there to pass argument to a generic interrupt handler.
In other words, each interrupt handler has to be created for each InterruptIn
object if it is intended to do different actions.
errored program
posted by siddhartha A R 24 Jul 2017