From 700e35c6ac74a64719fbc38fe66386dd422613f3 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 9 Jun 2019 20:26:30 -0400 Subject: armcm_timer: Unify udelay() implementation Move the udelay() code from various arm board directories into the src/generic/armcm_timer.c code. Signed-off-by: Kevin O'Connor --- src/generic/armcm_timer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/generic/armcm_timer.c') diff --git a/src/generic/armcm_timer.c b/src/generic/armcm_timer.c index a9c8ab9f..7f11cd68 100644 --- a/src/generic/armcm_timer.c +++ b/src/generic/armcm_timer.c @@ -54,6 +54,20 @@ timer_kick(void) SCB->ICSR = SCB_ICSR_PENDSTSET_Msk; } +// Implement simple early-boot delay mechanism +void +udelay(uint32_t usecs) +{ + if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + } + + uint32_t end = timer_read_time() + timer_from_us(usecs); + while (timer_is_before(timer_read_time(), end)) + ; +} + void timer_init(void) { -- cgit v1.2.3-70-g09d2