Hi All,
Is there anything special to getting the handler for SIGALRM working in the (default PREEMPT) Wheezy distro?
I've followed the examples I've found to a tee (I *think*) and from all indications it seems that the handler is not 'firing' so I'm not sure if the alarm is not being raised or the hander is faulty.
I've tried two methods: 'timer' and via the alarm() function call.
Any tips appreciated, example code follows:
#include #include #include #include #include #include
#define LED_R 7
void blinkRed(int); void timerSetup(long int, long int); void sig_hdlr(int);
volatile sig_atomic_t toggle_flag = false;
int main(void) { wiringPiSetupGpio();
printf("GPIO Setup\n"); pinMode(LED_R, OUTPUT);
signal(SIGALRM, sig_hdlr);
alarm(1); // timerSetup(0, 500000);
for(;;) {
if(toggle_flag) { blinkRed(); printf("Something's happening!\n"); toggle_flag = false; alarm(1); }
return 0; }
void timerSetup(long int sec, long int usec) { struct itimerval timer1;
timer1.it_interval.tv_usec = usec; timer1.it_interval.tv_sec = sec; timer1.it_value.tv_usec = usec; timer1.it_value.tv_sec = sec;
setitimer(ITIMER_REAL, &timer1, NULL); }
void sig_hdlr(int sig) { toggle_flag = true; }
void blinkRed(void) { static int toggle = 0;
if(toggle == 1) { digitalWrite(LED_R, HIGH); toggle = 0; } else { digitalWrite(LED_R, LOW); toggle = 1; } }