1

Im using Raspberry Pi 3 model B. Using wiringPi library.

For ISR I use , wiringPiISR ().

When the interrupt occurs , the interrupt function get executed along with the main(). But I want to pause the main() from executing and do the interrupt function only.

Can anyone help me on this one?

goldilocks
  • 58,859
  • 17
  • 112
  • 227
Sam
  • 81
  • 1
  • 10

2 Answers2

0

Judging by this you need to look at the API a bit differently.

The only way out of having a concurrent thread handle the interrupt is to use a blocking call -- for example, you could poll() the sysfs interface. The wiringPi equivalent of this is presumably waitForInterrupt(). Here's the issue. Either a process:

  1. Is single threaded and must wait for an interrupt to occur via a blocking call, OR

  2. Is multi-threaded and handles interrupts on a dedicated thread concurrently.

The second one is really an elaboration of the first, since the handler thread is waiting on blocking calls in the background. However, this is probably a step closer to what you are looking for since it can be adapted to do things synchronously with locks (or asynchronously with signals) -- although you might have to implement the thread yourself to do that. Again, glancing at that wiringPi page it has "a simplified interface to the Linux implementation of Posix threads" which you could presumably make use of (together with waitForInterrupt()) for this.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
0

If your main has nothing to do just make it a sleep.

e.g.

...

int main(int argc, char *argv[])
{
   ...

   // Initialise and set up the ISR 

   ...

   while (1)
   {
      sleep(1);
   }

   return 0;
}
joan
  • 71,024
  • 5
  • 73
  • 106