source: rtems/c/src/lib/libcpu/powerpc/mpc821/clock/clock.c @ 0dd1d44

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