source: rtems/c/src/lib/libcpu/powerpc/mpc8260/clock/clock.c @ aaed235

4.104.114.84.95
Last change on this file since aaed235 was 21e1c44, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:53:10 PM

2003-09-04 Joel Sherrill <joel@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/clock/c_clock.h, mpc6xx/exceptions/raw_exception.c, mpc6xx/exceptions/raw_exception.h, mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h, mpc6xx/mmu/mmuAsm.S, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/brg.c, mpc8260/exceptions/raw_exception.c, mpc8260/exceptions/raw_exception.h, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/exceptions/raw_exception.c, mpc8xx/exceptions/raw_exception.h, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c.polled, ppc403/timer/timer.c, rtems/powerpc/debugmod.h, shared/include/byteorder.h, shared/include/cpuIdent.c, shared/include/cpuIdent.h, shared/include/io.h, shared/include/mmu.h, shared/include/page.h, shared/include/pgtable.h, shared/include/spr.h: URL for license changed.
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*  clock.c
2 *
3 *  This routine initializes the PIT on the MPC8xx.
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 *
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.rtems.com/license/LICENSE.
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 <mpc8260.h>
44#include <bsp/irq.h>
45
46volatile rtems_unsigned32 Clock_driver_ticks;
47extern int BSP_get_clock_irq_level();
48extern int BSP_connect_clock_handler(rtems_isr_entry);
49extern int BSP_disconnect_clock_handler();
50
51void Clock_exit( void );
52
53rtems_unsigned32 decrementer_value;
54
55volatile int ClockInitialised = 0;
56
57
58/*
59 * These are set by clock driver during its init
60 */
61 
62rtems_device_major_number rtems_clock_major = ~0;
63rtems_device_minor_number rtems_clock_minor;
64 
65/*
66 *  ISR Handler
67 */
68rtems_isr Clock_isr(rtems_vector_number vector)
69{
70  int clicks;
71
72  if( ClockInitialised ) {
73    PPC_Get_decrementer( clicks );
74    do {
75      clicks += decrementer_value;
76      PPC_Set_decrementer( clicks );
77
78      Clock_driver_ticks++;
79      rtems_clock_tick();
80    } while( clicks < 100 );
81  }
82#if 0
83  m8260.piscr |= M8260_PISCR_PS;
84  Clock_driver_ticks++;
85  rtems_clock_tick();
86#endif
87
88
89}
90
91void clockOn(void* unused)
92{
93
94  decrementer_value = rtems_configuration_get_microseconds_per_tick() *
95                      rtems_cpu_configuration_get_clicks_per_usec() - 1;
96
97  PPC_Set_decrementer( decrementer_value );
98  Clock_driver_ticks = 0;
99
100  ClockInitialised = 1;
101
102
103#if 0
104  unsigned desiredLevel;
105  rtems_unsigned32 pit_value;
106 
107  pit_value = (rtems_configuration_get_microseconds_per_tick() *
108               rtems_cpu_configuration_get_clicks_per_usec()) - 1 ;
109 
110  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
111    rtems_fatal_error_occurred(-1);
112  }
113  m8260.sccr &= ~(1<<24);
114  m8260.pitc = pit_value;
115
116  desiredLevel = BSP_get_clock_irq_level();
117  /* set PIT irq level, enable PIT, PIT interrupts */
118  /*  and clear int. status */
119  m8260.piscr = /*M8260_PISCR_PIRQ(desiredLevel) |*/
120    M8260_PISCR_PTE | M8260_PISCR_PS | M8260_PISCR_PIE;
121#endif
122}
123/*
124 * Called via atexit()
125 * Remove the clock interrupt handler by setting handler to NULL
126 */
127void
128clockOff(void* unused)
129{
130#if 0
131  /* disable PIT and PIT interrupts */
132  m8260.piscr &= ~(M8260_PISCR_PTE | M8260_PISCR_PIE);
133#endif
134  ClockInitialised = 0;
135}
136
137int clockIsOn(void* unused)
138{
139  return ClockInitialised;
140#if 0
141  if (m8260.piscr & M8260_PISCR_PIE) return 1;
142  return 0;
143#endif
144
145}
146
147/*
148 * Called via atexit()
149 * Remove the clock interrupt handler by setting handler to NULL
150 */
151void
152Clock_exit(void)
153{
154  (void) BSP_disconnect_clock_handler ();
155}
156
157void Install_clock(rtems_isr_entry clock_isr)
158{
159  Clock_driver_ticks = 0;
160
161
162  decrementer_value = rtems_configuration_get_microseconds_per_tick() *
163                      rtems_cpu_configuration_get_clicks_per_usec() - 1;
164
165  PPC_Set_decrementer( decrementer_value );
166
167  BSP_connect_clock_handler (clock_isr);
168
169
170  ClockInitialised = 1;
171
172  atexit(Clock_exit);
173
174}
175
176void
177ReInstall_clock(rtems_isr_entry new_clock_isr)
178{
179  BSP_connect_clock_handler (new_clock_isr);
180}
181
182
183rtems_device_driver Clock_initialize(
184  rtems_device_major_number major,
185  rtems_device_minor_number minor,
186  void *pargp
187)
188{
189  Install_clock( Clock_isr );
190 
191  /*
192   * make major/minor avail to others such as shared memory driver
193   */
194 
195  rtems_clock_major = major;
196  rtems_clock_minor = minor;
197 
198  return RTEMS_SUCCESSFUL;
199}
200 
201rtems_device_driver Clock_control(
202  rtems_device_major_number major,
203  rtems_device_minor_number minor,
204  void *pargp
205)
206{
207  rtems_libio_ioctl_args_t *args = pargp;
208 
209  if (args == 0)
210    goto done;
211 
212  /*
213   * This is hokey, but until we get a defined interface
214   * to do this, it will just be this simple...
215   */
216 
217  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
218    Clock_isr(BSP_PERIODIC_TIMER);
219  }
220  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
221    ReInstall_clock(args->buffer);
222  }
223 
224 done:
225  return RTEMS_SUCCESSFUL;
226}
227
Note: See TracBrowser for help on using the repository browser.