source: rtems/c/src/lib/libcpu/powerpc/mpc6xx/clock/c_clock.c @ a73a977

4.104.114.84.95
Last change on this file since a73a977 was a73a977, checked in by Joel Sherrill <joel.sherrill@…>, on 04/18/02 at 20:55:37

2002-04-18 Ralf Corsepius <corsepiu@…>

  • shared/include/cpu.h: Removed.
  • shared/include/Makefile.am: Reflect changes above.
  • shared/include/spr.h: Include rtems/powerpc/registers.h instead of libcpu/cpu.h.
  • mpc6xx/clock/c_clock.c: Reflect changes to <rtems/score/cpu.h>.
  • mpc6xx/exceptions/asm_utils.S: Ditto.
  • mpc6xx/exceptions/raw_exception.c: Ditto.
  • mpc6xx/mmu/mmuAsm.S: Ditto.
  • mpc6xx/timer/timer.c: Ditto.
  • mpc8260/exceptions/asm_utils.S: Ditto.
  • mpc8260/exceptions/raw_exception.c: Ditto.
  • mpc8xx/exceptions/asm_utils.S: Ditto.
  • mpc8xx/exceptions/raw_exception.c: Ditto.
  • ppc403/vectors/vectors.S: Include <asm.h> instead of "asm.h".
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  Clock Tick Device Driver
3 *
4 *  This routine utilizes the Decrementer Register common to the PPC family.
5 *
6 *  The tick frequency is directly programmed to the configured number of
7 *  microseconds per tick.
8 *
9 *  COPYRIGHT (c) 1989-1997.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may in
13 *  the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  Modified to support the MPC750.
17 *  Modifications Copyright (c) 1999 Eric Valette valette@crf.canon.fr
18 *
19 *  $Id$
20 */
21
22#include <rtems/system.h>
23#include <rtems.h>
24#include <rtems/libio.h>
25#include <stdlib.h>                     /* for atexit() */
26#include <assert.h>
27#include <libcpu/c_clock.h>
28#include <rtems/bspIo.h>                     /* for printk() */
29
30/*
31 *  Clock ticks since initialization
32 */
33
34volatile rtems_unsigned32 Clock_driver_ticks;
35
36/*
37 *  This is the value programmed into the count down timer.
38 */
39
40rtems_unsigned32 Clock_Decrementer_value;
41
42/*
43 * These are set by clock driver during its init
44 */
45 
46rtems_device_major_number rtems_clock_major = ~0;
47rtems_device_minor_number rtems_clock_minor;
48
49void clockOff(void* unused)
50{
51  /*
52   * Nothing to do as we cannot disable all interrupts and
53   * the decrementer interrupt enable is MSR_EE
54   */
55}
56void clockOn(void* unused)
57{
58  PPC_Set_decrementer( Clock_Decrementer_value );
59}
60
61/*
62 *  Clock_isr
63 *
64 *  This is the clock tick interrupt handler.
65 *
66 *  Input parameters:
67 *    vector - vector number
68 *
69 *  Output parameters:  NONE
70 *
71 *  Return values:      NONE
72 *
73 */
74void clockIsr()
75{
76  /*
77   *  The driver has seen another tick.
78   */
79
80  PPC_Set_decrementer( Clock_Decrementer_value );
81
82  Clock_driver_ticks += 1;
83
84  /*
85   *  Real Time Clock counter/timer is set to automatically reload.
86   */
87
88  rtems_clock_tick();
89}
90
91int clockIsOn(void* unused)
92{
93  unsigned32 msr_value;
94
95  _CPU_MSR_GET( msr_value );
96  if (msr_value & MSR_EE) return 1;
97  return 0;
98}
99
100
101/*
102 *  Clock_exit
103 *
104 *  This routine allows the clock driver to exit by masking the interrupt and
105 *  disabling the clock's counter.
106 *
107 *  Input parameters:   NONE
108 *
109 *  Output parameters:  NONE
110 *
111 *  Return values:      NONE
112 *
113 */
114
115void Clock_exit( void )
116{
117  (void) BSP_disconnect_clock_handler ();
118}
119 
120/*
121 *  Clock_initialize
122 *
123 *  This routine initializes the clock driver.
124 *
125 *  Input parameters:
126 *    major - clock device major number
127 *    minor - clock device minor number
128 *    parg  - pointer to optional device driver arguments
129 *
130 *  Output parameters:  NONE
131 *
132 *  Return values:
133 *    rtems_device_driver status code
134 */
135
136rtems_device_driver Clock_initialize(
137  rtems_device_major_number major,
138  rtems_device_minor_number minor,
139  void *pargp
140)
141{
142  Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
143            (rtems_configuration_get_microseconds_per_tick()/1000);
144
145  if (!BSP_connect_clock_handler ()) {
146    printk("Unable to initialize system clock\n");
147    rtems_fatal_error_occurred(1);
148  }
149  /* make major/minor avail to others such as shared memory driver */
150 
151  rtems_clock_major = major;
152  rtems_clock_minor = minor;
153
154  return RTEMS_SUCCESSFUL;
155} /* Clock_initialize */
156 
157/*
158 *  Clock_control
159 *
160 *  This routine is the clock device driver control entry point.
161 *
162 *  Input parameters:
163 *    major - clock device major number
164 *    minor - clock device minor number
165 *    parg  - pointer to optional device driver arguments
166 *
167 *  Output parameters:  NONE
168 *
169 *  Return values:
170 *    rtems_device_driver status code
171 */
172
173rtems_device_driver Clock_control(
174  rtems_device_major_number major,
175  rtems_device_minor_number minor,
176  void *pargp
177)
178{
179    rtems_libio_ioctl_args_t *args = pargp;
180 
181    if (args == 0)
182        goto done;
183 
184    Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
185      (rtems_configuration_get_microseconds_per_tick()/1000);
186
187    if      (args->command == rtems_build_name('I', 'S', 'R', ' '))
188      clockIsr();
189    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
190    {
191      if (!BSP_connect_clock_handler ()) {
192        printk("Error installing clock interrupt handler!\n");
193        rtems_fatal_error_occurred(1);
194      }
195    }
196done:
197    return RTEMS_SUCCESSFUL;
198}
199
200
201
202
203
204
Note: See TracBrowser for help on using the repository browser.