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

4.104.114.84.95
Last change on this file since f817b02 was f817b02, checked in by Joel Sherrill <joel.sherrill@…>, on 11/04/99 at 18:05:09

The files in libcpu should not be directly dependent on any BSP. In
particular, using bsp.h, or getting information from the BSP which
should properly be obtained from RTEMS is forbidden. This is
necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.
The changes primarily eliminated the need to include bsp.h and
peeking at BSP_Configuration. The use of Cpu_table in each
BSP needs to be eliminated.

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