3 * Wait for Interrupt test program - ISR method - interrupt oscillator
7 * IMPORTANT: To run this test we connect 2 GPIO pins together, but
8 * before we do that YOU must make sure that they are both setup
9 * the right way. If they are set to outputs and one is high and one low,
10 * then you connect the wire, you'll create a short and that won't be good.
12 * Before making the connection, type:
16 * then you can connect them together.
18 * Run the program, then:
22 * at which point it will trigger an interrupt and the program will
23 * then do the up/down toggling for itself and run at full speed, and
24 * it will report the number of interrupts recieved every second.
26 * Copyright (c) 2013 Gordon Henderson. projects@drogon.net
27 ***********************************************************************
28 * This file is part of wiringPi:
29 * https://projects.drogon.net/raspberry-pi/wiringpi/
31 * wiringPi is free software: you can redistribute it and/or modify
32 * it under the terms of the GNU Lesser General Public License as published by
33 * the Free Software Foundation, either version 3 of the License, or
34 * (at your option) any later version.
36 * wiringPi is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU Lesser General Public License for more details.
41 * You should have received a copy of the GNU Lesser General Public License
42 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
43 ***********************************************************************
53 // What GPIO input are we using?
54 // This is a wiringPi pin number
60 // Global variable to count interrupts
61 // Should be declared volatile to make sure the compiler doesn't cache it.
63 static volatile int globalCounter = 0 ;
67 *********************************************************************************
70 void myInterrupt (void)
72 digitalWrite (OUT_PIN, 1) ;
74 digitalWrite (OUT_PIN, 0) ;
79 *********************************************************************************
81 *********************************************************************************
89 if (wiringPiSetup () < 0)
91 fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
95 pinMode (OUT_PIN, OUTPUT) ;
96 pinMode (IN_PIN, INPUT) ;
98 if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
100 fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
106 printf ("Waiting ... ") ; fflush (stdout) ;
108 while (myCounter == globalCounter)
111 printf (" Done. counter: %6d: %6d\n",
112 globalCounter, myCounter - lastCounter) ;
113 lastCounter = myCounter ;
114 myCounter = globalCounter ;