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

4.104.114.84.95
Last change on this file since df49c60 was 0dd1d44, checked in by Joel Sherrill <joel.sherrill@…>, on 01/11/00 at 17:34:20

Removed old hack of using Configuration Table entry ticks_per_timeslice
being set to 0 to indicate that there should be no Clock Tick. This
was used by the Timing Tests to avoid clock tick overhead perturbing
execution times. Now the Timing Tests simply leave the Clock Tick
Driver out of the Device Driver Table.

  • Property mode set to 100644
File size: 4.3 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-1999.
29 *  On-Line Applications Research Corporation (OAR).
30 *
31 *  The license and distribution terms for this file may be
32 *  found in the file LICENSE in this distribution or at
33 *  http://www.OARcorp.com/rtems/license.html.
34 *
35 *  $Id$
36 */
37
38#include <rtems.h>
39#include <clockdrv.h>
40#include <rtems/libio.h>
41
42#include <stdlib.h>                     /* for atexit() */
43#include <mpc860.h>
44
45volatile rtems_unsigned32 Clock_driver_ticks;
46extern volatile m860_t m860;
47
48void Clock_exit( void );
49 
50/*
51 * These are set by clock driver during its init
52 */
53 
54rtems_device_major_number rtems_clock_major = ~0;
55rtems_device_minor_number rtems_clock_minor;
56 
57/*
58 *  ISR Handler
59 */
60rtems_isr Clock_isr(rtems_vector_number vector)
61{
62  m860.piscr |= M860_PISCR_PS;
63  Clock_driver_ticks++;
64  rtems_clock_tick();
65}
66
67void Install_clock(rtems_isr_entry clock_isr)
68{
69  rtems_isr_entry previous_isr;
70  rtems_unsigned32 pit_value;
71 
72  Clock_driver_ticks = 0;
73 
74  pit_value = rtems_configuration_get_microseconds_per_tick() /
75               rtems_cpu_configuration_get_clicks_per_usec();
76  if (pit_value == 0) {
77    pit_value = 0xffff;
78  } else {
79    pit_value--;
80  }
81 
82  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
83    rtems_fatal_error_occurred(-1);
84  } 
85   
86  /*
87   * initialize the interval here
88   * First tick is set to right amount of time in the future
89   * Future ticks will be incremented over last value set
90   * in order to provide consistent clicks in the face of
91   * interrupt overhead
92   */
93 
94  rtems_interrupt_catch(clock_isr, PPC_IRQ_LVL0, &previous_isr);
95   
96  m860.sccr &= ~(1<<24);
97  m860.pitc = pit_value;
98   
99  /* set PIT irq level, enable PIT, PIT interrupts */
100  /*  and clear int. status */
101  m860.piscr = M860_PISCR_PIRQ(0) |
102    M860_PISCR_PTE | M860_PISCR_PS | M860_PISCR_PIE;
103   
104  m860.simask |= M860_SIMASK_LVM0;
105  atexit(Clock_exit);
106}
107
108void
109ReInstall_clock(rtems_isr_entry new_clock_isr)
110{
111  rtems_isr_entry previous_isr;
112  rtems_unsigned32 isrlevel = 0;
113 
114  rtems_interrupt_disable(isrlevel);
115 
116  rtems_interrupt_catch(new_clock_isr, PPC_IRQ_LVL0, &previous_isr);
117 
118  rtems_interrupt_enable(isrlevel);
119}
120
121
122/*
123 * Called via atexit()
124 * Remove the clock interrupt handler by setting handler to NULL
125 */
126void
127Clock_exit(void)
128{
129  /* disable PIT and PIT interrupts */
130  m860.piscr &= ~(M860_PISCR_PTE | M860_PISCR_PIE);
131   
132  (void) set_vector(0, PPC_IRQ_LVL0, 1);
133}
134
135rtems_device_driver Clock_initialize(
136  rtems_device_major_number major,
137  rtems_device_minor_number minor,
138  void *pargp
139)
140{
141  Install_clock( Clock_isr );
142 
143  /*
144   * make major/minor avail to others such as shared memory driver
145   */
146 
147  rtems_clock_major = major;
148  rtems_clock_minor = minor;
149 
150  return RTEMS_SUCCESSFUL;
151}
152 
153rtems_device_driver Clock_control(
154  rtems_device_major_number major,
155  rtems_device_minor_number minor,
156  void *pargp
157)
158{
159  rtems_libio_ioctl_args_t *args = pargp;
160 
161  if (args == 0)
162    goto done;
163 
164  /*
165   * This is hokey, but until we get a defined interface
166   * to do this, it will just be this simple...
167   */
168 
169  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
170    Clock_isr(PPC_IRQ_LVL0);
171  }
172  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
173    ReInstall_clock(args->buffer);
174  }
175 
176 done:
177  return RTEMS_SUCCESSFUL;
178}
179
Note: See TracBrowser for help on using the repository browser.