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

4.104.114.84.95
Last change on this file since 0dd1d44 was 0dd1d44, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 11, 2000 at 5:34:20 PM

Removed old hack of using Configuration Table entry ticks_per_timeslice
being set to 0 to indicate that there should be no Clock Tick. This
was used by the Timing Tests to avoid clock tick overhead perturbing
execution times. Now the Timing Tests simply leave the Clock Tick
Driver out of the Device Driver Table.

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