summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/sh/sh7032/timer/timer.c
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/timer/timer.c
parentCorrected to include extra arguments for simulators on sparc (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/timer/timer.c')
-rw-r--r--c/src/lib/libcpu/sh/sh7032/timer/timer.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/c/src/lib/libcpu/sh/sh7032/timer/timer.c b/c/src/lib/libcpu/sh/sh7032/timer/timer.c
index 03ffdd7e56..9dd57a4bb4 100644
--- a/c/src/lib/libcpu/sh/sh7032/timer/timer.c
+++ b/c/src/lib/libcpu/sh/sh7032/timer/timer.c
@@ -32,17 +32,26 @@
#include <rtems.h>
#include <rtems/score/sh_io.h>
-#include <rtems/score/iosh7030.h>
+#include <rtems/score/ispsh7032.h>
+#include <rtems/score/iosh7032.h>
+
+#define I_CLK_PHI_1 0
+#define I_CLK_PHI_2 1
+#define I_CLK_PHI_4 2
+#define I_CLK_PHI_8 3
/*
- * We use a Phi/4 timer
+ * Set I_CLK_PHI to one of the I_CLK_PHI_X values from above to choose
+ * a PHI/X clock rate.
*/
-#define SCALE (MHZ/4)
+
+#define I_CLK_PHI I_CLK_PHI_4
+#define CLOCK_SCALE (1<<I_CLK_PHI)
#define ITU1_STARTMASK 0xfd
#define ITU1_SYNCMASK 0xfd
#define ITU1_MODEMASK 0xfd
-#define ITU1_TCRMASK 0x02
+#define ITU1_TCRMASK (0x00 | I_CLK_PHI)
#define ITU1_TIORMASK 0x88
#define ITU1_STAT_MASK 0xf8
#define ITU1_TIERMASK 0xfc
@@ -52,7 +61,7 @@
#define ITU1_PRIO 15
#endif
-#define ITU1_VECTOR 86
+#define ITU1_VECTOR OVI1_ISP_V
rtems_isr timerisr();
@@ -60,6 +69,8 @@ static rtems_unsigned32 Timer_interrupts;
rtems_boolean Timer_driver_Find_average_overhead;
+static rtems_unsigned32 Timer_HZ ;
+
void Timer_initialize( void )
{
rtems_unsigned8 temp8;
@@ -67,6 +78,8 @@ void Timer_initialize( void )
rtems_unsigned32 level;
rtems_isr *ignored;
+ Timer_HZ = rtems_cpu_configuration_get_clicks_per_second() / CLOCK_SCALE ;
+
/*
* Timer has never overflowed. This may not be necessary on some
* implemenations of timer but ....
@@ -93,12 +106,7 @@ void Timer_initialize( void )
temp8 = read8( ITU_TMDR) & ITU1_MODEMASK;
write8( temp8, ITU_TMDR);
- /* x0000000
- * |||||+++--- Internal Clock
- * |||++------ Count on rising edge
- * |++-------- disable TCNT clear
- * +---------- don`t care
- */
+ /* Use a Phi/X counter */
write8( ITU1_TCRMASK, ITU_TCR1);
/* gra and grb are not used */
@@ -142,14 +150,14 @@ void Timer_initialize( void )
int Read_timer( void )
{
- rtems_unsigned32 clicks;
+ rtems_unsigned32 cclicks;
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 */
+ cclicks = read16( ITU_TCNT1); /* XXX: read some HW here */
/*
* Total is calculated by taking into account the number of timer overflow
@@ -157,10 +165,10 @@ int Read_timer( void )
* interrupts.
*/
- total = clicks + Timer_interrupts * 65536 ;
+ total = cclicks + Timer_interrupts * 65536 ;
if ( Timer_driver_Find_average_overhead )
- return total / SCALE; /* in XXX microsecond units */
+ return total / CLOCK_SCALE; /* in XXX microsecond units */
else
{
if ( total < LEAST_VALID )
@@ -168,7 +176,7 @@ int Read_timer( void )
/*
* Somehow convert total into microseconds
*/
- return (total / SCALE - AVG_OVERHEAD) ;
+ return (total / CLOCK_SCALE - AVG_OVERHEAD) ;
}
}