Beginner C question. RTOSTimer confuses me.

01 Dec 2012

Hi all,..

in the RTOS there is a timer that looks like this...

RtosTimer::RtosTimer(void (*periodic_task)(void const *argument), os_timer_type type, void *argument)

I want to use it to call a method that has no argument.

One like this

void adjustPWM()

I can get it to work like this... I've tried many other things, but nothing else works..

void main() {

RtosTimer adjust_timer(adjustPWM, osTimerPeriodic, (void *) NULL);
adjust_timer.start(100);

..waitForever..
}

void adjustPWM(void const *)
{
..adjust PWM on a pin depending on a pot..
}

surely there's a neater way ? without having to pass a null ?, or is this the correct way ?

01 Dec 2012

What you entered there is the same as the arguments default value: it should also work if you skip the third argument. (Just like the second one defaults to osTimerPeriodic if you dont enter anything there).

28 Dec 2012

In other words this should also work:

void main() {
 
RtosTimer adjust_timer(adjustPWM);
adjust_timer.start(100);
 
//..waitForever..
}
 
void adjustPWM(void const *)
{
//..adjust PWM on a pin depending on a pot..
}