Changeset 4a238002 in rtems for c/src/lib/libcpu/sh


Ignore:
Timestamp:
Nov 18, 1999, 9:22:58 PM (21 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
97c465c
Parents:
5503d75
Message:

Patch from "John M. Mills" <jmills@…> with subsequent cleanup from
Ralf Corsepius <corsepiu@…> 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.
  1. 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
  1. 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
Location:
c/src/lib/libcpu/sh
Files:
20 added
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libcpu/sh/sh7032/Makefile.in

    r5503d75 r4a238002  
    1919INSTALL_CHANGE = @INSTALL_CHANGE@
    2020
    21 SUB_DIRS = include clock console timer null
     21SUB_DIRS = include clock timer null sci delay
    2222
    2323Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • c/src/lib/libcpu/sh/sh7032/clock/Makefile.in

    r5503d75 r4a238002  
    4141
    4242DEFINES +=
    43 CPPFLAGS += -DMHZ=$(MHZ)
     43CPPFLAGS +=
    4444CFLAGS += $(CFLAGS_OS_V)
    4545
  • c/src/lib/libcpu/sh/sh7032/clock/ckinit.c

    r5503d75 r4a238002  
    3030#include <rtems/score/sh_io.h>
    3131#include <rtems/score/sh.h>
    32 #include <rtems/score/cpu_isps.h>
    33 #include <rtems/score/iosh7030.h>
    34 
    35 #define _ITU_COUNTER0_MICROSECOND (MHZ/4)
     32#include <rtems/score/ispsh7032.h>
     33#include <rtems/score/iosh7032.h>
    3634
    3735#ifndef CLOCKPRIO
     
    3937#endif
    4038
     39#define I_CLK_PHI_1     0
     40#define I_CLK_PHI_2     1
     41#define I_CLK_PHI_4     2
     42#define I_CLK_PHI_8     3
     43
     44/*
     45 * Set I_CLK_PHI to one of the I_CLK_PHI_X values from above to choose
     46 * a PHI/X clock rate.
     47 */
     48 
     49#define I_CLK_PHI       I_CLK_PHI_4
     50#define CLOCK_SCALE     (1<<I_CLK_PHI)
     51
    4152#define ITU0_STARTMASK  0xfe
    4253#define ITU0_SYNCMASK   0xfe
    4354#define ITU0_MODEMASK   0xfe
    44 #define ITU0_TCRMASK    0x22
     55#define ITU0_TCRMASK    (0x20 | I_CLK_PHI)
    4556#define ITU_STAT_MASK   0xf8
    4657#define ITU0_IRQMASK    0xfe
     
    5061
    5162/*
     63 * clicks_per_tick := clicks_per_sec * usec_per_tick
     64 *
     65 * This is a very expensive function ;-)
     66 *
     67 * Below are two variants:
     68 * 1. A variant applying integer arithmetics, only.
     69 * 2. A variant applying floating point arithmetics
     70 *
     71 * The floating point variant pulls in the fmath routines when linking,
     72 * resulting in slightly larger executables for applications that do not
     73 * apply fmath otherwise. However, the imath variant is significantly slower
     74 * than the fmath variant and more complex.
     75 *
     76 * Assuming that most applications will not use fmath, but are critical
     77 * in memory size constraints, we apply the integer variant.
     78 *
     79 * To the sake of simplicity, we might abandon one of both variants in
     80 * future.
     81 */
     82static unsigned int sh_clicks_per_tick(
     83  unsigned int clicks_per_sec,
     84  unsigned int usec_per_tick )
     85{
     86#if 1
     87  unsigned int clicks_per_tick = 0 ;
     88 
     89  unsigned int b = clicks_per_sec ;
     90  unsigned int c = 1000000 ;
     91  unsigned int d = 1 ;
     92  unsigned int a = ( ( b / c ) * usec_per_tick ) / d;
     93
     94  clicks_per_tick += a ;
     95
     96  while ( ( b %= c ) > 0 )
     97  {
     98    c /= 10 ;
     99    d *= 10 ;
     100    a = ( ( b / c ) * usec_per_tick ) / d ;
     101    clicks_per_tick += a ;
     102  }
     103  return clicks_per_tick ;
     104#else
     105  double fclicks_per_tick =
     106    ((double) clicks_per_sec * (double) usec_per_tick) / 1000000.0 ;
     107  return (unsigned32) fclicks_per_tick ;
     108#endif
     109}
     110
     111/*
    52112 *  The interrupt vector number associated with the clock tick device
    53113 *  driver.
     
    101161   * bump the number of clock driver ticks since initialization
    102162   *
    103 
    104163   * determine if it is time to announce the passing of tick as configured
    105164   * to RTEMS through the rtems_clock_tick directive
     
    138197{
    139198  unsigned8 temp8 = 0;
     199  unsigned32 microseconds_per_tick ;
     200  unsigned32 cclicks_per_tick ;
     201  unsigned16 Clock_limit ;
    140202 
    141203  /*
     
    144206
    145207  Clock_driver_ticks = 0;
    146   Clock_isrs_const = rtems_configuration_get_microseconds_per_tick() / 10000;
     208   
     209  if ( rtems_configuration_get_microseconds_per_tick() != 0 )
     210    microseconds_per_tick = rtems_configuration_get_microseconds_per_tick() ;
     211  else
     212    microseconds_per_tick = 10000 ; /* 10000 us */
     213
     214  /* clock clicks per tick */
     215  cclicks_per_tick =
     216    sh_clicks_per_tick(
     217      rtems_cpu_configuration_get_clicks_per_second() / CLOCK_SCALE,
     218      microseconds_per_tick );
     219
     220  Clock_isrs_const = cclicks_per_tick >> 16 ;
     221  if ( ( cclicks_per_tick | 0xffff ) > 0 )
     222    Clock_isrs_const++ ;
     223  Clock_limit = cclicks_per_tick / Clock_isrs_const ;
    147224  Clock_isrs = Clock_isrs_const;
    148225
     
    192269
    193270    /* set counter limits */
    194     write16( _ITU_COUNTER0_MICROSECOND * rtems_configuration_get_microseconds_per_tick(),
    195              ITU_GRA0);
     271    write16( Clock_limit, ITU_GRA0);
    196272   
    197273    /* start counter */
  • c/src/lib/libcpu/sh/sh7032/include/Makefile.in

    r5503d75 r4a238002  
    1414VPATH = @srcdir@
    1515
    16 H_FILES = $(srcdir)/ioqueue.h $(srcdir)/null.h $(srcdir)/sci.h \
    17     $(srcdir)/sh7_pfc.h $(srcdir)/sh7_sci.h
     16H_FILES = $(srcdir)/null.h $(srcdir)/sci.h  $(srcdir)/sh7_pfc.h \
     17    $(srcdir)/sh7_sci.h
    1818
    1919SRCS = $(H_FILES)
  • c/src/lib/libcpu/sh/sh7032/include/sci.h

    r5503d75 r4a238002  
    7979);
    8080
    81 /* Internal error codes */
    82 #define SH_TTY_NO_ERROR         0x2000
    83 #define SH_TTY_FRAME_ERR        0x2001
    84 #define SH_TTY_PARITY_ERR       0x2002
    85 #define SH_TTY_OVERRUN_ERR      0x2003
    86 
    8781#ifdef __cplusplus
    8882}
  • c/src/lib/libcpu/sh/sh7032/include/sh7_pfc.h

    r5503d75 r4a238002  
    2828#define _sh7_pfc_h
    2929
    30 #include <rtems/score/iosh7030.h>
     30#include <rtems/score/iosh7032.h>
    3131
    3232/*
  • c/src/lib/libcpu/sh/sh7032/include/sh7_sci.h

    r5503d75 r4a238002  
    2828#define _sh7_sci_h
    2929
    30 #include <rtems/score/iosh7030.h>
     30#include <rtems/score/iosh7032.h>
    3131
    3232/*
  • c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c

    r5503d75 r4a238002  
    4242#include <rtems/score/isr.h>
    4343#include <rtems/score/thread.h>
    44 #include <rtems/score/cpu_isps.h>
     44#include <rtems/score/sh.h>
     45
     46#if defined(sh7032)
     47#include <rtems/score/ispsh7032.h>
     48#include <rtems/score/iosh7032.h>
     49#elif defined (sh7045)
     50#include <rtems/score/ispsh7045.h>
     51#include <rtems/score/iosh7045.h>
     52#endif
     53
    4554#include <rtems/score/sh_io.h>
    46 #include <rtems/score/sh.h>
    47 #include <rtems/score/iosh7030.h>
    4855
    4956/* from cpu_isps.c */
  • c/src/lib/libcpu/sh/sh7032/score/ispsh7032.c

    r5503d75 r4a238002  
    3131#include <rtems/system.h>
    3232#include <rtems/score/shtypes.h>
    33 #include <rtems/score/cpu_isps.h>
     33#include <rtems/score/ispsh7032.h>
     34
     35#if !defined(sh7032)
     36#error Wrong CPU MODEL
     37#endif
    3438
    3539/*
    36  * This is a exception vector table
     40 * This is an exception vector table
    3741 *
    3842 * It has the same structure like the actual vector table (vectab)
  • c/src/lib/libcpu/sh/sh7032/timer/Makefile.in

    r5503d75 r4a238002  
    4141
    4242DEFINES +=
    43 CPPFLAGS += -DMHZ=$(MHZ)
     43CPPFLAGS +=
    4444CFLAGS +=
    4545
  • c/src/lib/libcpu/sh/sh7032/timer/timer.c

    r5503d75 r4a238002  
    3333
    3434#include <rtems/score/sh_io.h>
    35 #include <rtems/score/iosh7030.h>
    36 
    37 /*
    38  * We use a Phi/4 timer
    39  */
    40 #define SCALE (MHZ/4)
     35#include <rtems/score/ispsh7032.h>
     36#include <rtems/score/iosh7032.h>
     37
     38#define I_CLK_PHI_1     0
     39#define I_CLK_PHI_2     1
     40#define I_CLK_PHI_4     2
     41#define I_CLK_PHI_8     3
     42
     43/*
     44 * Set I_CLK_PHI to one of the I_CLK_PHI_X values from above to choose
     45 * a PHI/X clock rate. 
     46 */
     47   
     48#define I_CLK_PHI       I_CLK_PHI_4
     49#define CLOCK_SCALE     (1<<I_CLK_PHI)
    4150
    4251#define ITU1_STARTMASK  0xfd
    4352#define ITU1_SYNCMASK   0xfd
    4453#define ITU1_MODEMASK   0xfd
    45 #define ITU1_TCRMASK    0x02
     54#define ITU1_TCRMASK    (0x00 | I_CLK_PHI)
    4655#define ITU1_TIORMASK   0x88
    4756#define ITU1_STAT_MASK  0xf8
     
    5362#endif
    5463
    55 #define ITU1_VECTOR 86
     64#define ITU1_VECTOR OVI1_ISP_V
    5665
    5766rtems_isr timerisr();
     
    6069
    6170rtems_boolean Timer_driver_Find_average_overhead;
     71
     72static rtems_unsigned32 Timer_HZ ;
    6273
    6374void Timer_initialize( void )
     
    6879  rtems_isr        *ignored;
    6980
     81  Timer_HZ = rtems_cpu_configuration_get_clicks_per_second() / CLOCK_SCALE ;
     82
    7083  /*
    7184   *  Timer has never overflowed.  This may not be necessary on some
     
    94107  write8( temp8, ITU_TMDR);
    95108
    96   /* x0000000
    97    * |||||+++--- Internal Clock
    98    * |||++------ Count on rising edge
    99    * |++-------- disable TCNT clear
    100    * +---------- don`t care
    101    */
     109  /* Use a Phi/X counter */
    102110  write8( ITU1_TCRMASK, ITU_TCR1);
    103111
     
    143151int Read_timer( void )
    144152{
    145   rtems_unsigned32 clicks;
     153  rtems_unsigned32 cclicks;
    146154  rtems_unsigned32 total ;
    147155  /*
     
    150158 
    151159
    152   clicks = read16( ITU_TCNT1);   /* XXX: read some HW here */
     160  cclicks = read16( ITU_TCNT1);   /* XXX: read some HW here */
    153161 
    154162  /*
     
    158166   */
    159167
    160   total = clicks + Timer_interrupts * 65536 ;
     168  total = cclicks + Timer_interrupts * 65536 ;
    161169
    162170  if ( Timer_driver_Find_average_overhead )
    163     return total / SCALE;          /* in XXX microsecond units */
     171    return total / CLOCK_SCALE;          /* in XXX microsecond units */
    164172  else
    165173  {
     
    169177   *  Somehow convert total into microseconds
    170178   */
    171     return (total / SCALE - AVG_OVERHEAD) ;
     179    return (total / CLOCK_SCALE - AVG_OVERHEAD) ;
    172180  }
    173181}
  • c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c

    r5503d75 r4a238002  
    4242#include <rtems/score/isr.h>
    4343#include <rtems/score/thread.h>
    44 #include <rtems/score/cpu_isps.h>
     44#include <rtems/score/sh.h>
     45
     46#if defined(sh7032)
     47#include <rtems/score/ispsh7032.h>
     48#include <rtems/score/iosh7032.h>
     49#elif defined (sh7045)
     50#include <rtems/score/ispsh7045.h>
     51#include <rtems/score/iosh7045.h>
     52#endif
     53
    4554#include <rtems/score/sh_io.h>
    46 #include <rtems/score/sh.h>
    47 #include <rtems/score/iosh7030.h>
    4855
    4956/* from cpu_isps.c */
Note: See TracChangeset for help on using the changeset viewer.