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

4.104.114.84.95
Last change on this file since bdb2899 was 2785eab2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 16:01:12

Changed calculaction for Clock_Decrementer_value to use the
BSP_configuration table.

  • 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
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  if ( BSP_Configuration.ticks_per_timeslice ) {
123    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
124
125    PPC_Set_decrementer( Clock_Decrementer_value );
126
127    atexit( Clock_exit );
128  }
129}
130
131/*PAGE
132 *
133 *  Clock_exit
134 *
135 *  This routine allows the clock driver to exit by masking the interrupt and
136 *  disabling the clock's counter.
137 *
138 *  Input parameters:   NONE
139 *
140 *  Output parameters:  NONE
141 *
142 *  Return values:      NONE
143 *
144 */
145
146void Clock_exit( void )
147{
148  if ( BSP_Configuration.ticks_per_timeslice ) {
149
150    /* nothing to do */;
151
152    /* do not restore old vector */
153  }
154}
155 
156/*PAGE
157 *
158 *  Clock_initialize
159 *
160 *  This routine initializes the clock driver.
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
173rtems_device_driver Clock_initialize(
174  rtems_device_major_number major,
175  rtems_device_minor_number minor,
176  void *pargp
177)
178{
179  Clock_Decrementer_value = Cpu_table.clicks_per_usec *
180                       BSP_Configuration.microseconds_per_tick;
181
182  Install_clock( Clock_isr );
183 
184  /*
185   * make major/minor avail to others such as shared memory driver
186   */
187 
188  rtems_clock_major = major;
189  rtems_clock_minor = minor;
190 
191  return RTEMS_SUCCESSFUL;
192}
193 
194/*  PAGE
195 *
196 *  Clock_control
197 *
198 *  This routine is the clock device driver control entry point.
199 *
200 *  Input parameters:
201 *    major - clock device major number
202 *    minor - clock device minor number
203 *    parg  - pointer to optional device driver arguments
204 *
205 *  Output parameters:  NONE
206 *
207 *  Return values:
208 *    rtems_device_driver status code
209 */
210
211rtems_device_driver Clock_control(
212  rtems_device_major_number major,
213  rtems_device_minor_number minor,
214  void *pargp
215)
216{
217    rtems_unsigned32 isrlevel;
218    rtems_libio_ioctl_args_t *args = pargp;
219 
220    if (args == 0)
221        goto done;
222 
223    /*
224     * This is hokey, but until we get a defined interface
225     * to do this, it will just be this simple...
226     */
227 
228    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
229    {
230        Clock_isr( CLOCK_VECTOR, pargp );
231    }
232    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
233    {
234      rtems_interrupt_disable( isrlevel );
235       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
236      rtems_interrupt_enable( isrlevel );
237    }
238 
239done:
240    return RTEMS_SUCCESSFUL;
241}
242
243
244
245
246
Note: See TracBrowser for help on using the repository browser.