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

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 4.4 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  if ( rtems_configuration_get_ticks_per_timeslice() ) {
86   
87    /*
88     * initialize the interval here
89     * First tick is set to right amount of time in the future
90     * Future ticks will be incremented over last value set
91     * in order to provide consistent clicks in the face of
92     * interrupt overhead
93     */
94   
95    rtems_interrupt_catch(clock_isr, PPC_IRQ_LVL0, &previous_isr);
96   
97    m860.sccr &= ~(1<<24);
98    m860.pitc = pit_value;
99   
100    /* set PIT irq level, enable PIT, PIT interrupts */
101    /*  and clear int. status */
102    m860.piscr = M860_PISCR_PIRQ(0) |
103      M860_PISCR_PTE | M860_PISCR_PS | M860_PISCR_PIE;
104   
105    m860.simask |= M860_SIMASK_LVM0;
106  }
107  atexit(Clock_exit);
108}
109
110void
111ReInstall_clock(rtems_isr_entry new_clock_isr)
112{
113  rtems_isr_entry previous_isr;
114  rtems_unsigned32 isrlevel = 0;
115 
116  rtems_interrupt_disable(isrlevel);
117 
118  rtems_interrupt_catch(new_clock_isr, PPC_IRQ_LVL0, &previous_isr);
119 
120  rtems_interrupt_enable(isrlevel);
121}
122
123
124/*
125 * Called via atexit()
126 * Remove the clock interrupt handler by setting handler to NULL
127 */
128void
129Clock_exit(void)
130{
131  if ( rtems_configuration_get_ticks_per_timeslice() ) {
132    /* disable PIT and PIT interrupts */
133    m860.piscr &= ~(M860_PISCR_PTE | M860_PISCR_PIE);
134   
135    (void) set_vector(0, PPC_IRQ_LVL0, 1);
136  }
137}
138
139rtems_device_driver Clock_initialize(
140  rtems_device_major_number major,
141  rtems_device_minor_number minor,
142  void *pargp
143)
144{
145  Install_clock( Clock_isr );
146 
147  /*
148   * make major/minor avail to others such as shared memory driver
149   */
150 
151  rtems_clock_major = major;
152  rtems_clock_minor = minor;
153 
154  return RTEMS_SUCCESSFUL;
155}
156 
157rtems_device_driver Clock_control(
158  rtems_device_major_number major,
159  rtems_device_minor_number minor,
160  void *pargp
161)
162{
163  rtems_libio_ioctl_args_t *args = pargp;
164 
165  if (args == 0)
166    goto done;
167 
168  /*
169   * This is hokey, but until we get a defined interface
170   * to do this, it will just be this simple...
171   */
172 
173  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
174    Clock_isr(PPC_IRQ_LVL0);
175  }
176  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
177    ReInstall_clock(args->buffer);
178  }
179 
180 done:
181  return RTEMS_SUCCESSFUL;
182}
183
Note: See TracBrowser for help on using the repository browser.