diff options
Diffstat (limited to 'nuttx/arch/arm/src/tiva/tiva_timerlib.c')
-rw-r--r-- | nuttx/arch/arm/src/tiva/tiva_timerlib.c | 123 |
1 files changed, 122 insertions, 1 deletions
diff --git a/nuttx/arch/arm/src/tiva/tiva_timerlib.c b/nuttx/arch/arm/src/tiva/tiva_timerlib.c index 837693e6b..f5c32b0c3 100644 --- a/nuttx/arch/arm/src/tiva/tiva_timerlib.c +++ b/nuttx/arch/arm/src/tiva/tiva_timerlib.c @@ -72,9 +72,13 @@ struct tiva_gptmattr_s { uintptr_t base; /* Register base address */ - int irq[2]; /* Timer A/B interrupt numbers */ + uint16_t irq[2]; /* Timer A/B interrupt numbers */ +#ifdef CONFIG_TIVA_TIMER_32BIT xcpt_t handler32; /* Handler for 32-bit timer interrupts */ +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT xcpt_t handler16[2]; /* Handlers for 16-bit timer A/B interrupts */ +#endif }; /* This structure represents the state of a GPTM module */ @@ -116,6 +120,7 @@ static void tiva_putreg(struct tiva_gptmstate_s *priv, unsigned int offset, /* Interrupt handling */ +#ifdef CONFIG_TIVA_TIMER_32BIT static int tiva_timer32_interrupt(struct tiva_gptmstate_s *priv); #ifdef CONFIG_TIVA_TIMER0 static int tiva_gptm0_interrupt(int irq, FAR void *context); @@ -141,7 +146,9 @@ static int tiva_gptm6_interrupt(int irq, FAR void *context); #ifdef CONFIG_TIVA_TIMER7 static int tiva_gptm7_interrupt(int irq, FAR void *context); #endif +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT static int tiva_timer16_interrupt(struct tiva_gptmstate_s *priv, int tmndx); #ifdef CONFIG_TIVA_TIMER0 @@ -176,26 +183,43 @@ static int tiva_timer6b_interrupt(int irq, FAR void *context); static int tiva_timer7a_interrupt(int irq, FAR void *context); static int tiva_timer7b_interrupt(int irq, FAR void *context); #endif +#endif /* Timer initialization and configuration */ +#ifdef CONFIG_TIVA_TIMER32_PERIODIC static int tiva_oneshot_periodic_mode32(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer); +#endif +#ifdef CONFIG_TIVA_TIMER16_PERIODIC static int tiva_oneshot_periodic_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_RTC static int tiva_rtc_mode32(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer); +#endif +#ifdef CONFIG_TIVA_TIMER32_EDGECOUNT static int tiva_input_edgecount_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_TIMECAP static int tiva_input_time_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_PWM static int tiva_pwm_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER_32BIT static int tiva_timer32_configure(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer); +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT static int tiva_timer16_configure(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx); +#endif /**************************************************************************** * Private Data @@ -206,8 +230,12 @@ static const struct tiva_gptmattr_s g_gptm0_attr = { .base = TIVA_TIMER0_BASE, .irq = { TIVA_IRQ_TIMER0A, TIVA_IRQ_TIMER0B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm0_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer0a_interrupt, tiva_timer0b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm0_state; @@ -218,8 +246,12 @@ static const struct tiva_gptmattr_s g_gptm1_attr = { .base = TIVA_TIMER1_BASE, .irq = { TIVA_IRQ_TIMER1A, TIVA_IRQ_TIMER1B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm1_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer1a_interrupt, tiva_timer1b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm1_state; @@ -230,8 +262,12 @@ static const struct tiva_gptmattr_s g_gptm2_attr = { .base = TIVA_TIMER2_BASE, .irq = { TIVA_IRQ_TIMER2A, TIVA_IRQ_TIMER2B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm2_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer2a_interrupt, tiva_timer2b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm2_state; @@ -242,8 +278,12 @@ static const struct tiva_gptmattr_s g_gptm3_attr = { .base = TIVA_TIMER3_BASE, .irq = { TIVA_IRQ_TIMER3A, TIVA_IRQ_TIMER3B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm3_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer3a_interrupt, tiva_timer3b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm3_state; @@ -254,8 +294,12 @@ static const struct tiva_gptmattr_s g_gptm4_attr = { .base = TIVA_TIMER4_BASE, .irq = { TIVA_IRQ_TIMER4A, TIVA_IRQ_TIMER4B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm4_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer4a_interrupt, tiva_timer4b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm4_state; @@ -266,8 +310,12 @@ static const struct tiva_gptmattr_s g_gptm5_attr = { .base = TIVA_TIMER5_BASE, .irq = { TIVA_IRQ_TIMER5A, TIVA_IRQ_TIMER5B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm5_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer5a_interrupt, tiva_timer5b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm5_state; @@ -278,8 +326,12 @@ static const struct tiva_gptmattr_s g_gptm6_attr = { .base = TIVA_TIMER6_BASE, .irq = { TIVA_IRQ_TIMER6A, TIVA_IRQ_TIMER6B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm6_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer6a_interrupt, tiva_timer6b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm6_state; @@ -290,8 +342,12 @@ static const struct tiva_gptmattr_s g_gptm7_attr = { .base = TIVA_TIMER7_BASE, .irq = { TIVA_IRQ_TIMER7A, TIVA_IRQ_TIMER7B }, +#ifdef CONFIG_TIVA_TIMER_32BIT .handler32 = tiva_gptm7_interrupt, +#endif +#ifdef CONFIG_TIVA_TIMER_16BIT .handler16 = { tiva_timer7a_interrupt, tiva_timer7b_interrupt }, +#endif }; static struct tiva_gptmstate_s g_gptm7_state; @@ -438,6 +494,7 @@ static void tiva_modifyreg(struct tiva_gptmstate_s *priv, unsigned int offset, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT static int tiva_timer32_interrupt(struct tiva_gptmstate_s *priv) { const struct tiva_gptm32config_s *config32; @@ -485,6 +542,7 @@ static int tiva_timer32_interrupt(struct tiva_gptmstate_s *priv) return OK; } +#endif /**************************************************************************** * Name: tiva_gptmN_interrupt, N=0..7 @@ -494,6 +552,7 @@ static int tiva_timer32_interrupt(struct tiva_gptmstate_s *priv) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT #ifdef CONFIG_TIVA_TIMER0 static int tiva_gptm0_interrupt(int irq, FAR void *context) { @@ -549,6 +608,7 @@ static int tiva_gptm7_interrupt(int irq, FAR void *context) return tiva_timer32_interrupt(&g_gptm7_state); } #endif +#endif /**************************************************************************** * Name: tiva_timer16_interrupt @@ -558,6 +618,7 @@ static int tiva_gptm7_interrupt(int irq, FAR void *context) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT static int tiva_timer16_interrupt(struct tiva_gptmstate_s *priv, int tmndx) { const struct tiva_gptm16config_s *config16; @@ -607,6 +668,7 @@ static int tiva_timer16_interrupt(struct tiva_gptmstate_s *priv, int tmndx) return OK; } +#endif /**************************************************************************** * Name: tiva_timerNa_interrupt, tiva_timerNb_interrupt, N=0..7 @@ -616,6 +678,7 @@ static int tiva_timer16_interrupt(struct tiva_gptmstate_s *priv, int tmndx) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT #ifdef CONFIG_TIVA_TIMER0 static int tiva_timer0a_interrupt(int irq, FAR void *context) { @@ -711,6 +774,7 @@ static int tiva_timer7b_interrupt(int irq, FAR void *context) return tiva_timer16_interrupt(&g_gptm7_state, TIMER16B); } #endif +#endif /**************************************************************************** * Name: tiva_oneshot_periodic_mode32 @@ -720,6 +784,7 @@ static int tiva_timer7b_interrupt(int irq, FAR void *context) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_PERIODIC static int tiva_oneshot_periodic_mode32(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer) { @@ -929,6 +994,7 @@ static int tiva_oneshot_periodic_mode32(struct tiva_gptmstate_s *priv, return OK; } +#endif /**************************************************************************** * Name: tiva_oneshot_periodic_mode16 @@ -938,6 +1004,7 @@ static int tiva_oneshot_periodic_mode32(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER16_PERIODIC static int tiva_oneshot_periodic_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx) @@ -1149,6 +1216,7 @@ static int tiva_oneshot_periodic_mode16(struct tiva_gptmstate_s *priv, return OK; } +#endif /**************************************************************************** * Name: tiva_rtc_mode32 @@ -1162,6 +1230,7 @@ static int tiva_oneshot_periodic_mode16(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_RTC static int tiva_rtc_mode32(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer) { @@ -1235,6 +1304,7 @@ static int tiva_rtc_mode32(struct tiva_gptmstate_s *priv, return OK; } +#endif /**************************************************************************** * Name: tiva_input_edgecount_mode16 @@ -1244,6 +1314,7 @@ static int tiva_rtc_mode32(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_EDGECOUNT static int tiva_input_edgecount_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx) @@ -1302,6 +1373,7 @@ static int tiva_input_edgecount_mode16(struct tiva_gptmstate_s *priv, return -ENOSYS; } +#endif /**************************************************************************** * Name: tiva_input_time_mode16 @@ -1311,6 +1383,7 @@ static int tiva_input_edgecount_mode16(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_TIMECAP static int tiva_input_time_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx) @@ -1370,6 +1443,7 @@ static int tiva_input_time_mode16(struct tiva_gptmstate_s *priv, return -ENOSYS; } +#endif /**************************************************************************** * Name: tiva_pwm_mode16 @@ -1379,6 +1453,7 @@ static int tiva_input_time_mode16(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_PWM static int tiva_pwm_mode16(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx) @@ -1438,6 +1513,7 @@ static int tiva_pwm_mode16(struct tiva_gptmstate_s *priv, return -ENOSYS; } +#endif /**************************************************************************** * Name: tiva_timer16_configure @@ -1447,23 +1523,29 @@ static int tiva_pwm_mode16(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT static int tiva_timer32_configure(struct tiva_gptmstate_s *priv, const struct tiva_timer32config_s *timer) { switch (priv->config->mode) { +#ifdef CONFIG_TIVA_TIMER32_PERIODIC case TIMER32_MODE_ONESHOT: /* 32-bit programmable one-shot timer */ case TIMER32_MODE_PERIODIC: /* 32-bit programmable periodic timer */ return tiva_oneshot_periodic_mode32(priv, timer); +#endif +#ifdef CONFIG_TIVA_TIMER32_RTC case TIMER32_MODE_RTC: /* 32-bit RTC with external 32.768-KHz * input */ return tiva_rtc_mode32(priv, timer); +#endif default: return -EINVAL; } } +#endif /**************************************************************************** * Name: tiva_timer16_configure @@ -1473,6 +1555,7 @@ static int tiva_timer32_configure(struct tiva_gptmstate_s *priv, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT static int tiva_timer16_configure(struct tiva_gptmstate_s *priv, const struct tiva_timer16config_s *timer, int tmndx) @@ -1484,26 +1567,35 @@ static int tiva_timer16_configure(struct tiva_gptmstate_s *priv, case TIMER16_MODE_NONE: return OK; +#ifdef CONFIG_TIVA_TIMER16_PERIODIC case TIMER16_MODE_ONESHOT: /* 16-bit programmable one-shot timer */ case TIMER16_MODE_PERIODIC: /* 16-bit programmable periodic timer */ return tiva_oneshot_periodic_mode16(priv, timer, tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_EDGECOUNT case TIMER16_MODE_COUNT_CAPTURE: /* 16-bit input-edge count-capture * mode w/8-bit prescaler */ return tiva_input_edgecount_mode16(priv, timer, tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_TIMECAP case TIMER16_MODE_TIME_CAPTURE: /* 16-bit input-edge time-capture * mode w/8-bit prescaler */ return tiva_input_time_mode16(priv, timer, tmndx); +#endif +#ifdef CONFIG_TIVA_TIMER32_PWM case TIMER16_MODE_PWM: /* 16-bit PWM output mode w/8-bit * prescaler */ return tiva_pwm_mode16(priv, timer, tmndx); +#endif default: return -EINVAL; } } +#endif /**************************************************************************** * Public Functions @@ -1687,6 +1779,7 @@ TIMER_HANDLE tiva_gptm_configure(const struct tiva_gptmconfig_s *config) if (config->mode != TIMER16_MODE) { +#ifdef CONFIG_TIVA_TIMER_32BIT const struct tiva_gptm32config_s *config32 = (const struct tiva_gptm32config_s *)config; @@ -1701,9 +1794,13 @@ TIMER_HANDLE tiva_gptm_configure(const struct tiva_gptmconfig_s *config) ret = tiva_timer32_configure(priv, &config32->config); } +#else + return (TIMER_HANDLE)NULL; +#endif } else { +#ifdef CONFIG_TIVA_TIMER_16BIT const struct tiva_gptm16config_s *config16 = (const struct tiva_gptm16config_s *)config; @@ -1738,6 +1835,9 @@ TIMER_HANDLE tiva_gptm_configure(const struct tiva_gptmconfig_s *config) ret = tiva_timer16_configure(priv, &config16->config[TIMER16B], TIMER16B); } +#else + return (TIMER_HANDLE)NULL; +#endif } /* Return the timer handler if successfully configured */ @@ -1894,6 +1994,7 @@ void tiva_gptm_modifyreg(TIMER_HANDLE handle, unsigned int offset, * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT void tiva_timer32_start(TIMER_HANDLE handle) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -1913,6 +2014,7 @@ void tiva_timer32_start(TIMER_HANDLE handle) up_enable_irq(priv->attr->irq[TIMER32]); } } +#endif /**************************************************************************** * Name: tiva_timer16_start @@ -1930,6 +2032,7 @@ void tiva_timer32_start(TIMER_HANDLE handle) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT void tiva_timer16_start(TIMER_HANDLE handle, int tmndx) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -1953,6 +2056,7 @@ void tiva_timer16_start(TIMER_HANDLE handle, int tmndx) up_enable_irq(priv->attr->irq[tmndx]); } } +#endif /**************************************************************************** * Name: tiva_timer32_stop @@ -1969,6 +2073,7 @@ void tiva_timer16_start(TIMER_HANDLE handle, int tmndx) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT void tiva_timer32_stop(TIMER_HANDLE handle) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -1983,6 +2088,7 @@ void tiva_timer32_stop(TIMER_HANDLE handle) tiva_modifyreg(priv, TIVA_TIMER_CTL_OFFSET, TIMER_CTL_TAEN, 0); } +#endif /**************************************************************************** * Name: tiva_timer16_stop @@ -2000,6 +2106,7 @@ void tiva_timer32_stop(TIMER_HANDLE handle) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT void tiva_timer16_stop(TIMER_HANDLE handle, int tmndx) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2016,6 +2123,7 @@ void tiva_timer16_stop(TIMER_HANDLE handle, int tmndx) clrbits = tmndx ? TIMER_CTL_TBEN : TIMER_CTL_TAEN; tiva_gptm_modifyreg(handle, TIVA_TIMER_CTL_OFFSET, clrbits, 0); } +#endif /**************************************************************************** * Name: tiva_timer16_counter @@ -2041,6 +2149,7 @@ void tiva_timer16_stop(TIMER_HANDLE handle, int tmndx) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT uint32_t tiva_timer16_counter(TIMER_HANDLE handle, int tmndx) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2141,6 +2250,7 @@ uint32_t tiva_timer16_counter(TIMER_HANDLE handle, int tmndx) return counter; } +#endif /**************************************************************************** * Name: tiva_timer32_setinterval @@ -2158,6 +2268,7 @@ uint32_t tiva_timer16_counter(TIMER_HANDLE handle, int tmndx) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_32BIT void tiva_timer32_setinterval(TIMER_HANDLE handle, uint32_t interval) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2251,6 +2362,7 @@ void tiva_timer32_setinterval(TIMER_HANDLE handle, uint32_t interval) lldbg("%08x<-%08x\n", imrr, priv->imr); #endif } +#endif /**************************************************************************** * Name: tiva_timer16_setinterval @@ -2269,6 +2381,7 @@ void tiva_timer32_setinterval(TIMER_HANDLE handle, uint32_t interval) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER_16BIT void tiva_timer16_setinterval(TIMER_HANDLE handle, uint16_t interval, int tmndx) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2376,6 +2489,7 @@ void tiva_timer16_setinterval(TIMER_HANDLE handle, uint16_t interval, int tmndx) lldbg("%08x<-%08x\n", imrr, priv->imr); #endif } +#endif /**************************************************************************** * Name: tiva_rtc_setalarm @@ -2397,6 +2511,7 @@ void tiva_timer16_setinterval(TIMER_HANDLE handle, uint16_t interval, int tmndx) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_RTC void tiva_rtc_setalarm(TIMER_HANDLE handle, uint32_t delay) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2464,6 +2579,7 @@ void tiva_rtc_setalarm(TIMER_HANDLE handle, uint32_t delay) lldbg("%08x<-%08x\n", base + TIVA_TIMER_IMR_OFFSET, priv->imr); #endif } +#endif /**************************************************************************** * Name: tiva_timer32_relmatch @@ -2494,6 +2610,7 @@ void tiva_rtc_setalarm(TIMER_HANDLE handle, uint32_t delay) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER32_PERIODIC void tiva_timer32_relmatch(TIMER_HANDLE handle, uint32_t relmatch) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2561,6 +2678,7 @@ void tiva_timer32_relmatch(TIMER_HANDLE handle, uint32_t relmatch) lldbg("%08x<-%08x\n", base + TIVA_TIMER_IMR_OFFSET, priv->imr); #endif } +#endif /**************************************************************************** * Name: tiva_timer16_relmatch @@ -2602,6 +2720,7 @@ void tiva_timer32_relmatch(TIMER_HANDLE handle, uint32_t relmatch) * ****************************************************************************/ +#ifdef CONFIG_TIVA_TIMER16_PERIODIC void tiva_timer16_relmatch(TIMER_HANDLE handle, uint32_t relmatch, int tmndx) { struct tiva_gptmstate_s *priv = (struct tiva_gptmstate_s *)handle; @@ -2749,3 +2868,5 @@ void tiva_timer16_relmatch(TIMER_HANDLE handle, uint32_t relmatch, int tmndx) lldbg("%08x<-%08x\n", imr, priv->imr); #endif } +#endif + |