From dac9fdf6e81124be65b857f749438e63306e0a95 Mon Sep 17 00:00:00 2001 From: Kelvin Lawson Date: Sun, 17 Nov 2013 21:49:02 +0000 Subject: [PATCH] dm36x: Add usec timer measurement functions. --- ports/arm/atomport.h | 2 ++ ports/arm/platforms/dm36x/timer.c | 45 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ports/arm/atomport.h b/ports/arm/atomport.h index ac2d82b..6198a19 100644 --- a/ports/arm/atomport.h +++ b/ports/arm/atomport.h @@ -55,6 +55,8 @@ extern void archUsleep (int32_t microsecs); extern int32_t archUsleepStart (void); extern int archUsleepCheckExpired (int32_t start_time, int32_t delay_usecs); +extern int32_t archUsecStart (void); +extern int32_t archUsecDiff (int32_t start_time); /** * ISR handler registration (optional, not available on all ports) diff --git a/ports/arm/platforms/dm36x/timer.c b/ports/arm/platforms/dm36x/timer.c index 2bf09df..d45583b 100644 --- a/ports/arm/platforms/dm36x/timer.c +++ b/ports/arm/platforms/dm36x/timer.c @@ -135,7 +135,7 @@ void archUsleep (int32_t microsecs) /** * \b archUsleepStart * - * Start a usec timer session. + * Start a usleep timer session. * * @retval Start time for use in subsequent archUsleepCheckExpired() calls * @@ -156,7 +156,7 @@ int32_t archUsleepStart (void) /** * \b archUsleepCheckExpired * - * Test whether a usec timer session has expired. + * Test whether a usleep 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 @@ -176,3 +176,44 @@ int archUsleepCheckExpired (int32_t start_time, int32_t delay_usecs) status = (((int32_t)TIMER_REG(DM36X_TIMER_TIM12) - start_time) < delay_timer_ticks) ? 0 : 1; return (status); } + + +/** + * \b archUsecStart + * + * Start a usec timer session for use with archUsecDiff() layer. + * + * @retval Start time for use in subsequent archUsecDiff() calls + * + */ +int32_t archUsecStart (void) +{ + /* Check we are initialised */ + if (initialised == FALSE) + { + timer_init(); + } + + /* Return the current 24MHz count */ + return (TIMER_REG(DM36X_TIMER_TIM12)); +} + + +/** + * \b archUsecDiff + * + * Calculate the usecs that have expired since the passed "start_time". + * + * The 24MHz timer rolls over every 178 seconds. The use of a signed + * integer means that this cannot be used to measure periods over 89 seconds. + * + * @param[in] start_time Beginning of time difference session (returned by archUsecStart()) + * + * @retval Number of microseconds expired since start_time + * + */ +int32_t archUsecDiff (int32_t start_time) +{ + /* Translate diff in 24MHz ticks to usecs */ + return (((int32_t)TIMER_REG(DM36X_TIMER_TIM12) - start_time) / (TIMER_CLK / 1000000)); +}