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

4.104.114.84.95
Last change on this file since cebb89b was cebb89b, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 31, 2002 at 8:12:46 PM

2002-10-31 Joel Sherrill <joel@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/exceptions/raw_exception.c, mpc6xx/mmu/bat.c: Removed warnings.
  • 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
30extern int BSP_connect_clock_handler (void);
31
32/*
33 *  Clock ticks since initialization
34 */
35
36volatile rtems_unsigned32 Clock_driver_ticks;
37
38/*
39 *  This is the value programmed into the count down timer.
40 */
41
42rtems_unsigned32 Clock_Decrementer_value;
43
44/*
45 * These are set by clock driver during its init
46 */
47 
48rtems_device_major_number rtems_clock_major = ~0;
49rtems_device_minor_number rtems_clock_minor;
50
51void clockOff(void* unused)
52{
53  /*
54   * Nothing to do as we cannot disable all interrupts and
55   * the decrementer interrupt enable is MSR_EE
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  (void) BSP_disconnect_clock_handler ();
120}
121 
122/*
123 *  Clock_initialize
124 *
125 *  This routine initializes the clock driver.
126 *
127 *  Input parameters:
128 *    major - clock device major number
129 *    minor - clock device minor number
130 *    parg  - pointer to optional device driver arguments
131 *
132 *  Output parameters:  NONE
133 *
134 *  Return values:
135 *    rtems_device_driver status code
136 */
137
138rtems_device_driver Clock_initialize(
139  rtems_device_major_number major,
140  rtems_device_minor_number minor,
141  void *pargp
142)
143{
144  Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
145            (rtems_configuration_get_microseconds_per_tick()/1000);
146
147  if (!BSP_connect_clock_handler ()) {
148    printk("Unable to initialize system clock\n");
149    rtems_fatal_error_occurred(1);
150  }
151  /* make major/minor avail to others such as shared memory driver */
152 
153  rtems_clock_major = major;
154  rtems_clock_minor = minor;
155
156  return RTEMS_SUCCESSFUL;
157} /* Clock_initialize */
158 
159/*
160 *  Clock_control
161 *
162 *  This routine is the clock device driver control entry point.
163 *
164 *  Input parameters:
165 *    major - clock device major number
166 *    minor - clock device minor number
167 *    parg  - pointer to optional device driver arguments
168 *
169 *  Output parameters:  NONE
170 *
171 *  Return values:
172 *    rtems_device_driver status code
173 */
174
175rtems_device_driver Clock_control(
176  rtems_device_major_number major,
177  rtems_device_minor_number minor,
178  void *pargp
179)
180{
181    rtems_libio_ioctl_args_t *args = pargp;
182 
183    if (args == 0)
184        goto done;
185 
186    Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
187      (rtems_configuration_get_microseconds_per_tick()/1000);
188
189    if      (args->command == rtems_build_name('I', 'S', 'R', ' '))
190      clockIsr();
191    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
192    {
193      if (!BSP_connect_clock_handler ()) {
194        printk("Error installing clock interrupt handler!\n");
195        rtems_fatal_error_occurred(1);
196      }
197    }
198done:
199    return RTEMS_SUCCESSFUL;
200}
201
202
203
204
205
206
Note: See TracBrowser for help on using the repository browser.