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

4.104.114.84.95
Last change on this file since 458bd34 was 458bd34, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 5, 1999 at 4:44:02 PM

This is another pass at making sure that nothing outside the BSP
unnecessarily uses any variables defined by the BSP. On this
sweep, use of BSP_Configuration and Cpu_table was eliminated.

A significant part of this modification was the addition of
macros to access fields in the RTEMS configuration structures.

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@…>.

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