Generating a timer interrupt using C++

1,545 views
Skip to first unread message

arunbarn...@gmail.com

unread,
Aug 31, 2013, 2:21:12 AM8/31/13
to beagl...@googlegroups.com
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

Roy Bellingan

unread,
Aug 31, 2013, 1:00:18 PM8/31/13
to beagl...@googlegroups.com
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

William Hermans

unread,
Aug 31, 2013, 1:17:05 PM8/31/13
to beagl...@googlegroups.com
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 . ..




On Sat, Aug 31, 2013 at 10:00 AM, Roy Bellingan <tsm...@gmail.com> wrote:
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


--
For more options, visit http://beagleboard.org/discuss
--- You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Roy Bellingan

unread,
Aug 31, 2013, 1:29:20 PM8/31/13
to beagl...@googlegroups.com
Il 31/08/2013 19:17, William Hermans ha scritto:
> 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.

William Hermans

unread,
Aug 31, 2013, 1:41:55 PM8/31/13
to beagl...@googlegroups.com
#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;
}



meerutmicr...@gmail.com

unread,
Aug 31, 2013, 2:15:08 PM8/31/13
to beagl...@googlegroups.com
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

William Hermans

unread,
Aug 31, 2013, 4:28:10 PM8/31/13
to beagl...@googlegroups.com
ualarm() -> http://linux.die.net/man/3/ualarm.

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


--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages