Timer set

joe_her wrote on Tuesday, July 14, 2015:

I have a simple timer call back which just decrements a variable:

int timerx;
// the callback function:
void vTimerCb1Sec( TimerHandle_t pxTimer )
{
timerx–;
}

Now I need to set timerx:

void set1SecTimer(uint32_t val )
{
xTimerStop(xTimers1Sec,10);
timerx = val;
xTimerStart(xTimers1Sec,10);

}

Is it safe to do it without stop and start like this?

void set1SecTimer(uint32_t val )
{
timerx = val;
}

Thanks,
Johanan

davedoors wrote on Tuesday, July 14, 2015:

Probably not safe just to set timerx, but it can be done in a critical section no need to stop then start the timer.

taskENTER_CRITICAL();
timerx = val;
taskEXIT_CRITICAL();

joe_her wrote on Tuesday, July 14, 2015:

Thanks Dave.