Community
cancel
Showing results for 
Search instead for 
Did you mean: 
YLu11
New Contributor I
941 Views

Strange behaviour of Timer Interrupts on Intel Edison

Hi

I found myself facing a strange problem when testing Linux timer interrupts on Intel Edison as suggested in https://madalanarayana.wordpress.com/2014/01/25/create-your-own-timer-routine-in-linux/ Create your own timer routine in Linux | My Linux and Telecom Experiences.

This is my test code:

# include "mraa.h"

# include

# include

# include

# include

# include

# include

using namespace std;

struct itimerval timer;

bool test = false;

void sigalrm_handler(int signum);

struct timespec startTime;

struct timespec endTime;

int main () {

cout<<"started"<<endl;

timer.it_value.tv_sec = 5;

timer.it_value.tv_usec = 0;

timer.it_interval.tv_sec = 5;

timer.it_interval.tv_usec = 0;

struct sigaction act;

memset(&act, '\0', sizeof(act));

act.sa_handler = &sigalrm_handler;

sigaction(SIGTERM, &act, NULL);

setitimer(ITIMER_REAL, &timer, NULL);

while(!test){

cout<<"working..."<<endl;

}

cout<<test<<endl;

}

void sigalrm_handler(int signum){

cout<<"handler executed"<<endl;

test = true;

}

Strangely, this code does not work as the interrupt handler never get executed and the program keeps outputting "working..." in my test. but if you comment out line 31 and have a empty while loop, the timer works perfectly. The same bahaviour happens if I use the deprecated signal() function.

Has anyone else faced this problem before? Did I do something wrong in my code? I tried to search online but all resources that I found seem to suggest that this should work.

Thanks in advance.

Best Regards

lyfkyle

3 Replies
idata
Community Manager
53 Views

Hello lyfkyle,

 

 

I tested your code on the latest version of Edison's image and it seemed to work just fine. If I'm not mistaken the script should start, write working… for five seconds until the interrupt comes and ends the script, am I right? If so, it's working fine for me, which image are you using to test this?

 

 

Peter.
YLu11
New Contributor I
53 Views

Hi Peter,

I just flashed in the latest firmware using the installer version 2016.1.035 and I am still facing the same problem. My code works when I leave the while loop blank but it does not when I add in the cout<<"working..."<<endl. I have also tested with other functions in the while loop, it seems that as long as I am are outputting something to the eclipse console, the timer interrupt will not work. But since I don't have to output anything in my final application, I guess it is fine for me. This problem is a little bit weird though.

Thanks

Lyfkyle

idata
Community Manager
53 Views

Oh, you are using Eclipse to run your code. That might the cause of the issue. As you can see in the screenshot bellow I tested it directly on Linux and if I'm not mistaken, that is the expected behavior:

 

 

 

 

Peter.
Reply