Generating a timer interrupt using C++

Hi,

I am not sure if this a BBB related question or a C++ one, so please excuse the mistake.

I would like to generate an event say every 100 milliseconds. Is this possible with C++ using BBB.

I am using BBB with Angstrom, and cross-compiling on C++, using Eclipse . I have searched for timer events in the internet, but many of them have code explanations for windows, using windows APIs, others make the use of a RTC, but since the BBB does not have a RTC, I am not sure how this can be done.

Are there timers in BBB, that can be used for this purpose ?? Most micro-controllers have them, is there any way of accessing these timers via C++ in Linux ??

Any small hints/pointers would be useful…

thanks
a

sleep or usleep, if you are in the range of > 10ms you have pretty good accuracy (and the CPU load is <90%).

http://www.gnu.org/software/libc/manual/html_node/Sleeping.html

About usleep →

OK so first let me say that I am new to linux development . …

usleep() never seems to let the processor scale up in frequency. So if software on the BBB is starting the AM335x off at 300Mhz while idle or with a light load, the CPU will scale up to 1Ghz by the time the processor hits around ~60% processor load. using usleep() however, I’ve hit as high as 95%-98% processor load, and the CPU frequency would still be at 300Mhz.

I’ve posted the code I ran on these groups before, which was a very simple load testing app.

Anyhow, just thought I would mention that so the OP would be aware . …

Can you reshare the code give a link ?
I'll give an eye.

#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
unsigned int index = 0;
unsigned int mSeconds = 500;
int returnCode;

while(1)
{
if((++index % 10240) == 0 ){
returnCode = usleep(mSeconds);
index = 0;
}
}

return 0;
}

Link is here → https://groups.google.com/forum/#!searchin/beagleboard/usleep()$20william/beagleboard/SwAJB4jUXTs/vd1ELitwVisJ

but usleep locks the cpu right ??

I am trying to implement a timer event that generates a timer event say every 2 or 10 msec.

For example: I have a program that waits for data to arrive on a UART port on the BBB, if the sender does not send the data within 100 msec, the program does some action like generate an error. The program must also perform other tasks like monitoring the UART port.

thanks
a

ualarm() → http://linux.die.net/man/3/ualarm.

There are also more potential alternatives on that page under “see also”. . .