summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/sh/sh7032/clock
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-11-18 21:22:58 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-11-18 21:22:58 +0000
commit4a238002e71ec018723229f8669363a5ffb7302e (patch)
treefc5a57faf9a30225bd1f3fa2d713b85815cb77ef /c/src/lib/libcpu/sh/sh7032/clock
parent5503d75c00d94d2e0b7677d137c38a44e19d725e (diff)
downloadrtems-4a238002e71ec018723229f8669363a5ffb7302e.tar.bz2
Patch from "John M. Mills" <jmills@tga.com> with subsequent cleanup from
Ralf Corsepius <corsepiu@faw.uni-ulm.de> that adds initial Hitachi SH-2 support to RTEMS. Ralf's comments are: Changes: ------ 1. SH-Port: * Many files renamed. * CONSOLE_DEVNAME and MHZ defines removed from libcpu. * console.c moved to libbsp/sh/shared, build in libbsp/sh/<BSP>/console applying VPATH. * CONSOLE_DEVNAME made BSP-specific, replacement is defined in bsp.h * MHZ define replaced with HZ (extendent resolution) in custom/*.cfg * -DHZ=HZ used in bspstart.c, only * Makefile variable HZ used in bsp-dependent directories only. 2. SH1-Port * clock-driver rewritten to provide better resolution for odd CPU frequencies. This driver is only partially tested on hardware, ie. sightly experimental, but I don't expect severe problems with it. * Polling SCI-driver added. This driver is experimental and completly untested yet. Therefore it is not yet used for the console (/dev/console is still pointing to /dev/null, cf. gensh1/bsp.h). * minor changes to the timer driver * SH1 specific delay()/CPU_delay() now is implemented as a function 3. SH2-Port * Merged * IMO, the code is still in its infancy. Therefore I have interspersed comments (FIXME) it for items which I think John should look after. * sci and console drivers partially rewritten and extended (John, I hope you don't mind). * Copyright notices are not yet adapted
Diffstat (limited to 'c/src/lib/libcpu/sh/sh7032/clock')
-rw-r--r--c/src/lib/libcpu/sh/sh7032/clock/Makefile.in2
-rw-r--r--c/src/lib/libcpu/sh/sh7032/clock/ckinit.c94
2 files changed, 86 insertions, 10 deletions
diff --git a/c/src/lib/libcpu/sh/sh7032/clock/Makefile.in b/c/src/lib/libcpu/sh/sh7032/clock/Makefile.in
index c9bd2ac92d..5617ae594e 100644
--- a/c/src/lib/libcpu/sh/sh7032/clock/Makefile.in
+++ b/c/src/lib/libcpu/sh/sh7032/clock/Makefile.in
@@ -40,7 +40,7 @@ INSTALL_CHANGE = @INSTALL_CHANGE@
#
DEFINES +=
-CPPFLAGS += -DMHZ=$(MHZ)
+CPPFLAGS +=
CFLAGS += $(CFLAGS_OS_V)
LD_PATHS +=
diff --git a/c/src/lib/libcpu/sh/sh7032/clock/ckinit.c b/c/src/lib/libcpu/sh/sh7032/clock/ckinit.c
index 7aef64ed99..a8acc1ca20 100644
--- a/c/src/lib/libcpu/sh/sh7032/clock/ckinit.c
+++ b/c/src/lib/libcpu/sh/sh7032/clock/ckinit.c
@@ -29,19 +29,30 @@
#include <rtems/libio.h>
#include <rtems/score/sh_io.h>
#include <rtems/score/sh.h>
-#include <rtems/score/cpu_isps.h>
-#include <rtems/score/iosh7030.h>
-
-#define _ITU_COUNTER0_MICROSECOND (MHZ/4)
+#include <rtems/score/ispsh7032.h>
+#include <rtems/score/iosh7032.h>
#ifndef CLOCKPRIO
#define CLOCKPRIO 10
#endif
+#define I_CLK_PHI_1 0
+#define I_CLK_PHI_2 1
+#define I_CLK_PHI_4 2
+#define I_CLK_PHI_8 3
+
+/*
+ * Set I_CLK_PHI to one of the I_CLK_PHI_X values from above to choose
+ * a PHI/X clock rate.
+ */
+
+#define I_CLK_PHI I_CLK_PHI_4
+#define CLOCK_SCALE (1<<I_CLK_PHI)
+
#define ITU0_STARTMASK 0xfe
#define ITU0_SYNCMASK 0xfe
#define ITU0_MODEMASK 0xfe
-#define ITU0_TCRMASK 0x22
+#define ITU0_TCRMASK (0x20 | I_CLK_PHI)
#define ITU_STAT_MASK 0xf8
#define ITU0_IRQMASK 0xfe
#define ITU0_TIERMASK 0x01
@@ -49,6 +60,55 @@
#define ITU0_TIORVAL 0x08
/*
+ * clicks_per_tick := clicks_per_sec * usec_per_tick
+ *
+ * This is a very expensive function ;-)
+ *
+ * Below are two variants:
+ * 1. A variant applying integer arithmetics, only.
+ * 2. A variant applying floating point arithmetics
+ *
+ * The floating point variant pulls in the fmath routines when linking,
+ * resulting in slightly larger executables for applications that do not
+ * apply fmath otherwise. However, the imath variant is significantly slower
+ * than the fmath variant and more complex.
+ *
+ * Assuming that most applications will not use fmath, but are critical
+ * in memory size constraints, we apply the integer variant.
+ *
+ * To the sake of simplicity, we might abandon one of both variants in
+ * future.
+ */
+static unsigned int sh_clicks_per_tick(
+ unsigned int clicks_per_sec,
+ unsigned int usec_per_tick )
+{
+#if 1
+ unsigned int clicks_per_tick = 0 ;
+
+ unsigned int b = clicks_per_sec ;
+ unsigned int c = 1000000 ;
+ unsigned int d = 1 ;
+ unsigned int a = ( ( b / c ) * usec_per_tick ) / d;
+
+ clicks_per_tick += a ;
+
+ while ( ( b %= c ) > 0 )
+ {
+ c /= 10 ;
+ d *= 10 ;
+ a = ( ( b / c ) * usec_per_tick ) / d ;
+ clicks_per_tick += a ;
+ }
+ return clicks_per_tick ;
+#else
+ double fclicks_per_tick =
+ ((double) clicks_per_sec * (double) usec_per_tick) / 1000000.0 ;
+ return (unsigned32) fclicks_per_tick ;
+#endif
+}
+
+/*
* The interrupt vector number associated with the clock tick device
* driver.
*/
@@ -100,7 +160,6 @@ rtems_isr Clock_isr(
/*
* bump the number of clock driver ticks since initialization
*
-
* determine if it is time to announce the passing of tick as configured
* to RTEMS through the rtems_clock_tick directive
*
@@ -137,13 +196,31 @@ void Install_clock(
)
{
unsigned8 temp8 = 0;
+ unsigned32 microseconds_per_tick ;
+ unsigned32 cclicks_per_tick ;
+ unsigned16 Clock_limit ;
/*
* Initialize the clock tick device driver variables
*/
Clock_driver_ticks = 0;
- Clock_isrs_const = rtems_configuration_get_microseconds_per_tick() / 10000;
+
+ if ( rtems_configuration_get_microseconds_per_tick() != 0 )
+ microseconds_per_tick = rtems_configuration_get_microseconds_per_tick() ;
+ else
+ microseconds_per_tick = 10000 ; /* 10000 us */
+
+ /* clock clicks per tick */
+ cclicks_per_tick =
+ sh_clicks_per_tick(
+ rtems_cpu_configuration_get_clicks_per_second() / CLOCK_SCALE,
+ microseconds_per_tick );
+
+ Clock_isrs_const = cclicks_per_tick >> 16 ;
+ if ( ( cclicks_per_tick | 0xffff ) > 0 )
+ Clock_isrs_const++ ;
+ Clock_limit = cclicks_per_tick / Clock_isrs_const ;
Clock_isrs = Clock_isrs_const;
/*
@@ -191,8 +268,7 @@ void Install_clock(
rtems_fatal_error_occurred( RTEMS_NOT_CONFIGURED);
/* set counter limits */
- write16( _ITU_COUNTER0_MICROSECOND * rtems_configuration_get_microseconds_per_tick(),
- ITU_GRA0);
+ write16( Clock_limit, ITU_GRA0);
/* start counter */
temp8 = read8( ITU_TSTR) |~ITU0_STARTMASK;