timer: arm: implement arch_busy_wait

To take the usage of arm arch counter 64bit capability, implement
custom arch_busy_wait

Signed-off-by: Peng Fan <peng.fan@nxp.com>
This commit is contained in:
Peng Fan 2020-11-09 15:49:21 +08:00 committed by Anas Nashif
parent 5c1c5bbb5e
commit e6392301f8
2 changed files with 23 additions and 0 deletions

View file

@ -82,6 +82,7 @@ config ARCV2_TIMER_IRQ_PRIORITY
config ARM_ARCH_TIMER
bool "ARM architected timer"
depends on GIC
select ARCH_HAS_CUSTOM_BUSY_WAIT
select TICKLESS_CAPABLE
help
This module implements a kernel device driver for the ARM architected

View file

@ -113,3 +113,25 @@ uint32_t z_timer_cycle_get_32(void)
{
return (uint32_t)arm_arch_timer_count();
}
#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT
void arch_busy_wait(uint32_t usec_to_wait)
{
if (usec_to_wait == 0) {
return;
}
uint64_t start_cycles = arm_arch_timer_count();
uint64_t cycles_to_wait = sys_clock_hw_cycles_per_sec() / USEC_PER_SEC * usec_to_wait;
for (;;) {
uint64_t current_cycles = arm_arch_timer_count();
/* this handles the rollover on an unsigned 32-bit value */
if ((current_cycles - start_cycles) >= cycles_to_wait) {
break;
}
}
}
#endif