summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/sh/sh7032/clock
diff options
context:
space:
mode:
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;