Anybody know of an example of how to handle Pi GPIO IRQs in a C module?
Alan Williams (2601) 88 posts |
I am working on an Econet hat for a pi based on Andrew Gordons RasPi Pico Econet work, and while I have a fair way to go before I have a drop in replacement for the Econet module, its functional to the point of packet exchange with my BBC. At the moment the RISC OS side polls the Pico side over the GPIO but the PRM says I should generate Econet RX and TX events and for that it looks like I need the Pico side to interrupt the RISC OS side. If anybody knows where I might find an example pi gpio irq handling, preferably for a C module that would be very helpful. I am thinking my plan B is to sit on tickerv and just poll the pico irg gpio pin at 100hz. Alan |
Alain Lowet (7745) 41 posts |
Hello Alan, |
Alain Lowet (7745) 41 posts |
Using wiring library, you could do: #define BUTTON_PIN 17 void handleInterrupt(void) { int main(void) { } but of course, it’s using WiringPi library… |
Alain Lowet (7745) 41 posts |
oops, apparently includes are lost in the copy of code: |
Alain Lowet (7745) 41 posts |
#include (wiringPi.h) …. replace parenthesis by minus and greater signs… |
Chris Gransden (337) 1207 posts |
You can use HTML character entities to stop Textile converting them.
becomes #include <stdio.h> |
Rick Murray (539) 13840 posts |
Or wrap the code in a <pre> block to make it readable? Then the angle brackets get converted automatically. |
Steve Pampling (1551) 8170 posts |
Reading material: https://textile-lang.com/ |
Jay Davis (12058) 7 posts |
Using a timer to poll the GPIO pin (your plan B) could work, but interrupt-driven GPIO handling is a more efficient and responsive approach. |
Alan Adams (2486) 1149 posts |
I recently wanted to implement a timer in RISC OS, triggered to start and stop by two different GPIO pins. I discovered that the GPIO module allows setting of the pins to generate interrupts, but doesn’t allow a handler to be added. I ended up polling in tickerV, and for speed stored a counter that was incremented in TickerV every call. As I needed accurate time-of-day I also stored the 5-byte system clock when I started the counter. TickerV also set a pollword to non-zero, and the poll response code read the stored counter, and cleared it (done with interrupts disabled), and added the system clock value. Having run it for 24 hours, the results were about a second different from the stopwatch. As I only need 1/10 second accuracy, over a maximum of 10 minutes, it’s fine. (I have 5 stopwatches, and the difference between them is greater than that.) |
Alan Williams (2601) 88 posts |
Jay: Alan: It seems there are two versions of the GPIO module the current one which converts all its SWI calls to HAL calls and the old one that did all the work in the module and supported beagle boards, DEVKIT8000,and early pies. What I find at the moment is neither the GPIO module or the PI HAL have any code to enable/disable GPIO interrupts. (A) write support for interrupts into the HAL and GPIO module or Since I don’t even know of a single use case for Econet events I will be implementing option C for now. I guess its valuable to know that GPIO IRQS are presently unsupported by the OS. I doubt its hard to DIY, I just haven’t bothered finding the data book on the GPIO registers and their addresses in RISC OS yet. |