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 ***********************************************************************
42 // Global variable to count interrupts
43 // Should be declared volatile to make sure the compiler doesn't cache it.
45 static volatile int globalCounter [8] ;
50 *********************************************************************************
53 void myInterrupt0 (void) { ++globalCounter [0] ; }
54 void myInterrupt1 (void) { ++globalCounter [1] ; }
55 void myInterrupt2 (void) { ++globalCounter [2] ; }
56 void myInterrupt3 (void) { ++globalCounter [3] ; }
57 void myInterrupt4 (void) { ++globalCounter [4] ; }
58 void myInterrupt5 (void) { ++globalCounter [5] ; }
59 void myInterrupt6 (void) { ++globalCounter [6] ; }
60 void myInterrupt7 (void) { ++globalCounter [7] ; }
64 *********************************************************************************
66 *********************************************************************************
74 for (pin = 0 ; pin < 8 ; ++pin)
75 globalCounter [pin] = myCounter [pin] = 0 ;
79 wiringPiISR (0, INT_EDGE_FALLING, &myInterrupt0) ;
80 wiringPiISR (1, INT_EDGE_FALLING, &myInterrupt1) ;
81 wiringPiISR (2, INT_EDGE_FALLING, &myInterrupt2) ;
82 wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ;
83 wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ;
84 wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt5) ;
85 wiringPiISR (6, INT_EDGE_FALLING, &myInterrupt6) ;
86 wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt7) ;
91 printf ("Waiting ... ") ; fflush (stdout) ;
95 for (pin = 0 ; pin < 8 ; ++pin)
97 if (globalCounter [pin] != myCounter [pin])
99 printf (" Int on pin %d: Counter: %5d\n", pin, globalCounter [pin]) ;
100 myCounter [pin] = globalCounter [pin] ;