3 * Wait for Interrupt test program - ISR method
6 * Use the SoC's pull-up and pull down resistors that are avalable
7 * on input pins. So compile & run this program (via sudo), then
11 * at which point it should trigger an interrupt. Toggle the pin
12 * up/down to generate more interrupts to test.
14 * Copyright (c) 2013 Gordon Henderson.
15 ***********************************************************************
16 * This file is part of wiringPi:
17 * https://projects.drogon.net/raspberry-pi/wiringpi/
19 * wiringPi is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * wiringPi is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
31 ***********************************************************************
41 // What GPIO input are we using?
42 // This is a wiringPi pin number
47 // Global variable to count interrupts
48 // Should be declared volatile to make sure the compiler doesn't cache it.
50 static volatile int globalCounter = 0 ;
55 *********************************************************************************
58 void myInterrupt (void)
65 *********************************************************************************
67 *********************************************************************************
74 if (wiringPiSetup () < 0)
76 fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
80 if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
82 fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
89 printf ("Waiting ... ") ; fflush (stdout) ;
91 while (myCounter == globalCounter)
94 printf (" Done. counter: %5d\n", globalCounter) ;
95 myCounter = globalCounter ;