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

4.104.114.84.95
Last change on this file since acc25ee was acc25ee, checked in by Joel Sherrill <joel.sherrill@…>, on 12/02/99 at 14:31:19

Merged of mcp750 and mvme2307 BSP by Eric Valette <valette@…>.
As part of this effort, the mpc750 libcpu code is now shared with the
ppc6xx.

  • 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 *  Copyright assigned to U.S. Government, 1994.
12 *
13 *  The license and distribution terms for this file may in
14 *  the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  Modified to support the MPC750.
18 *  Modifications Copyright (c) 1999 Eric Valette valette@crf.canon.fr
19 *
20 *  $Id$
21 */
22
23#include <rtems.h>
24#include <rtems/libio.h>
25#include <stdlib.h>                     /* for atexit() */
26#include <assert.h>
27#include <libcpu/cpu.h>
28#include <libcpu/c_clock.h>
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  if (BSP_Configuration.ticks_per_timeslice)    {
52    /*
53     * Nothing to do as we cannot disable all interrupts and
54     * the decrementer interrupt enable is MSR_EE
55     */
56  }
57}
58void clockOn(void* unused)
59{
60  PPC_Set_decrementer( Clock_Decrementer_value );
61}
62
63/*
64 *  Clock_isr
65 *
66 *  This is the clock tick interrupt handler.
67 *
68 *  Input parameters:
69 *    vector - vector number
70 *
71 *  Output parameters:  NONE
72 *
73 *  Return values:      NONE
74 *
75 */
76void clockIsr()
77{
78  /*
79   *  The driver has seen another tick.
80   */
81
82  PPC_Set_decrementer( Clock_Decrementer_value );
83
84  Clock_driver_ticks += 1;
85
86  /*
87   *  Real Time Clock counter/timer is set to automatically reload.
88   */
89
90  rtems_clock_tick();
91}
92
93int clockIsOn(void* unused)
94{
95  unsigned32 msr_value;
96
97  _CPU_MSR_GET( msr_value );
98  if (msr_value & MSR_EE) return 1;
99  return 0;
100}
101
102
103/*
104 *  Clock_exit
105 *
106 *  This routine allows the clock driver to exit by masking the interrupt and
107 *  disabling the clock's counter.
108 *
109 *  Input parameters:   NONE
110 *
111 *  Output parameters:  NONE
112 *
113 *  Return values:      NONE
114 *
115 */
116
117void Clock_exit( void )
118{
119  if ( BSP_Configuration.ticks_per_timeslice ) {
120   (void) BSP_disconnect_clock_handler ();
121  }
122}
123 
124/*
125 *  Clock_initialize
126 *
127 *  This routine initializes the clock driver.
128 *
129 *  Input parameters:
130 *    major - clock device major number
131 *    minor - clock device minor number
132 *    parg  - pointer to optional device driver arguments
133 *
134 *  Output parameters:  NONE
135 *
136 *  Return values:
137 *    rtems_device_driver status code
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  Clock_Decrementer_value = (BSP_bus_frequency/4000)*
147                            (BSP_Configuration.microseconds_per_tick/1000);
148
149  if (!BSP_connect_clock_handler ()) {
150    printk("Unable to initialize system clock\n");
151    rtems_fatal_error_occurred(1);
152  }
153  /* make major/minor avail to others such as shared memory driver */
154 
155  rtems_clock_major = major;
156  rtems_clock_minor = minor;
157
158  return RTEMS_SUCCESSFUL;
159} /* Clock_initialize */
160 
161/*
162 *  Clock_control
163 *
164 *  This routine is the clock device driver control entry point.
165 *
166 *  Input parameters:
167 *    major - clock device major number
168 *    minor - clock device minor number
169 *    parg  - pointer to optional device driver arguments
170 *
171 *  Output parameters:  NONE
172 *
173 *  Return values:
174 *    rtems_device_driver status code
175 */
176
177rtems_device_driver Clock_control(
178  rtems_device_major_number major,
179  rtems_device_minor_number minor,
180  void *pargp
181)
182{
183    rtems_libio_ioctl_args_t *args = pargp;
184 
185    if (args == 0)
186        goto done;
187 
188    Clock_Decrementer_value = (BSP_bus_frequency/4000)*
189      (BSP_Configuration.microseconds_per_tick/1000);
190
191    if      (args->command == rtems_build_name('I', 'S', 'R', ' '))
192      clockIsr();
193    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
194    {
195      if (!BSP_connect_clock_handler ()) {
196        printk("Error installing clock interrupt handler!\n");
197        rtems_fatal_error_occurred(1);
198      }
199    }
200done:
201    return RTEMS_SUCCESSFUL;
202}
203
204
205
206
207
208
Note: See TracBrowser for help on using the repository browser.