Part Number: CC2652R7
Hello,
I was trying to run a one-shot timer multiple times. What I did was start the timer and stopped it mid way and then reran it. On the second run it doesn't complete the full period but starts off where it was stopped. I created a test below that shows this functionality. I am using a CC2652R7 board with the SDK : 7_10_01_24. I presume the internal timer count isn't being reset until the count reaches the period.
Regards,
Kenneth Thomas
sem_t timer_sem;
void timerCallback(Timer_Handle handle, int_fast16_t status)
{
sem_post(&timer_sem);
}
void testTimer()
{
sem_init(&timer_sem, 0, 0);
// Configure Timer parameters for one-shot callback after one second
Timer_Handle timer;
Timer_Params timer_params;
Timer_Params_init(&timer_params);
timer_params.periodUnits = Timer_PERIOD_US;
timer_params.period = 1000000;
timer_params.timerCallback = timerCallback;
timer_params.timerMode = Timer_ONESHOT_CALLBACK;
// Start/stop timer before it can finish
bool stop_early_and_restart = true;
if (stop_early_and_restart)
{
timer = Timer_open(CONFIG_TIMER_3, &timer_params);
Timer_start(timer);
usleep(500000);
Timer_stop(timer);
Timer_close(timer);
}
// Restart timer but let it finish
timer = Timer_open(CONFIG_TIMER_3, &timer_params);
uint32_t start_ticks = ClockP_getSystemTicks();
Timer_start(timer);
sem_wait(&timer_sem);
uint32_t stop_ticks = ClockP_getSystemTicks();
Timer_stop(timer);
Timer_close(timer);
printf("[TIMER] Elapsed time = %d msec", ((stop_ticks - start_ticks) * ClockP_getSystemTickPeriod()) / 1000);
sem_destroy(&timer_sem);
}

