OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [powerpc/] [mpc6xx/] [clock/] [c_clock.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: c_clock.c,v 1.2 2001-09-27 12:01:24 chris Exp $
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
 
34
volatile rtems_unsigned32 Clock_driver_ticks;
35
 
36
/*
37
 *  This is the value programmed into the count down timer.
38
 */
39
 
40
rtems_unsigned32 Clock_Decrementer_value;
41
 
42
/*
43
 * These are set by clock driver during its init
44
 */
45
 
46
rtems_device_major_number rtems_clock_major = ~0;
47
rtems_device_minor_number rtems_clock_minor;
48
 
49
void 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
}
56
void 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
 */
74
void 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
 
91
int 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
 
115
void 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
 
136
rtems_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
                            (BSP_Configuration.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
 
173
rtems_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
      (BSP_Configuration.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
    }
196
done:
197
    return RTEMS_SUCCESSFUL;
198
}
199
 
200
 
201
 
202
 
203
 
204
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.