summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-13 11:49:00 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-13 11:49:00 -0600
commit539679ea1af06dfa26c117023807bf4cb46eb8bf (patch)
treeb53774af7efd885fbdc87cc2c5d1de0a0c39b6a5
parentca5d1c373f04fd70444ea6bf96123b6cbf40c234 (diff)
downloadpx4-nuttx-539679ea1af06dfa26c117023807bf4cb46eb8bf.tar.gz
px4-nuttx-539679ea1af06dfa26c117023807bf4cb46eb8bf.tar.bz2
px4-nuttx-539679ea1af06dfa26c117023807bf4cb46eb8bf.zip
Timer Timer: Timer driver now initializes without complaints. Need a test driver of some kind to make more testing progress.
-rw-r--r--nuttx/arch/arm/src/tiva/tiva_timerlib.c20
-rw-r--r--nuttx/arch/arm/src/tiva/tiva_timerlow32.c70
-rw-r--r--nuttx/configs/dk-tm4c129x/nsh/defconfig2
3 files changed, 61 insertions, 31 deletions
diff --git a/nuttx/arch/arm/src/tiva/tiva_timerlib.c b/nuttx/arch/arm/src/tiva/tiva_timerlib.c
index f3b3a8b1d..041848f59 100644
--- a/nuttx/arch/arm/src/tiva/tiva_timerlib.c
+++ b/nuttx/arch/arm/src/tiva/tiva_timerlib.c
@@ -1792,12 +1792,12 @@ TIMER_HANDLE tiva_gptm_configure(const struct tiva_gptmconfig_s *config)
/* Reset the timer to be certain that it is in the disabled state */
- regval = tiva_getreg(priv, TIVA_SYSCON_SRTIMER);
+ regval = getreg32(TIVA_SYSCON_SRTIMER);
regval |= SYSCON_SRTIMER(config->gptm);
- tiva_putreg(priv, TIVA_SYSCON_SRTIMER, regval);
+ putreg32(regval, TIVA_SYSCON_SRTIMER);
regval &= ~SYSCON_SRTIMER(config->gptm);
- tiva_putreg(priv, TIVA_SYSCON_SRTIMER, regval);
+ putreg32(regval, TIVA_SYSCON_SRTIMER);
/* Wait for the reset to complete */
@@ -1946,12 +1946,12 @@ void tiva_gptm_release(TIMER_HANDLE handle)
/* Reset the time to be certain that it is in the disabled state */
- regval = tiva_getreg(priv, TIVA_SYSCON_SRTIMER);
+ regval = getreg32(TIVA_SYSCON_SRTIMER);
regval |= SYSCON_SRTIMER(config->gptm);
- tiva_putreg(priv, TIVA_SYSCON_SRTIMER, regval);
+ putreg32(regval, TIVA_SYSCON_SRTIMER);
regval &= ~SYSCON_SRTIMER(config->gptm);
- tiva_putreg(priv, TIVA_SYSCON_SRTIMER, regval);
+ putreg32(regval, TIVA_SYSCON_SRTIMER);
/* Wait for the reset to complete */
@@ -2407,7 +2407,7 @@ void tiva_timer32_setinterval(TIMER_HANDLE handle, uint32_t interval)
* generated as normal
*/
- modev1 = tiva_getreg(priv, moder);
+ modev1 = getreg32(moder);
modev2 = modev1 & ~TIMER_TnMR_TnCINTD;
putreg32(modev2, moder);
}
@@ -2415,7 +2415,7 @@ void tiva_timer32_setinterval(TIMER_HANDLE handle, uint32_t interval)
{
/* Setting the TACINTD bit prevents the time-out interrupt */
- modev1 = tiva_getreg(priv, moder);
+ modev1 = getreg32(moder);
modev2 = modev1 | TIMER_TnMR_TnCINTD;
putreg32(modev2, moder);
@@ -2550,7 +2550,7 @@ void tiva_timer16_setinterval(TIMER_HANDLE handle, uint16_t interval, int tmndx)
* generated as normal
*/
- modev1 = tiva_getreg(priv, moder);
+ modev1 = getreg32(moder);
modev2 = modev1 & ~TIMER_TnMR_TnCINTD;
putreg32(modev2, moder);
}
@@ -2558,7 +2558,7 @@ void tiva_timer16_setinterval(TIMER_HANDLE handle, uint16_t interval, int tmndx)
{
/* Setting the TACINTD bit prevents the time-out interrupt */
- modev1 = tiva_getreg(priv, moder);
+ modev1 = getreg32(moder);
modev2 = modev1 | TIMER_TnMR_TnCINTD;
putreg32(modev2, moder);
diff --git a/nuttx/arch/arm/src/tiva/tiva_timerlow32.c b/nuttx/arch/arm/src/tiva/tiva_timerlow32.c
index d7711ad64..ab6053db2 100644
--- a/nuttx/arch/arm/src/tiva/tiva_timerlow32.c
+++ b/nuttx/arch/arm/src/tiva/tiva_timerlow32.c
@@ -87,6 +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);
/* Interrupt handling *******************************************************/
@@ -181,6 +182,44 @@ static uint32_t tiva_ticks2usec(struct tiva_lowerhalf_s *priv, uint32_t ticks)
}
/****************************************************************************
+ * Name: tiva_timeout
+ *
+ * Description:
+ * Calculate a new timeout value.
+ *
+ * Input Parameters:
+ * priv - A pointer to a private timer driver lower half instance
+ * timeout - The new timeout value in microseconds.
+ *
+ * Returned Values:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int tiva_timeout(struct tiva_lowerhalf_s *priv, uint32_t timeout)
+{
+ timvdbg("Entry: timeout=%d\n", timeout);
+
+ /* Save the desired timeout value */
+
+ priv->timeout = timeout;
+
+ /* Calculate the actual timeout value in clock ticks */
+
+ priv->clkticks = tiva_usec2ticks(priv, timeout);
+
+ /* Calculate an adjustment due to truncation in timer resolution */
+
+ timeout = tiva_ticks2usec(priv, priv->clkticks);
+ priv->adjustment = priv->timeout - timeout;
+
+ timvdbg("clkin=%d clkticks=%d timeout=%d, adjustment=%d\n",
+ priv->clkin, priv->clkticks, priv->timeout, priv->adjustment);
+
+ return OK;
+}
+
+/****************************************************************************
* Name: tiva_handler
*
* Description:
@@ -380,10 +419,10 @@ static int tiva_getstatus(struct timer_lowerhalf_s *lower,
*
****************************************************************************/
-static int tiva_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout)
+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);
@@ -394,26 +433,17 @@ static int tiva_settimeout(struct timer_lowerhalf_s *lower,
timvdbg("Entry: timeout=%d\n", timeout);
- /* Save the desired timeout value */
-
- priv->timeout = timeout;
-
- /* Calculate the actual timeout value in clock ticks */
-
- priv->clkticks = tiva_usec2ticks(priv, timeout);
+ /* Calculate the the new time settings */
- /* Calculate an adjustment due to truncation in timer resolution */
-
- timeout = tiva_ticks2usec(priv, priv->clkticks);
- priv->adjustment = priv->timeout - timeout;
-
- timvdbg("clkin=%d clkticks=%d timout=%d, adjustment=%d\n",
- priv->clkin, priv->clkticks, priv->timeout, priv->adjustment);
+ ret = tiva_timeout(priv, timeout);
+ if (ret == OK)
+ {
+ /* Reset the timer interval */
- /* Reset the timer interval */
+ tiva_timer32_setinterval(priv->handle, priv->clkticks);
+ }
- tiva_timer32_setinterval(priv->handle, priv->clkticks);
- return OK;
+ return ret;
}
/****************************************************************************
@@ -554,7 +584,7 @@ int tiva_timer_register(const char *devpath, int gptm, uint32_t timeout,
/* Set the initial timer interval */
- ret = tiva_settimeout((struct timer_lowerhalf_s *)priv, timeout);
+ ret = tiva_timeout(priv, timeout);
if (ret < 0)
{
timdbg("ERROR: Failed to set initial timeout\n");
diff --git a/nuttx/configs/dk-tm4c129x/nsh/defconfig b/nuttx/configs/dk-tm4c129x/nsh/defconfig
index 0eaa909ab..f48daae0b 100644
--- a/nuttx/configs/dk-tm4c129x/nsh/defconfig
+++ b/nuttx/configs/dk-tm4c129x/nsh/defconfig
@@ -257,7 +257,7 @@ CONFIG_ARCH_HAVE_RAMVECTORS=y
#
# Board Settings
#
-CONFIG_BOARD_LOOPSPERMSEC=4531
+CONFIG_BOARD_LOOPSPERMSEC=11401
# CONFIG_ARCH_CALIBRATION is not set
#