source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/clock/clock.c @ 37731c2

4.104.114.84.95
Last change on this file since 37731c2 was 37731c2, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 6, 2001 at 3:54:20 PM

2001-03-30 Eric Valette <valette@…>

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