Tiva Timer: Add basic framework to configure timers. Incomplete on initial commit

This commit is contained in:
Gregory Nutt
2015-01-08 09:47:38 -06:00
parent 4224fd0edc
commit 737108e066
7 changed files with 1033 additions and 52 deletions
+87 -4
View File
@@ -17,6 +17,7 @@ config ARCH_CHIP_LM3S6918
select ARCH_CHIP_LM3S
select TIVA_HAVE_I2C1
select TIVA_HAVE_SSI1
select TIVA_HAVE_TIMER3
select TIVA_HAVE_ETHERNET
config ARCH_CHIP_LM3S9B96
@@ -27,6 +28,7 @@ config ARCH_CHIP_LM3S9B96
select TIVA_HAVE_UART3
select TIVA_HAVE_I2C1
select TIVA_HAVE_SSI1
select TIVA_HAVE_TIMER3
select TIVA_HAVE_ETHERNET
select TIVA_HAVE_GPIOH_IRQS
@@ -44,6 +46,7 @@ config ARCH_CHIP_LM3S6965
select ARCH_CHIP_LM3S
select TIVA_HAVE_UART3
select TIVA_HAVE_I2C1
select TIVA_HAVE_TIMER3
select TIVA_HAVE_ETHERNET
select TIVA_HAVE_GPIOH_IRQS
@@ -54,6 +57,9 @@ config ARCH_CHIP_LM3S8962
select ARCH_CHIP_LM3S
select TIVA_HAVE_UART3
select TIVA_HAVE_I2C1
select TIVA_HAVE_TIMER3
select TIVA_HAVE_TIMER4
select TIVA_HAVE_TIMER5
select TIVA_HAVE_ETHERNET
select TIVA_HAVE_GPIOH_IRQS
@@ -136,6 +142,9 @@ config ARCH_CHIP_LM4F
select TIVA_HAVE_SSI1
select TIVA_HAVE_SSI2
select TIVA_HAVE_SSI3
select TIVA_HAVE_TIMER3
select TIVA_HAVE_TIMER4
select TIVA_HAVE_TIMER5
config ARCH_CHIP_TM4C123
bool
@@ -149,6 +158,8 @@ config ARCH_CHIP_TM4C129
select TIVA_HAVE_I2C7
select TIVA_HAVE_I2C8
select TIVA_HAVE_I2C9
select TIVA_HAVE_TIMER6
select TIVA_HAVE_TIMER7
config ARCH_CHIP_TM4C
bool
@@ -167,6 +178,9 @@ config ARCH_CHIP_TM4C
select TIVA_HAVE_SSI1
select TIVA_HAVE_SSI2
select TIVA_HAVE_SSI3
select TIVA_HAVE_TIMER3
select TIVA_HAVE_TIMER4
select TIVA_HAVE_TIMER5
config LM_REVA2
bool "Rev A2"
@@ -266,6 +280,30 @@ config TIVA_SSI
bool
default n
config TIVA_TIMER
bool
default n
config TIVA_HAVE_TIMER3
bool
default n
config TIVA_HAVE_TIMER4
bool
default n
config TIVA_HAVE_TIMER5
bool
default n
config TIVA_HAVE_TIMER6
bool
default n
config TIVA_HAVE_TIMER7
bool
default n
config TIVA_I2C0
bool "I2C0"
default n
@@ -371,28 +409,73 @@ config TIVA_UART7
config TIVA_SSI0
bool "SSI0"
default y
default n
depends on TIVA_HAVE_SSI0
select TIVA_SSI
config TIVA_SSI1
bool "SSI1"
default y
default n
depends on TIVA_HAVE_SSI1
select TIVA_SSI
config TIVA_SSI2
bool "SSI2"
default y
default n
depends on TIVA_HAVE_SSI2
select TIVA_SSI
config TIVA_SSI3
bool "SSI3"
default y
default n
depends on TIVA_HAVE_SSI3
select TIVA_SSI
config TIVA_TIMER0
bool "16-/32-bit Timer 0"
default n
select TIVA_TIMER
config TIVA_TIMER1
bool "16-/32-bit Timer 1"
default n
select TIVA_TIMER
config TIVA_TIMER2
bool "16-/32-bit Timer 2"
default n
select TIVA_TIMER
config TIVA_TIMER3
bool "16-/32-bit Timer 3"
default n
depends on TIVA_HAVE_TIMER3
select TIVA_TIMER
config TIVA_TIMER4
bool "16-/32-bit Timer 4"
default n
depends on TIVA_HAVE_TIMER4
select TIVA_TIMER
config TIVA_TIMER5
bool "16-/32-bit Timer 5"
default n
depends on TIVA_HAVE_TIMER5
select TIVA_TIMER
config TIVA_TIMER6
bool "16-/32-bit Timer 6"
default n
depends on TIVA_HAVE_TIMER6
select TIVA_TIMER
config TIVA_TIMER7
bool "16-/32-bit Timer 7"
default n
depends on TIVA_HAVE_TIMER7
select TIVA_TIMER
config TIVA_ETHERNET
bool "Ethernet"
default n
+4
View File
@@ -96,6 +96,10 @@ ifeq ($(CONFIG_TIVA_I2C),y)
CHIP_CSRCS += tiva_i2c.c
endif
ifeq ($(CONFIG_TIVA_TIMER),y)
CHIP_CSRCS += tiva_timer.c
endif
ifeq ($(CONFIG_NET),y)
ifeq ($(CONFIG_ARCH_CHIP_LM3S),y)
CHIP_CSRCS += lm3s_ethernet.c
+18 -18
View File
@@ -73,26 +73,26 @@
/* 16/32-Bit Timer Run Mode Clock Gating Control */
#ifdef TIVA_SYSCON_RCGCTIMER
# define tiva_tm_enableclk(p) tiva_enableclk(TIVA_SYSCON_RCGCTIMER,SYSCON_RCGCTIMER(p))
# define tiva_tm_disableclk(p) tiva_disableclk(TIVA_SYSCON_RCGCTIMER,SYSCON_RCGCTIMER(p))
# define tiva_gptm_enableclk(p) tiva_enableclk(TIVA_SYSCON_RCGCTIMER,SYSCON_RCGCTIMER(p))
# define tiva_gptm_disableclk(p) tiva_disableclk(TIVA_SYSCON_RCGCTIMER,SYSCON_RCGCTIMER(p))
# define tiva_tm0_enableclk() tiva_tm_enableclk(0)
# define tiva_tm1_enableclk() tiva_tm_enableclk(1)
# define tiva_tm2_enableclk() tiva_tm_enableclk(2)
# define tiva_tm3_enableclk() tiva_tm_enableclk(3)
# define tiva_tm4_enableclk() tiva_tm_enableclk(4)
# define tiva_tm5_enableclk() tiva_tm_enableclk(5)
# define tiva_tm6_enableclk() tiva_tm_enableclk(6)
# define tiva_tm7_enableclk() tiva_tm_enableclk(7)
# define tiva_gptm0_enableclk() tiva_gptm_enableclk(0)
# define tiva_gptm1_enableclk() tiva_gptm_enableclk(1)
# define tiva_gptm2_enableclk() tiva_gptm_enableclk(2)
# define tiva_gptm3_enableclk() tiva_gptm_enableclk(3)
# define tiva_gptm4_enableclk() tiva_gptm_enableclk(4)
# define tiva_gptm5_enableclk() tiva_gptm_enableclk(5)
# define tiva_gptm6_enableclk() tiva_gptm_enableclk(6)
# define tiva_gptm7_enableclk() tiva_gptm_enableclk(7)
# define tiva_tm0_disableclk() tiva_tm_disableclk(0)
# define tiva_tm1_disableclk() tiva_tm_disableclk(1)
# define tiva_tm2_disableclk() tiva_tm_disableclk(2)
# define tiva_tm3_disableclk() tiva_tm_disableclk(3)
# define tiva_tm4_disableclk() tiva_tm_disableclk(4)
# define tiva_tm5_disableclk() tiva_tm_disableclk(5)
# define tiva_tm6_disableclk() tiva_tm_disableclk(6)
# define tiva_tm7_disableclk() tiva_tm_disableclk(7)
# define tiva_gptm0_disableclk() tiva_gptm_disableclk(0)
# define tiva_gptm1_disableclk() tiva_gptm_disableclk(1)
# define tiva_gptm2_disableclk() tiva_gptm_disableclk(2)
# define tiva_gptm3_disableclk() tiva_gptm_disableclk(3)
# define tiva_gptm4_disableclk() tiva_gptm_disableclk(4)
# define tiva_gptm5_disableclk() tiva_gptm_disableclk(5)
# define tiva_gptm6_disableclk() tiva_gptm_disableclk(6)
# define tiva_gptm7_disableclk() tiva_gptm_disableclk(7)
#else
#endif
+20 -20
View File
@@ -75,30 +75,30 @@
/* 16/32-Bit Timer Power Control */
#ifdef TIVA_SYSCON_PCTIMER
# define tiva_tm_enablepwr(p) tiva_enablepwr(TIVA_SYSCON_PCTIMER,SYSCON_PCTIMER(p))
# define tiva_tm_disablepwr(p) tiva_disablepwr(TIVA_SYSCON_PCTIMER,SYSCON_PCTIMER(p))
# define tiva_gptm_enablepwr(p) tiva_enablepwr(TIVA_SYSCON_PCTIMER,SYSCON_PCTIMER(p))
# define tiva_gptm_disablepwr(p) tiva_disablepwr(TIVA_SYSCON_PCTIMER,SYSCON_PCTIMER(p))
#else
# define tiva_tm_enablepwr(p)
# define tiva_tm_disablepwr(p)
# define tiva_gptm_enablepwr(p)
# define tiva_gptm_disablepwr(p)
#endif
#define tiva_tm0_enablepwr() tiva_tm_enablepwr(0)
#define tiva_tm1_enablepwr() tiva_tm_enablepwr(1)
#define tiva_tm2_enablepwr() tiva_tm_enablepwr(2)
#define tiva_tm3_enablepwr() tiva_tm_enablepwr(3)
#define tiva_tm4_enablepwr() tiva_tm_enablepwr(4)
#define tiva_tm5_enablepwr() tiva_tm_enablepwr(5)
#define tiva_tm6_enablepwr() tiva_tm_enablepwr(6)
#define tiva_tm7_enablepwr() tiva_tm_enablepwr(7)
#define tiva_gptm0_enablepwr() tiva_gptm_enablepwr(0)
#define tiva_gptm1_enablepwr() tiva_gptm_enablepwr(1)
#define tiva_gptm2_enablepwr() tiva_gptm_enablepwr(2)
#define tiva_gptm3_enablepwr() tiva_gptm_enablepwr(3)
#define tiva_gptm4_enablepwr() tiva_gptm_enablepwr(4)
#define tiva_gptm5_enablepwr() tiva_gptm_enablepwr(5)
#define tiva_gptm6_enablepwr() tiva_gptm_enablepwr(6)
#define tiva_gptm7_enablepwr() tiva_gptm_enablepwr(7)
#define tiva_tm0_disablepwr() tiva_tm_disablepwr(0)
#define tiva_tm1_disablepwr() tiva_tm_disablepwr(1)
#define tiva_tm2_disablepwr() tiva_tm_disablepwr(2)
#define tiva_tm3_disablepwr() tiva_tm_disablepwr(3)
#define tiva_tm4_disablepwr() tiva_tm_disablepwr(4)
#define tiva_tm5_disablepwr() tiva_tm_disablepwr(5)
#define tiva_tm6_disablepwr() tiva_tm_disablepwr(6)
#define tiva_tm7_disablepwr() tiva_tm_disablepwr(7)
#define tiva_gptm0_disablepwr() tiva_gptm_disablepwr(0)
#define tiva_gptm1_disablepwr() tiva_gptm_disablepwr(1)
#define tiva_gptm2_disablepwr() tiva_gptm_disablepwr(2)
#define tiva_gptm3_disablepwr() tiva_gptm_disablepwr(3)
#define tiva_gptm4_disablepwr() tiva_gptm_disablepwr(4)
#define tiva_gptm5_disablepwr() tiva_gptm_disablepwr(5)
#define tiva_gptm6_disablepwr() tiva_gptm_disablepwr(6)
#define tiva_gptm7_disablepwr() tiva_gptm_disablepwr(7)
/* GPIO Power Control */
+10 -10
View File
@@ -69,19 +69,19 @@
/* 16/32-Bit Timer Power Control */
#ifdef TIVA_SYSCON_PRTIMER
# define tiva_tm_periphrdy(p) tiva_periphrdy(TIVA_SYSCON_PRTIMER,SYSCON_PRTIMER(p))
# define tiva_gptm_periphrdy(p) tiva_periphrdy(TIVA_SYSCON_PRTIMER,SYSCON_PRTIMER(p))
#else
# define tiva_tm_periphrdy(p) (true)
# define tiva_gptm_periphrdy(p) (true)
#endif
#define tiva_tm0_periphrdy() tiva_tm_periphrdy(0)
#define tiva_tm1_periphrdy() tiva_tm_periphrdy(1)
#define tiva_tm2_periphrdy() tiva_tm_periphrdy(2)
#define tiva_tm3_periphrdy() tiva_tm_periphrdy(3)
#define tiva_tm4_periphrdy() tiva_tm_periphrdy(4)
#define tiva_tm5_periphrdy() tiva_tm_periphrdy(5)
#define tiva_tm6_periphrdy() tiva_tm_periphrdy(6)
#define tiva_tm7_periphrdy() tiva_tm_periphrdy(7)
#define tiva_gptm0_periphrdy() tiva_gptm_periphrdy(0)
#define tiva_gptm1_periphrdy() tiva_gptm_periphrdy(1)
#define tiva_gptm2_periphrdy() tiva_gptm_periphrdy(2)
#define tiva_gptm3_periphrdy() tiva_gptm_periphrdy(3)
#define tiva_gptm4_periphrdy() tiva_gptm_periphrdy(4)
#define tiva_gptm5_periphrdy() tiva_gptm_periphrdy(5)
#define tiva_gptm6_periphrdy() tiva_gptm_periphrdy(6)
#define tiva_gptm7_periphrdy() tiva_gptm_periphrdy(7)
/* GPIO Power Control */
File diff suppressed because it is too large Load Diff
+207
View File
@@ -0,0 +1,207 @@
/****************************************************************************
* arch/arm/src/tiva/tiva_timer.h
*
* Copyright (C) 201r Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_TIVA_TIVA_TIMER_H
#define __ARCH_ARM_SRC_TIVA_TIVA_TIMER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <arch/tiva/chip.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Make sure that no timers are enabled that are not supported by the
* architecture.
*/
#if TIVA_NTIMERS < 8
# undef CONFIG_TIVA_TIMER7
# if TIVA_NTIMERS < 7
# undef CONFIG_TIVA_TIMER6
# if TIVA_NTIMERS < 6
# undef CONFIG_TIVA_TIMER5
# if TIVA_NTIMERS < 5
# undef CONFIG_TIVA_TIMER4
# if TIVA_NTIMERS < 4
# undef CONFIG_TIVA_TIMER3
# if TIVA_NTIMERS < 3
# undef CONFIG_TIVA_TIMER2
# if TIVA_NTIMERS < 2
# undef CONFIG_TIVA_TIMER1
# if TIVA_NTIMERS < 1
# undef CONFIG_TIVA_TIMER0
# endif
# endif
# endif
# endif
# endif
# endif
# endif
#endif
/* Used with the synca and syncb fields of struct tiva_timerconfig_s */
#define TIMER_SYNC(n) (1 << (n))
/* Identifies timer A and timer B */
#define TIMER_A 0
#define TIMER_B 1
/****************************************************************************
* Public Types
****************************************************************************/
/* This enumeration identifies all supported 32-bit timer modes of operation */
enum tiva_timer32mode_e
{
TIMER16_MODE = 0, /* Use 16-bit timers, not 32-bit timer */
TIMER32_MODE_ONESHOT, /* 32-bit programmable one-shot timer */
TIMER32_MODE_PERIODIC, /* 32-bit programmable periodic timer */
TIMER32_MODE_RTC /* 32-bit RTC with external 32.768-KHz input */
};
/* This enumeration identifies all supported 16-bit timer A/Bmodes of
* operation.
*/
enum tiva_timer16mode_e
{
TIMER16_MODE_NONE = 0, /* 16-bit timer not used */
TIMER16_MODE_ONESHOT, /* 16-bit programmable one-shot timer */
TIMER16_MODE_PERIODIC, /* 16-bit programmable periodic timer */
TIMER16_MODE_COUNT_CAPTURE, /* 16-bit input edge-count capture mode w/8-bit prescaler */
TIMER16_MODE_TIME_CAPTURE, /* 16-bit input time capture mode w/8-bit prescaler */
TIMER16_MODE_PWM /* 16-bit PWM output mode w/8-bit prescaler */
};
/* This enumeration describes the timer clock source */
enum tiva_timersource_e
{
TIMER_SOURCE_SYSCLK = 0, /* Timer clock source is SysClk */
TIMER_SOURCE_PIOSC, /* Timer clock source is PIOSC */
TIMER_SOURCE_RTCOSC, /* Source is Hibernation Module Real-time clock */
TIMER_SOURCE_LFIOSC /* Timer clock source is LFI oscillator */
};
/* This structure describes the configuration of one 32-bit timer */
struct tiva_timer32config_s
{
bool down; /* False: Count up; True: Count down */
/* TODO: Add fields to support ADC trigger events */
};
/* This structure describes the configuration of one 16-bit timer A/B */
struct tiva_timer16config_s
{
uint8_t mode; /* See enum tiva_timermode_e */
bool down; /* False: Count up; True: Count down */
/* TODO: Add fields to support ADC trigger events */
};
/* This structure describes usage of both timers on a GPTIM module */
struct tiva_gptmconfig_s
{
uint8_t gptm; /* GPTM number */
uint8_t source; /* See enum tiva_timersource_e */
uint8_t mode; /* See enum tiva_timer32mode_e */
};
/* This structure is cast compatible with struct tiva_gptmconfig_s and
* describes usage of the single 32-bit timers on a GPTM module.
*/
struct tiva_gptm32config_s
{
struct tiva_gptmconfig_s cmn;
struct tiva_timer32config_s config;
};
/* This structure is cast compatible with struct tiva_gptmconfig_s and
* describes usage of both bit-bit timers A/B on a GPTM module.
*/
struct tiva_gptm16config_s
{
struct tiva_gptmconfig_s cmn;
struct tiva_timer16config_s config[2];
};
/* This type represents the opaque handler returned by tiva_gptm_configure() */
typedef FAR void *TIMER_HANDLE;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: tiva_gptm_configure
*
* Description:
* Configure a general purpose timer module to operate in the provided
* modes.
*
****************************************************************************/
TIMER_HANDLE tiva_gptm_configure(const struct tiva_gptmconfig_s *gptm);
/****************************************************************************
* Name: tiva_gptm0_synchronize
*
* Description:
* Trigger timers from GPTM0 output.
*
****************************************************************************/
int tiva_gptm0_synchronize(uint32_t sync);
#endif /* __ARCH_ARM_SRC_TIVA_TIVA_TIMER_H */