summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/sh/sh7032/timer
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-03-20 17:20:45 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-03-20 17:20:45 +0000
commitf8b27df985a1c65b329164fe1f57ca348fe862c1 (patch)
tree71966dab41fe483c6b830876bacc761902465a62 /c/src/lib/libcpu/sh/sh7032/timer
parentSH port submitted from Ralf Corsepius <corsepiu@faw.uni-ulm.de>. (diff)
downloadrtems-f8b27df985a1c65b329164fe1f57ca348fe862c1.tar.bz2
New port from Ralf Corsepius <corsepiu@faw.uni-ulm.de>.
Diffstat (limited to 'c/src/lib/libcpu/sh/sh7032/timer')
-rw-r--r--c/src/lib/libcpu/sh/sh7032/timer/Makefile.in60
-rw-r--r--c/src/lib/libcpu/sh/sh7032/timer/timer.c204
2 files changed, 264 insertions, 0 deletions
diff --git a/c/src/lib/libcpu/sh/sh7032/timer/Makefile.in b/c/src/lib/libcpu/sh/sh7032/timer/Makefile.in
new file mode 100644
index 0000000000..8fb56cf938
--- /dev/null
+++ b/c/src/lib/libcpu/sh/sh7032/timer/Makefile.in
@@ -0,0 +1,60 @@
+#
+# $Id$
+#
+
+@SET_MAKE@
+srcdir = @srcdir@
+VPATH=@srcdir@
+RTEMS_ROOT = @top_srcdir@
+PROJECT_ROOT = @PROJECT_ROOT@
+
+PGM=${ARCH}/timer.rel
+
+# C source names, if any, go here -- minus the .c
+C_PIECES=timer
+C_FILES=$(C_PIECES:%=%.c)
+C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
+
+H_FILES=
+
+# Assembly source names, if any, go here -- minus the .s
+S_PIECES=
+S_FILES=$(S_PIECES:%=%.s)
+S_O_FILES=$(S_FILES:%.s=${ARCH}/%.o)
+
+SRCS=$(C_FILES) $(H_FILES) $(S_FILES)
+OBJS=$(C_O_FILES) $(S_O_FILES)
+
+include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
+include $(RTEMS_ROOT)/make/leaf.cfg
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+DEFINES +=
+CPPFLAGS +=
+CFLAGS +=
+
+LD_PATHS +=
+LD_LIBS +=
+LDFLAGS +=
+
+#
+# Add your list of files to delete here. The config files
+# already know how to delete some stuff, so you may want
+# to just run 'make clean' first to see what gets missed.
+# 'make clobber' already includes 'make clean'
+#
+
+CLEAN_ADDITIONS +=
+CLOBBER_ADDITIONS +=
+
+${PGM}: ${SRCS} ${OBJS}
+ $(make-rel)
+
+all: ${ARCH} $(SRCS) $(PGM)
+
+# the .rel file built here will be put into libbsp.a by
+# libbsp/sh/BSP/Makefile
+install: all
diff --git a/c/src/lib/libcpu/sh/sh7032/timer/timer.c b/c/src/lib/libcpu/sh/sh7032/timer/timer.c
new file mode 100644
index 0000000000..8aa6cb9b27
--- /dev/null
+++ b/c/src/lib/libcpu/sh/sh7032/timer/timer.c
@@ -0,0 +1,204 @@
+/*
+ * timer for the Hitachi SH 703X
+ *
+ * This file manages the benchmark timer used by the RTEMS Timing Test
+ * Suite. Each measured time period is demarcated by calls to
+ * Timer_initialize() and Read_timer(). Read_timer() usually returns
+ * the number of microseconds since Timer_initialize() exitted.
+ *
+ * NOTE: It is important that the timer start/stop overhead be
+ * determined when porting or modifying this code.
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * 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.
+ *
+ * COPYRIGHT (c) 1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+
+#include <rtems/score/sh_io.h>
+#include <rtems/score/iosh7030.h>
+
+/*
+ * We use a Phi/4 timer
+ */
+#define SCALE (MHZ/4)
+
+#define ITU1_STARTMASK 0xfd
+#define ITU1_SYNCMASK 0xfd
+#define ITU1_MODEMASK 0xfd
+#define ITU1_TCRMASK 0x02
+#define ITU1_TIORMASK 0x88
+#define ITU1_STAT_MASK 0xf8
+#define ITU1_TIERMASK 0xfc
+#define IPRC_ITU1_MASK 0xfff0
+
+#ifndef ITU1_PRIO
+#define ITU1_PRIO 15
+#endif
+
+#define ITU1_VECTOR 86
+
+rtems_isr timerisr();
+
+static rtems_unsigned32 Timer_interrupts;
+
+rtems_boolean Timer_driver_Find_average_overhead;
+
+void Timer_initialize( void )
+{
+ rtems_unsigned8 temp8;
+ rtems_unsigned16 temp16;
+ rtems_unsigned32 level;
+ rtems_isr* ignored;
+
+ /*
+ * Timer has never overflowed. This may not be necessary on some
+ * implemenations of timer but ....
+ */
+
+ Timer_interrupts /* .i */ = 0;
+ _CPU_ISR_Disable( level);
+
+ /*
+ * Somehow start the timer
+ */
+ /* stop Timer 1 */
+ temp8 = read8( ITU_TSTR) & ITU1_STARTMASK;
+ write8( temp8, ITU_TSTR);
+
+ /* initialize counter 1 */
+ write16( 0, ITU_TCNT1);
+
+ /* Timer 1 is independent of other timers */
+ temp8 = read8( ITU_TSNC) & ITU1_SYNCMASK;
+ write8( temp8, ITU_TSNC);
+
+ /* Timer 1, normal mode */
+ temp8 = read8( ITU_TMDR) & ITU1_MODEMASK;
+ write8( temp8, ITU_TMDR);
+
+ /* x0000000
+ * |||||+++--- Internal Clock
+ * |||++------ Count on rising edge
+ * |++-------- disable TCNT clear
+ * +---------- don`t care
+ */
+ write8( ITU1_TCRMASK, ITU_TCR1);
+
+ /* gra and grb are not used */
+ write8( ITU1_TIORMASK, ITU_TIOR1);
+
+ /* reset all status flags */
+ temp8 = read8( ITU_TSR1) & ITU1_STAT_MASK;
+ write8( temp8, ITU_TSR1);
+
+ /* enable overflow interrupt */
+ write8( ITU1_TIERMASK, ITU_TIER1);
+
+ /* set interrupt priority */
+ temp16 = read16( INTC_IPRC) & IPRC_ITU1_MASK;
+ temp16 |= ITU1_PRIO;
+ write16( temp16, INTC_IPRC);
+
+ /* initialize ISR */
+ ignored = set_vector( timerisr, ITU1_VECTOR, 0);
+ _CPU_ISR_Enable( level);
+
+ /* start timer 1 */
+ temp8 = read8( ITU_TSTR) | ~ITU1_STARTMASK;
+ write8( temp8, ITU_TSTR);
+}
+
+/*
+ * The following controls the behavior of Read_timer().
+ *
+ * AVG_OVERHEAD is the overhead for starting and stopping the timer. It
+ * is usually deducted from the number returned.
+ *
+ * LEAST_VALID is the lowest number this routine should trust. Numbers
+ * below this are "noise" and zero is returned.
+ */
+
+#define AVG_OVERHEAD 1 /* It typically takes X.X microseconds */
+ /* (Y countdowns) to start/stop the timer. */
+ /* This value is in microseconds. */
+#define LEAST_VALID 0 /* 20 */ /* Don't trust a clicks value lower than this */
+
+int Read_timer( void )
+{
+ rtems_unsigned32 clicks;
+ rtems_unsigned32 total ;
+ /*
+ * Read the timer and see how many clicks it has been since we started.
+ */
+
+
+ clicks = read16( ITU_TCNT1); /* XXX: read some HW here */
+
+ /*
+ * Total is calculated by taking into account the number of timer overflow
+ * interrupts since the timer was initialized and clicks since the last
+ * interrupts.
+ */
+
+ total = clicks + Timer_interrupts * 65536 ;
+
+ if ( Timer_driver_Find_average_overhead )
+ return total / SCALE; /* in XXX microsecond units */
+ else
+ {
+ if ( total < LEAST_VALID )
+ return 0; /* below timer resolution */
+ /*
+ * Somehow convert total into microseconds
+ */
+ return (total / SCALE - AVG_OVERHEAD) ;
+ }
+}
+
+/*
+ * Empty function call used in loops to measure basic cost of looping
+ * in Timing Test Suite.
+ */
+
+rtems_status_code Empty_function( void )
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+void Set_find_average_overhead(
+ rtems_boolean find_flag
+)
+{
+ Timer_driver_Find_average_overhead = find_flag;
+}
+
+/* Timer 1 is used */
+
+#pragma interrupt
+void timerisr( void )
+{
+ unsigned8 temp8;
+
+ /* reset the flags of the status register */
+ temp8 = read8( ITU_TSR1) & ITU1_STAT_MASK;
+ write8( temp8, ITU_TSR1);
+
+ Timer_interrupts += 1;
+}