From 4a238002e71ec018723229f8669363a5ffb7302e Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 18 Nov 1999 21:22:58 +0000 Subject: Patch from "John M. Mills" with subsequent cleanup from Ralf Corsepius 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//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 --- c/src/lib/libcpu/sh/sh7032/clock/Makefile.in | 2 +- c/src/lib/libcpu/sh/sh7032/clock/ckinit.c | 94 +++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 10 deletions(-) (limited to 'c/src/lib/libcpu/sh/sh7032/clock') 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,25 +29,85 @@ #include #include #include -#include -#include - -#define _ITU_COUNTER0_MICROSECOND (MHZ/4) +#include +#include #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< 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; -- cgit v1.2.3