DK-TM3C129X Timer: Add timer initialization logic to the board bring-up

This commit is contained in:
Gregory Nutt 2015-01-13 11:10:35 -06:00
parent 47b04339d2
commit 9c3dce06e1
7 changed files with 232 additions and 4 deletions

View File

@ -892,7 +892,7 @@ static inline void tiva_gptm0_synchronize(uint32_t sync)
* devpath - The full path to the timer device. This should be of the form
* /dev/timer0
* gptm - General purpose timer number
* timeout - Timeout interval in milliseconds. Set to a non-zero value
* timeout - Timeout interval in microseconds. Set to a non-zero value
* to enable timeout interrupts
* altlck - True: Use alternate clock source.
*

View File

@ -4,5 +4,76 @@
#
if ARCH_BOARD_DK_TM4C129X
if TIMER && TIVA_TIMER32_PERIODIC
endif
config DK_TM4C129X_TIMER
bool
default n
choice
prompt "Timer driver selection"
default DK_TM4C129X_TIMER_NONE
config DK_TM4C129X_TIMER_NONE
bool "None"
config DK_TM4C129X_TIMER0
bool "Timer 0"
depends on TIVA_TIMER0
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER1
bool "Timer 1"
depends on TIVA_TIMER1
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER2
bool "Timer 2"
depends on TIVA_TIMER2
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER3
bool "Timer 3"
depends on TIVA_TIMER3
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER4
bool "Timer 4"
depends on TIVA_TIMER4
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER5
bool "Timer 5"
depends on TIVA_TIMER5
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER6
bool "Timer 6"
depends on TIVA_TIMER6
select DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER7
bool "Timer 7"
depends on TIVA_TIMER7
select DK_TM4C129X_TIMER
endchoice # Timer driver selection
if DK_TM4C129X_TIMER
config DK_TM4C129X_TIMER_DEVNAME
string "Timer device name"
default "/dev/timer0"
config DK_TM4C129X_TIMER_TIMEOUT
int "Timer interval (microseconds)"
default 10000
config DK_TM4C129X_TIMER_ALTCLK
bool "Use alternate clock source"
default n
depends on EXPERIMENTAL
endif # DK_TM4C129X_TIMER
endif # TIVA_TIMER32_PERIODIC
endif # ARCH_BOARD_DK_TM4C129X

View File

@ -55,6 +55,10 @@ ifeq ($(CONFIG_TIVA_ETHERNET),y)
CSRCS += tm4c_ethernet.c
endif
ifeq ($(CONFIG_DK_TM4C129X_TIMER),y)
CSRCS += tm4c_timer.c
endif
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += tm4c_nsh.c
endif

View File

@ -169,6 +169,18 @@ void tm4c_ledinit(void);
int tm4c_bringup(void);
/****************************************************************************
* Name: tiva_timer_initialize
*
* Description:
* Configure the timer driver
*
****************************************************************************/
#ifdef CONFIG_DK_TM4C129X_TIMER
int tiva_timer_initialize(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_DK_TM4C129X_DK_TM4C129X_H */

View File

@ -49,6 +49,14 @@
* Pre-Processor Definitions
****************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_TIVA_I2C6)
# define HAVE_TMP100
#endif
#ifdef CONFIG_DK_TM4C129X_TIMER
# define HAVE_TIMER
#endif
#ifdef CONFIG_SYSTEM_LM75_DEVNAME
# define TMP100_DEVNAME CONFIG_SYSTEM_LM75_DEVNAME
#else
@ -69,9 +77,11 @@
int tm4c_bringup(void)
{
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_TIVA_I2C6)
#if defined(HAVE_TMP100) || defined(HAVE_TIMER)
int ret;
#endif
#ifdef HAVE_TMP100
/* Initialize and register the TMP-100 Temperature Sensor driver. */
ret = tiva_tmp100_initialize(TMP100_DEVNAME);
@ -81,5 +91,15 @@ int tm4c_bringup(void)
}
#endif
#ifdef HAVE_TIMER
/* Initialize the timer driver */
ret = tiva_timer_initialize();
if (ret < 0)
{
dbg("ERROR: Failed to initialize timer driver: %d\n", ret);
}
#endif
return OK;
}

View File

@ -45,7 +45,6 @@
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -0,0 +1,122 @@
/****************************************************************************
* config/dk-tm4c129x/src/tm4c_timer.c
*
* Copyright (C) 2015 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include "tiva_timer.h"
#include "dk-tm4c129x.h"
#ifdef CONFIG_DK_TM4C129X_TIMER
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_TIMER
# error CONFIG_TIMER is not defined
#endif
#ifndef CONFIG_TIVA_TIMER32_PERIODIC
# error CONFIG_TIVA_TIMER32_PERIODIC is not defined
#endif
#if defined(CONFIG_DK_TM4C129X_TIMER0)
# define GPTM 0
#elif defined(CONFIG_DK_TM4C129X_TIMER1)
# define GPTM 1
#elif defined(CONFIG_DK_TM4C129X_TIMER2)
# define GPTM 2
#elif defined(CONFIG_DK_TM4C129X_TIMER3)
# define GPTM 3
#elif defined(CONFIG_DK_TM4C129X_TIMER4)
# define GPTM 4
#elif defined(CONFIG_DK_TM4C129X_TIMER5)
# define GPTM 5
#elif defined(CONFIG_DK_TM4C129X_TIMER6)
# define GPTM 6
#elif defined(CONFIG_DK_TM4C129X_TIMER7)
# define GPTM 7
#else
# error No CONFIG_DK_TM4C129X_TIMERn definition
#endif
#ifndef CONFIG_DK_TM4C129X_TIMER_DEVNAME
# define CONFIG_DK_TM4C129X_TIMER_DEVNAME "/dev/timer0"
#endif
#ifndef CONFIG_DK_TM4C129X_TIMER_TIMEOUT
# define CONFIG_DK_TM4C129X_TIMER_TIMEOUT 10000
#endif
#undef CONFIG_DK_TM4C129X_TIMER_ALTCLK
#define ALTCLK false
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: tiva_timer_initialize
*
* Description:
* Configure the timer driver
*
****************************************************************************/
int tiva_timer_initialize(void)
{
int ret;
timvdbg("Registering TIMER%d at %s\n", GPTM, CONFIG_DK_TM4C129X_TIMER_DEVNAME);
timvdbg("Initial timer period: %d uS\n", CONFIG_DK_TM4C129X_TIMER_TIMEOUT);
ret = tiva_timer_register(CONFIG_DK_TM4C129X_TIMER_DEVNAME, GPTM,
CONFIG_DK_TM4C129X_TIMER_TIMEOUT, ALTCLK);
if (ret < 0)
{
timdbg("ERROR: Failed to register timer driver: %d\n", ret);
}
return ret;
}
#endif /* CONFIG_DK_TM4C129X_TIMER */