From fe4e3f4529b361d7255377624333e7d08ebf9beb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 13 Jan 2015 15:55:54 -0600 Subject: [PATCH] Tiva Timer: Timer test must attach a timer handler or the timer is stopped at the first interrupt --- arch/arm/src/sam34/sam_tc.c | 9 ++++++-- arch/arm/src/tiva/tiva_timerlow32.c | 36 ++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/arch/arm/src/sam34/sam_tc.c b/arch/arm/src/sam34/sam_tc.c index 1f866726a6..0f2ae3c37d 100644 --- a/arch/arm/src/sam34/sam_tc.c +++ b/arch/arm/src/sam34/sam_tc.c @@ -276,7 +276,9 @@ static int sam34_interrupt(int irq, FAR void *context) { uint32_t timeout; - /* Is there a registered handler? */ + /* Is there a registered handler? If the handler has been nullified, + * the timer will be stopped. + */ if (priv->handler && priv->handler(&priv->timeout)) { @@ -291,9 +293,12 @@ static int sam34_interrupt(int irq, FAR void *context) timeout = (1000000ULL * priv->clkticks) / TC_FCLK; /* trucated timeout */ priv->adjustment = (priv->adjustment + priv->timeout) - timeout; /* truncated time to be added to next interval (dither) */ } - else /* stop */ + else { + /* No handler or the handler returned false.. stop the timer */ + sam34_stop((FAR struct timer_lowerhalf_s *)priv); + tcvdbg("Stopped\n"); } /* TC_INT_CPCS is cleared by reading SAM_TCx_SR */ diff --git a/arch/arm/src/tiva/tiva_timerlow32.c b/arch/arm/src/tiva/tiva_timerlow32.c index ab6053db2d..20bf600a86 100644 --- a/arch/arm/src/tiva/tiva_timerlow32.c +++ b/arch/arm/src/tiva/tiva_timerlow32.c @@ -87,7 +87,7 @@ struct tiva_lowerhalf_s static uint32_t tiva_usec2ticks(struct tiva_lowerhalf_s *priv, uint32_t usecs); static uint32_t tiva_ticks2usec(struct tiva_lowerhalf_s *priv, uint32_t ticks); -static int tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout); +static void tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout); /* Interrupt handling *******************************************************/ @@ -192,11 +192,11 @@ static uint32_t tiva_ticks2usec(struct tiva_lowerhalf_s *priv, uint32_t ticks) * timeout - The new timeout value in microseconds. * * Returned Values: - * Zero on success; a negated errno value on failure. + * None * ****************************************************************************/ -static int tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout) +static void tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout) { timvdbg("Entry: timeout=%d\n", timeout); @@ -215,8 +215,6 @@ static int tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout) timvdbg("clkin=%d clkticks=%d timeout=%d, adjustment=%d\n", priv->clkin, priv->clkticks, priv->timeout, priv->adjustment); - - return OK; } /**************************************************************************** @@ -246,7 +244,9 @@ static void tiva_handler(TIMER_HANDLE handle, void *arg, uint32_t status) { uint32_t timeout; - /* Is there a registered handler? */ + /* Is there a registered handler? If the handler has been nullified, + * the timer will be stopped. + */ if (priv->handler && priv->handler(&priv->timeout)) { @@ -269,9 +269,12 @@ static void tiva_handler(TIMER_HANDLE handle, void *arg, uint32_t status) timeout = tiva_ticks2usec(priv, priv->clkticks); priv->adjustment = (priv->adjustment + priv->timeout) - timeout; } - else /* stop */ + else { + /* No handler or the handler returned false.. stop the timer */ + tiva_timer32_stop(priv->handle); + timvdbg("Stopped\n"); } } } @@ -422,7 +425,6 @@ static int tiva_getstatus(struct timer_lowerhalf_s *lower, static int tiva_settimeout(struct timer_lowerhalf_s *lower, uint32_t timeout) { struct tiva_lowerhalf_s *priv = (struct tiva_lowerhalf_s *)lower; - int ret; DEBUGASSERT(priv); @@ -435,15 +437,12 @@ static int tiva_settimeout(struct timer_lowerhalf_s *lower, uint32_t timeout) /* Calculate the the new time settings */ - ret = tiva_timeout(priv, timeout); - if (ret == OK) - { - /* Reset the timer interval */ + tiva_timeout(priv, timeout); - tiva_timer32_setinterval(priv->handle, priv->clkticks); - } + /* Reset the timer interval */ - return ret; + tiva_timer32_setinterval(priv->handle, priv->clkticks); + return OK; } /**************************************************************************** @@ -584,12 +583,7 @@ int tiva_timer_register(const char *devpath, int gptm, uint32_t timeout, /* Set the initial timer interval */ - ret = tiva_timeout(priv, timeout); - if (ret < 0) - { - timdbg("ERROR: Failed to set initial timeout\n"); - goto errout_with_alloc; - } + tiva_timeout(priv, timeout); /* Create the timer handle */