source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/clock/clock.c @ 8209461b

Last change on this file since 8209461b was 8209461b, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:45:53 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: 4.1 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 <mpc8xx.h>
44
45volatile rtems_unsigned32 Clock_driver_ticks;
46extern volatile m8xx_t m8xx;
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
53/*
54 * These are set by clock driver during its init
55 */
56 
57rtems_device_major_number rtems_clock_major = ~0;
58rtems_device_minor_number rtems_clock_minor;
59 
60/*
61 *  ISR Handler
62 */
63rtems_isr Clock_isr(rtems_vector_number vector)
64{
65  m8xx.piscr |= M8xx_PISCR_PS;
66  Clock_driver_ticks++;
67  rtems_clock_tick();
68}
69
70void clockOn(void* unused)
71{
72  unsigned desiredLevel;
73  rtems_unsigned32 pit_value;
74 
75  pit_value = (rtems_configuration_get_microseconds_per_tick() *
76               rtems_cpu_configuration_get_clicks_per_usec()) - 1 ;
77 
78  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
79    rtems_fatal_error_occurred(-1);
80  }
81  m8xx.sccr &= ~(1<<24);
82  m8xx.pitc = pit_value;
83
84  desiredLevel = BSP_get_clock_irq_level();
85  /* set PIT irq level, enable PIT, PIT interrupts */
86  /*  and clear int. status */
87  m8xx.piscr = M8xx_PISCR_PIRQ(desiredLevel) |
88    M8xx_PISCR_PTE | M8xx_PISCR_PS | M8xx_PISCR_PIE;
89}
90/*
91 * Called via atexit()
92 * Remove the clock interrupt handler by setting handler to NULL
93 */
94void
95clockOff(void* unused)
96{
97  /* disable PIT and PIT interrupts */
98  m8xx.piscr &= ~(M8xx_PISCR_PTE | M8xx_PISCR_PIE); 
99}
100
101int clockIsOn(void* unused)
102{
103  if (m8xx.piscr & M8xx_PISCR_PIE) return 1;
104  return 0;
105}
106
107/*
108 * Called via atexit()
109 * Remove the clock interrupt handler by setting handler to NULL
110 */
111void
112Clock_exit(void)
113{
114  (void) BSP_disconnect_clock_handler ();
115}
116
117void Install_clock(rtems_isr_entry clock_isr)
118{
119  Clock_driver_ticks = 0;
120
121  BSP_connect_clock_handler (clock_isr);
122  atexit(Clock_exit);
123}
124
125void
126ReInstall_clock(rtems_isr_entry new_clock_isr)
127{
128  BSP_connect_clock_handler (new_clock_isr);
129}
130
131
132rtems_device_driver Clock_initialize(
133  rtems_device_major_number major,
134  rtems_device_minor_number minor,
135  void *pargp
136)
137{
138  Install_clock( Clock_isr );
139 
140  /*
141   * make major/minor avail to others such as shared memory driver
142   */
143 
144  rtems_clock_major = major;
145  rtems_clock_minor = minor;
146 
147  return RTEMS_SUCCESSFUL;
148}
149 
150rtems_device_driver Clock_control(
151  rtems_device_major_number major,
152  rtems_device_minor_number minor,
153  void *pargp
154)
155{
156  rtems_libio_ioctl_args_t *args = pargp;
157 
158  if (args == 0)
159    goto done;
160 
161  /*
162   * This is hokey, but until we get a defined interface
163   * to do this, it will just be this simple...
164   */
165 
166  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
167    Clock_isr(PPC_IRQ_LVL0);
168  }
169  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
170    ReInstall_clock(args->buffer);
171  }
172 
173 done:
174  return RTEMS_SUCCESSFUL;
175}
176
Note: See TracBrowser for help on using the repository browser.