source: rtems/c/src/lib/libbsp/powerpc/ppcn_60x/clock/clock.c @ fa2c7a41

4.104.114.84.95
Last change on this file since fa2c7a41 was fa2c7a41, checked in by Joel Sherrill <joel.sherrill@…>, on 04/26/05 at 23:15:58

2005-04-26 Joel Sherrill <joel@…>

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