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

4.104.114.84.95
Last change on this file since 3239698 was 66c373bf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 02:04:00

2004-03-30 Ralf Corsepius <ralf_corsepius@…>

  • mpc505/timer/timer.c, mpc5xx/timer/timer.c, mpc6xx/clock/c_clock.c, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/cp.c, mpc8260/cpm/dpram.c, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/include/mpc8260.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/cpm/cp.c, mpc8xx/cpm/dpram.c, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/include/mpc8xx.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c, ppc403/console/console405.c, ppc403/ictrl/ictrl.c, ppc403/ictrl/ictrl.h, ppc403/timer/timer.c, ppc403/tty_drv/tty_drv.c, rtems/powerpc/cache.h, shared/src/cache.c: Convert to using c99 fixed size types.
  • 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.rtems.com/license/LICENSE.
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 uint32_t   Clock_driver_ticks;
37
38/*
39 *  This is the value programmed into the count down timer.
40 */
41
42uint32_t   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  uint32_t   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.