source: rtems/c/src/lib/libcpu/powerpc/mpc860/clock/clock.c @ fbe75c6e

4.104.114.84.95
Last change on this file since fbe75c6e was b06279d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/07/99 at 16:28:43

Bug fix from Gunter Magin <magin@…>:

in libcpu/powerpc/mpc860/clock/clock.c:InstallClock() the reload value for
the PIT is defined as:

pit_value = (BSP_Configuration.microseconds_per_tick *

Cpu_table.clicks_per_usec) - 1 ;

What exactly is a tick, and what is a click?

My confusion stems from the fact, that Jay defines clicks_per_usec to 1
which is correct for his configuration, where a 4MHz clock is predivided
by 4 and then fed to the PIT. So I assume a "click" is just the period of
the PIT input frequency.

However, our HW config seems to have 32.768 kHz crystal input for PIT.
Mandatory division by 4 means 8.196kHz (122usec) at the PIT.

I think, the above assignment should read:

pit_value = (BSP_Configuration.microseconds_per_tick /

Cpu_table.clicks_per_usec) - 1;

where I can define Cpu_table.clicks_per_usec in bspstart.c to 122
(clicks_per_usec). That would lead to a PIT reload value of
10000/122 - 1 = 81 to reach a 10ms "tick" period.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*  clock.c
2 *
3 *  This routine initializes the PIT on the MPC860.
4 *  The tick frequency is specified by the bsp.
5 *
6 *  Author: Jay Monkman (jmonkman@frasca.com)
7 *  Copyright (C) 1998 by Frasca International, Inc.
8 *
9 *  Derived from c/src/lib/libcpu/ppc/ppc403/clock/clock.c:
10 *
11 *  Author: Andrew Bray <andy@i-cubed.co.uk>
12 *
13 *  COPYRIGHT (c) 1995 by i-cubed ltd.
14 *
15 *  To anyone who acknowledges that this file is provided "AS IS"
16 *  without any express or implied warranty:
17 *      permission to use, copy, modify, and distribute this file
18 *      for any purpose is hereby granted without fee, provided that
19 *      the above copyright notice and this notice appears in all
20 *      copies, and that the name of i-cubed limited not be used in
21 *      advertising or publicity pertaining to distribution of the
22 *      software without specific, written prior permission.
23 *      i-cubed limited makes no representations about the suitability
24 *      of this software for any purpose.
25 *
26 *  Derived from c/src/lib/libcpu/hppa1_1/clock/clock.c:
27 *
28 *  COPYRIGHT (c) 1989-1998.
29 *  On-Line Applications Research Corporation (OAR).
30 *  Copyright assigned to U.S. Government, 1994.
31 *
32 *  The license and distribution terms for this file may be
33 *  found in the file LICENSE in this distribution or at
34 *  http://www.OARcorp.com/rtems/license.html.
35 *
36 *  $Id$
37 */
38
39#include <bsp.h>
40#include <clockdrv.h>
41#include <rtems/libio.h>
42
43#include <stdlib.h>                     /* for atexit() */
44#include <mpc860.h>
45
46extern rtems_cpu_table           Cpu_table;             /* owned by BSP */
47
48volatile rtems_unsigned32 Clock_driver_ticks;
49extern volatile m860_t m860;
50
51void Clock_exit( void );
52 
53/*
54 * These are set by clock driver during its init
55 */
56 
57rtems_device_major_number rtems_clock_major = ~0;
58rtems_device_minor_number rtems_clock_minor;
59 
60/*
61 *  ISR Handler
62 */
63rtems_isr Clock_isr(rtems_vector_number vector)
64{
65  m860.piscr |= M860_PISCR_PS;
66  Clock_driver_ticks++;
67  rtems_clock_tick();
68}
69
70void Install_clock(rtems_isr_entry clock_isr)
71{
72  rtems_isr_entry previous_isr;
73  rtems_unsigned32 pit_value;
74 
75  Clock_driver_ticks = 0;
76 
77  pit_value = BSP_Configuration.microseconds_per_tick /
78               Cpu_table.clicks_per_usec;
79  if (pit_value == 0) {
80    pit_value = 0xffff;
81  } else {
82    pit_value--;
83  }
84 
85  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
86    rtems_fatal_error_occurred(-1);
87  } 
88  if (BSP_Configuration.ticks_per_timeslice) {
89   
90    /*
91     * initialize the interval here
92     * First tick is set to right amount of time in the future
93     * Future ticks will be incremented over last value set
94     * in order to provide consistent clicks in the face of
95     * interrupt overhead
96     */
97   
98    rtems_interrupt_catch(clock_isr, PPC_IRQ_LVL0, &previous_isr);
99   
100    m860.sccr &= ~(1<<24);
101    m860.pitc = pit_value;
102   
103    /* set PIT irq level, enable PIT, PIT interrupts */
104    /*  and clear int. status */
105    m860.piscr = M860_PISCR_PIRQ(0) |
106      M860_PISCR_PTE | M860_PISCR_PS | M860_PISCR_PIE;
107   
108    m860.simask |= M860_SIMASK_LVM0;
109  }
110  atexit(Clock_exit);
111}
112
113void
114ReInstall_clock(rtems_isr_entry new_clock_isr)
115{
116  rtems_isr_entry previous_isr;
117  rtems_unsigned32 isrlevel = 0;
118 
119  rtems_interrupt_disable(isrlevel);
120 
121  rtems_interrupt_catch(new_clock_isr, PPC_IRQ_LVL0, &previous_isr);
122 
123  rtems_interrupt_enable(isrlevel);
124}
125
126
127/*
128 * Called via atexit()
129 * Remove the clock interrupt handler by setting handler to NULL
130 */
131void
132Clock_exit(void)
133{
134  if ( BSP_Configuration.ticks_per_timeslice ) {
135    /* disable PIT and PIT interrupts */
136    m860.piscr &= ~(M860_PISCR_PTE | M860_PISCR_PIE);
137   
138    (void) set_vector(0, PPC_IRQ_LVL0, 1);
139  }
140}
141
142rtems_device_driver Clock_initialize(
143  rtems_device_major_number major,
144  rtems_device_minor_number minor,
145  void *pargp
146)
147{
148  Install_clock( Clock_isr );
149 
150  /*
151   * make major/minor avail to others such as shared memory driver
152   */
153 
154  rtems_clock_major = major;
155  rtems_clock_minor = minor;
156 
157  return RTEMS_SUCCESSFUL;
158}
159 
160rtems_device_driver Clock_control(
161  rtems_device_major_number major,
162  rtems_device_minor_number minor,
163  void *pargp
164)
165{
166  rtems_libio_ioctl_args_t *args = pargp;
167 
168  if (args == 0)
169    goto done;
170 
171  /*
172   * This is hokey, but until we get a defined interface
173   * to do this, it will just be this simple...
174   */
175 
176  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
177    Clock_isr(PPC_IRQ_LVL0);
178  }
179  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
180    ReInstall_clock(args->buffer);
181  }
182 
183 done:
184  return RTEMS_SUCCESSFUL;
185}
186
Note: See TracBrowser for help on using the repository browser.