Changeset e8918ec in rtems


Ignore:
Timestamp:
12/13/99 22:12:03 (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
f09ac268
Parents:
c629812
Message:

Patch from Eric Norum <eric@…> to change to gen68360 clock handling.

I got tired of having strange clock rates (e.g. #define
CONFIGURE_MICROSECONDS_PER_TICK 52489) and drifting times-of-day with
the gen68360 BSP so I changed the way the programmable-interval clock
interrupt works. The new version will have some jitter in the intervals
between individual calls to the rtems_clock_tick routine, but the
long-term average will match the CONFIGURE_MICROSECONDS_PER_TICK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/m68k/gen68360/clock/ckinit.c

    rc629812 re8918ec  
    5454
    5555/*
     56 * RTEMS and hardware have different notions of clock rate.
     57 */
     58static unsigned long rtems_nsec_per_tick;
     59static unsigned long pit_nsec_per_tick;
     60
     61/*
    5662 * Periodic interval timer interrupt handler
    5763 */
     
    6066Clock_isr (rtems_vector_number vector)
    6167{
    62         /*
    63          * Perform a dummy read of DPRAM.
    64          * This works around a bug in Rev. B of the 68360
    65          */
    66         m360.dpram0[0];
     68        static unsigned long nsec;
    6769
    6870        /*
    69          * Feed the watchdog
    70          * Application code can override this by
    71          * setting M360DefaultWatchdogFeeder to zero.
     71         * See if it's really time for a `tick'
    7272         */
    73         if (M360DefaultWatchdogFeeder) {
    74                 m360.swsr = 0x55;
    75                 m360.swsr = 0xAA;
     73        nsec += pit_nsec_per_tick;
     74        if (nsec >= rtems_nsec_per_tick) {
     75                nsec -= rtems_nsec_per_tick;
     76       
     77                /*
     78                 * Perform a dummy read of DPRAM.
     79                 * This works around a bug in Rev. B of the 68360
     80                 */
     81                m360.dpram0[0];
     82
     83                /*
     84                 * Feed the watchdog
     85                 * Application code can override this by
     86                 * setting M360DefaultWatchdogFeeder to zero.
     87                 */
     88                if (M360DefaultWatchdogFeeder) {
     89                        m360.swsr = 0x55;
     90                        m360.swsr = 0xAA;
     91                }
     92
     93                /*
     94                 * Announce the clock tick
     95                 */
     96                Clock_driver_ticks++;
     97                rtems_clock_tick();
    7698        }
    77 
    78         /*
    79          * Announce the clock tick
    80          */
    81         Clock_driver_ticks++;
    82         rtems_clock_tick();
    8399}
    84100
     
    99115        Clock_driver_ticks = 0;
    100116        if ( BSP_Configuration.ticks_per_timeslice ) {
    101                 int pitr;
    102 
    103117                /*
    104118                 * Choose periodic interval timer register value
     119                 * The rate at which the periodic interval timer
     120                 * can generate interrupts is almost certainly not
     121                 * the same as desired by the BSP configuration.
     122                 * Handle the difference by choosing the largest PIT
     123                 * interval which is less than or equal to the RTEMS
     124                 * interval and skipping some hardware interrupts.
     125                 * To reduce the jitter in the calls to RTEMS the
     126                 * hardware interrupt interval is never less than
     127                 * the maximum non-prescaled value from the PIT.
     128                 *
    105129                 * For a 25 MHz external clock the basic clock rate is
    106130                 *      40 nsec * 128 * 4 = 20.48 usec/tick
    107131                 */
    108                 pitr = ((BSP_Configuration.microseconds_per_tick * 100) + 1023) / 2048;
    109                 if (pitr >= 256) {
    110                         pitr = (pitr + 255) / 512;
    111                         if (pitr >= 256)
    112                                 pitr = 255;
    113                         else if (pitr == 0)
    114                                 pitr = 1;
    115                         pitr |= 0x100;
     132                int divisor;
     133                extern int m360_clock_rate; /* This should be somewhere in a config file */
     134                unsigned long nsec_per_chip_tick = 1000000000 / m360_clock_rate;
     135                unsigned long nsec_per_pit_tick = 512 * nsec_per_chip_tick;
     136
     137                rtems_nsec_per_tick = BSP_Configuration.microseconds_per_tick * 1000;
     138                divisor = rtems_nsec_per_tick / nsec_per_pit_tick;
     139                if (divisor >= 256) {
     140                        divisor = 255;
    116141                }
    117                 else if (pitr == 0) {
    118                         pitr = 1;
     142                else if (divisor == 0) {
     143                        divisor = 1;
    119144                }
     145                pit_nsec_per_tick = nsec_per_pit_tick * divisor;
    120146                m360.pitr &= ~0x1FF;
    121147                m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;
    122148                set_vector (clock_isr, CLOCK_VECTOR, 1);
    123                 m360.pitr |= pitr;
     149                m360.pitr |= divisor;
    124150                atexit (Clock_exit);
    125151        }
Note: See TracChangeset for help on using the changeset viewer.