source: rtems/c/src/lib/libbsp/powerpc/dmv177/clock/clock.c @ dc104a4

4.104.114.84.95
Last change on this file since dc104a4 was dc104a4, checked in by Joel Sherrill <joel.sherrill@…>, on May 30, 1998 at 11:46:21 AM

Updated to current source and removed warnings.

  • Property mode set to 100644
File size: 4.5 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 *  $Id$
18 */
19
20#include <stdlib.h>
21
22#include <bsp.h>
23#include <rtems/libio.h>
24
25/*
26 *  The Real Time Clock Counter Timer uses this trap type.
27 */
28
29#define CLOCK_VECTOR PPC_IRQ_DECREMENTER
30
31/*
32 *  Clock ticks since initialization
33 */
34
35volatile rtems_unsigned32 Clock_driver_ticks;
36
37/*
38 *  This is the value programmed into the count down timer.
39 */
40
41rtems_unsigned32 Clock_Decrementer_value;
42
43/*
44 * This is the value of the old isr routine.
45 */
46rtems_isr_entry  Old_ticker;
47
48
49void Clock_exit( void );
50 
51/*
52 * These are set by clock driver during its init
53 */
54 
55rtems_device_major_number rtems_clock_major = ~0;
56rtems_device_minor_number rtems_clock_minor;
57
58/*PAGE
59 *
60 *  Clock_isr
61 *
62 *  This is the clock tick interrupt handler.
63 *
64 *  Input parameters:
65 *    vector - vector number
66 *
67 *  Output parameters:  NONE
68 *
69 *  Return values:      NONE
70 *
71 */
72
73rtems_isr Clock_isr(
74  rtems_vector_number  vector,
75  CPU_Interrupt_frame *frame
76)
77{
78  /*
79   *  Set the decrementer.
80   */
81
82  PPC_Set_decrementer( Clock_Decrementer_value );
83
84  /*
85   *  The driver has seen another tick.
86   */
87
88  Clock_driver_ticks += 1;
89
90  /*
91   *  Real Time Clock counter/timer is set to automatically reload.
92   */
93
94  rtems_clock_tick();
95}
96
97/*PAGE
98 *
99 *  Install_clock
100 *
101 *  This routine actually performs the hardware initialization for the clock.
102 *
103 *  Input parameters:
104 *    clock_isr - clock interrupt service routine entry point
105 *
106 *  Output parameters:  NONE
107 *
108 *  Return values:      NONE
109 *
110 */
111
112extern int CLOCK_SPEED;
113
114void Install_clock(
115  rtems_isr_entry clock_isr
116)
117{
118  Clock_driver_ticks = 0;
119
120  if ( BSP_Configuration.ticks_per_timeslice ) {
121    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
122
123    PPC_Set_decrementer( Clock_Decrementer_value );
124
125    atexit( Clock_exit );
126  }
127}
128
129/*PAGE
130 *
131 *  Clock_exit
132 *
133 *  This routine allows the clock driver to exit by masking the interrupt and
134 *  disabling the clock's counter.
135 *
136 *  Input parameters:   NONE
137 *
138 *  Output parameters:  NONE
139 *
140 *  Return values:      NONE
141 *
142 */
143
144void Clock_exit( void )
145{
146  if ( BSP_Configuration.ticks_per_timeslice ) {
147
148    /* nothing to do */; 
149
150    /* do not restore old vector */
151  }
152}
153 
154/*PAGE
155 *
156 *  Clock_initialize
157 *
158 *  This routine initializes the clock driver.
159 *
160 *  Input parameters:
161 *    major - clock device major number
162 *    minor - clock device minor number
163 *    parg  - pointer to optional device driver arguments
164 *
165 *  Output parameters:  NONE
166 *
167 *  Return values:
168 *    rtems_device_driver status code
169 */
170
171rtems_device_driver Clock_initialize(
172  rtems_device_major_number major,
173  rtems_device_minor_number minor,
174  void *pargp
175)
176{
177  Clock_Decrementer_value = (int) &CPU_PPC_CLICKS_PER_MS *
178                       (BSP_Configuration.microseconds_per_tick / 1000);
179
180  Install_clock( Clock_isr );
181 
182  /*
183   * make major/minor avail to others such as shared memory driver
184   */
185 
186  rtems_clock_major = major;
187  rtems_clock_minor = minor;
188 
189  return RTEMS_SUCCESSFUL;
190}
191 
192/*  PAGE
193 *
194 *  Clock_control
195 *
196 *  This routine is the clock device driver control entry point.
197 *
198 *  Input parameters:
199 *    major - clock device major number
200 *    minor - clock device minor number
201 *    parg  - pointer to optional device driver arguments
202 *
203 *  Output parameters:  NONE
204 *
205 *  Return values:
206 *    rtems_device_driver status code
207 */
208
209rtems_device_driver Clock_control(
210  rtems_device_major_number major,
211  rtems_device_minor_number minor,
212  void *pargp
213)
214{
215    rtems_unsigned32 isrlevel;
216    rtems_libio_ioctl_args_t *args = pargp;
217 
218    if (args == 0)
219        goto done;
220 
221    /*
222     * This is hokey, but until we get a defined interface
223     * to do this, it will just be this simple...
224     */
225 
226    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
227    {
228        Clock_isr( CLOCK_VECTOR, pargp );
229    }
230    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
231    {
232      rtems_interrupt_disable( isrlevel );
233       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
234      rtems_interrupt_enable( isrlevel );
235    }
236 
237done:
238    return RTEMS_SUCCESSFUL;
239}
240
241
242
243
244
Note: See TracBrowser for help on using the repository browser.