DM36x: Add microsecond accuracy timer.

This commit is contained in:
Kelvin Lawson
2013-10-19 01:40:22 +01:00
parent aba6c6f5fd
commit ebffc439a0
2 changed files with 49 additions and 2 deletions

View File

@@ -52,7 +52,9 @@
/**
* Hardware timer functions (optional, not available on all ports)
*/
void archUsleep (int32_t microsecs);
extern void archUsleep (int32_t microsecs);
extern int32_t archUsleepStart (void);
extern int archUsleepCheckExpired (int32_t start_time, int32_t delay_usecs);
/**
*

View File

@@ -129,5 +129,50 @@ void archUsleep (int32_t microsecs)
/* Wait in a spin-loop for timer to expire */
while (((int32_t)TIMER_REG(DM36X_TIMER_TIM12) - start_time) < delay_timer_ticks)
;
}
/**
* \b archUsleepStart
*
* Start a usec timer session.
*
* @retval Start time for use in subsequent archUsleepCheckExpired() calls
*
*/
int32_t archUsleepStart (void)
{
/* Check we are initialised */
if (initialised == FALSE)
{
timer_init();
}
/* Return the current 24MHz count */
return (TIMER_REG(DM36X_TIMER_TIM12));
}
/**
* \b archUsleepCheckExpired
*
* Test whether a usec timer session has expired.
*
* @param[in] start_time Beginning of timer expiry check session (returned by archUsleepStart())
* @param[in] delay_usecs Number of microsecs to check have expired after start_timE
*
* @retval 1=Timer expired, 0=Not expired
*
*/
int archUsleepCheckExpired (int32_t start_time, int32_t delay_usecs)
{
int32_t delay_timer_ticks;
int status;
/* Translate delay in usecs to delay in 24MHz ticks */
delay_timer_ticks = ((TIMER_CLK / 1000000) * delay_usecs);
/* Check if timer has expired */
status = (((int32_t)TIMER_REG(DM36X_TIMER_TIM12) - start_time) < delay_timer_ticks);
return (status);
}