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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2019-06-09 20:26:30 -04:00
parent 97840f9851
commit 700e35c6ac
10 changed files with 24 additions and 42 deletions

View File

@@ -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)
{

View File

@@ -0,0 +1,8 @@
#ifndef __GENERIC_ARMCM_TIMER_H
#define __GENERIC_ARMCM_TIMER_H
#include <stdint.h> // uint32_t
void udelay(uint32_t usecs);
#endif // serial_irq.h