Hello dle, Looping for prolonged period of time without any thread suspension will eventually cause your thread to be pre-emptied (unless it has the highest priority). It's generally not considered a good programming practice in RTOS environment. I recommend instead creating a helper function and that uses a semaphore to suspend the thread that's later released with a semaphore put from the timer callback. Configuration: GPT in one-shot mode, semaphore g_delay_sema with initial count of zero. Timer has previously been opened in a thread. void sleep_ms (uint32_t ms) { /* Configure the timer for ms */ g_timer_delay.p_api->periodSet(g_timer_delay.p_ctrl, (timer_size_t) ms, TIMER_UNIT_PERIOD_MSEC); /* Start the timer */ g_timer_delay.p_api->start(g_timer_delay.p_ctrl); /* Get semaphore from the callback */ tx_semaphore_get(&g_delay_sema, TX_WAIT_FOREVER); /* Clean up */ g_timer_delay.p_api->reset(g_timer_delay.p_ctrl); } void g_timer_delay_cb(timer_callback_args_t * p_args) { SSP_PARAMETER_NOT_USED(p_args); tx_semaphore_ceiling_put(&g_delay_sema, 1); } I used this function when porting some x86 code to Synergy and it provides accurate delays with 1ms resolution while my SysTick was kept at 10ms. Regards
↧