[U-Boot] [PATCH 16/28] nios2: move timer handler from interrupt.c to timer.c
Thomas Chou
thomas at wytron.com.tw
Fri Mar 19 08:43:41 CET 2010
This patch move the timer handler from interrupt.c to timer.c.
It will be cleaner to seperate time management from interrupt
management.
The registers access is changed from "volatile struct" to readl()/
writel(). This is consistent with Altera HAL and Linux.
The cpu/nios2/Makefile is updated with the removal of serial.c and
epcs.c, as the serial drivers are moved to drivers/serial/ and the
epcs flash is supported with altera_spi and spi_flash drivers.
Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
---
cpu/nios2/Makefile | 2 +-
cpu/nios2/interrupts.c | 64 +------------------------------
cpu/nios2/timer.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 63 deletions(-)
create mode 100644 cpu/nios2/timer.c
diff --git a/cpu/nios2/Makefile b/cpu/nios2/Makefile
index 75f30b4..9ced9dd 100644
--- a/cpu/nios2/Makefile
+++ b/cpu/nios2/Makefile
@@ -27,7 +27,7 @@ LIB = $(obj)lib$(CPU).a
START = start.o
SOBJS = exceptions.o
-COBJS = cpu.o interrupts.o serial.o sysid.o traps.o epcs.o
+COBJS = cpu.o interrupts.o sysid.o traps.o timer.o
SRCS := $(START:.o=.S) $(SOBJS:.o=.S) $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
diff --git a/cpu/nios2/interrupts.c b/cpu/nios2/interrupts.c
index 1c3566e..8becf09 100644
--- a/cpu/nios2/interrupts.c
+++ b/cpu/nios2/interrupts.c
@@ -37,10 +37,6 @@
#include <status_led.h>
#endif
-#if defined(CONFIG_SYS_NIOS_TMRBASE) && !defined(CONFIG_SYS_NIOS_TMRIRQ)
-#error CONFIG_SYS_NIOS_TMRIRQ not defined (see documentation)
-#endif
-
/****************************************************************************/
struct irq_action {
@@ -52,62 +48,6 @@ struct irq_action {
static struct irq_action vecs[32];
/*************************************************************************/
-volatile ulong timestamp = 0;
-
-void reset_timer (void)
-{
- timestamp = 0;
-}
-
-ulong get_timer (ulong base)
-{
- WATCHDOG_RESET ();
- return (timestamp - base);
-}
-
-void set_timer (ulong t)
-{
- timestamp = t;
-}
-
-
-/* The board must handle this interrupt if a timer is not
- * provided.
- */
-#if defined(CONFIG_SYS_NIOS_TMRBASE)
-void tmr_isr (void *arg)
-{
- nios_timer_t *tmr = (nios_timer_t *)arg;
- /* Interrupt is cleared by writing anything to the
- * status register.
- */
- writel (&tmr->status, 0);
- timestamp += CONFIG_SYS_NIOS_TMRMS;
-#ifdef CONFIG_STATUS_LED
- status_led_tick(timestamp);
-#endif
-}
-
-static void tmr_init (void)
-{
- nios_timer_t *tmr =(nios_timer_t *)CONFIG_SYS_NIOS_TMRBASE;
-
- writel (&tmr->status, 0);
- writel (&tmr->control, 0);
- writel (&tmr->control, NIOS_TIMER_STOP);
-
-#if defined(CONFIG_SYS_NIOS_TMRCNT)
- writel (&tmr->periodl, CONFIG_SYS_NIOS_TMRCNT & 0xffff);
- writel (&tmr->periodh, (CONFIG_SYS_NIOS_TMRCNT >> 16) & 0xffff);
-#endif
- writel (&tmr->control, NIOS_TIMER_ITO | NIOS_TIMER_CONT |
- NIOS_TIMER_START );
- irq_install_handler (CONFIG_SYS_NIOS_TMRIRQ, tmr_isr, (void *)tmr);
-}
-
-#endif /* CONFIG_SYS_NIOS_TMRBASE */
-
-/*************************************************************************/
int disable_interrupts (void)
{
int val = rdctl (CTL_STATUS);
@@ -195,8 +135,8 @@ int interrupt_init (void)
vecs[i].count = 0;
}
-#if defined(CONFIG_SYS_NIOS_TMRBASE)
- tmr_init ();
+#if defined(CONFIG_SYS_TIMER_BASE)
+ timer_init ();
#endif
enable_interrupts ();
diff --git a/cpu/nios2/timer.c b/cpu/nios2/timer.c
new file mode 100644
index 0000000..354da51
--- /dev/null
+++ b/cpu/nios2/timer.c
@@ -0,0 +1,98 @@
+/*
+ * (C) Copyright 2000-2002
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcnutt at psyent.com>
+ * (C) Copyright 2010, Thomas Chou <thomas at wytron.com.tw>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <asm/io.h>
+
+#define ALTERA_TIMER_PERIOD ((CONFIG_SYS_TIMER_FREQ / CONFIG_SYS_HZ) - 1)
+
+#define ALTERA_TIMER_STATUS_REG 0
+#define ALTERA_TIMER_CONTROL_REG 4
+#define ALTERA_TIMER_PERIODL_REG 8
+#define ALTERA_TIMER_PERIODH_REG 12
+#define ALTERA_TIMER_SNAPL_REG 16
+#define ALTERA_TIMER_SNAPH_REG 20
+
+#define ALTERA_TIMER_CONTROL_ITO_MSK (0x1)
+#define ALTERA_TIMER_CONTROL_CONT_MSK (0x2)
+#define ALTERA_TIMER_CONTROL_START_MSK (0x4)
+#define ALTERA_TIMER_CONTROL_STOP_MSK (0x8)
+
+static volatile ulong timestamp;
+
+void reset_timer(void)
+{
+ timestamp = 0;
+}
+
+ulong get_timer(ulong base)
+{
+ WATCHDOG_RESET();
+ return timestamp - base;
+}
+
+void set_timer(ulong t)
+{
+ timestamp = t;
+}
+
+/* The board must handle this interrupt if a timer is not
+ * provided.
+ */
+#if defined(CONFIG_SYS_TIMER_BASE)
+
+static void timer_isr(void *arg)
+{
+ /* Interrupt is cleared by writing anything to the
+ * status register.
+ */
+ writew(0, CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_STATUS_REG);
+ timestamp++;
+#ifdef CONFIG_STATUS_LED
+ status_led_tick(timestamp);
+#endif
+}
+
+void timer_init(void)
+{
+ writew(ALTERA_TIMER_CONTROL_STOP_MSK,
+ CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_CONTROL_REG);
+ writew(0, CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_STATUS_REG);
+ /* set timer period */
+ writew(ALTERA_TIMER_PERIOD,
+ CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_PERIODL_REG);
+ writew(ALTERA_TIMER_PERIOD >> 16,
+ CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_PERIODH_REG);
+ /* interrupt enable + continuous + start */
+ writew(ALTERA_TIMER_CONTROL_ITO_MSK | ALTERA_TIMER_CONTROL_CONT_MSK |
+ ALTERA_TIMER_CONTROL_START_MSK,
+ CONFIG_SYS_TIMER_BASE + ALTERA_TIMER_CONTROL_REG);
+
+ irq_install_handler(CONFIG_SYS_TIMER_IRQ, timer_isr, NULL);
+}
+
+#endif /* CONFIG_SYS_TIMER_BASE */
--
1.6.6.1
More information about the U-Boot
mailing list