the example is nice, but it does not tell you how to safely manage resources, that you feed into the interrupt function via the void* args parameter. If you only use static resources, everything will be fine. But if you use dynamically allocated resources in your interrupt function, there is no safe way to deallocate the resource, since you don't know if the interrupt function is still using the resource.
By calling mraa_gpio_close will not cancel the interrupt handling thread. By doing this, the gpio file will be closed and the interrupt handler thread will terminate the next time it tries to poll the interrupts. When this will happen, depends on your interrupt function. If you deallocate your resources immediately after calling mraa_gpio_close, the interrupt function may still use the deallocated memory.
But there is another option. You can call mraa_gpio_isr_exit, which tries to cancel the thread immediately. The problem is that this function also does not guarantee that the thread is canceled after the call. If your interrupt function is being executed, the thread will continue to run until your function exits, because thread cancellation is disabled as long as the interrupt function is being executed. So you can not safely deallocate your resources after calling mraa_gpio_isr_exit.
Currently you will have to wait some time after mraa_gpio_close or mraa_gpio_isr_exit and hope that your interrupt function will be finished after the given time span.
I'm new to Intel Edison development and just a bit of prior Arduino knowledge behind so please bare with me
I am trying to port some Arduino code and an implementation of the DMX protocol, but I think I need to
find equivalent Quark calls for the existing AVR code.
Here are the functions/constants I will need to replicate on Intel Edison:
- cli() / noInterrupts()
- sei() / interrupts()
- NOT_A_PORT / PORTB / PORTC / PORTD
From what I understand in this post, interrupts()/noInterrupts() can be achieved with libmraa.
Would I use that in plain c on the linux side or from the Arduino IDE ?
I found digitalPinToBitMask() in hardware/arduino/edison/cores/arduino/wiring_digital.h but I get an error when I try to use it:
has no member named
#define digitalPinToBitMask(P) ( g_APinDescription[P].ulPin )
I've also found this GPIO reference I'm going through at the moment:
Is it feasible to port the DMX code to the IntelEdison ? Where could I find the AVR equivalent calls/constants for Edison ?
would you mind copy&pasting this feature request to https://communities.intel.com/community/makers/? The forum you posted here is mostly around Intel IoT developer kit but not about Arduino IDE which isn't part of the devkit.
On questions on how to bring it to C/C++/Python or Node.JS using the devkit feel free to continue on this forum.
Thank you for the advice. I will ask on the Makers community as well.
If I can get the code running in Arduino that would be great,
but I'm not excluding porting the code to c or python using libmraa
in which case the questions on finding equivalents for the AVR
constants and functions within libmraa remain.
Would you consider it's possible to do this sort of port manipulation with libmraa ?
If so, how can I continue ?