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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [dmv177/] [clock/] [clock.c] - Blame information for rev 389

Go to most recent revision | 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
 *  $Id: clock.c,v 1.2 2001-09-27 12:00:32 chris Exp $
18
 */
19
 
20
#include <stdlib.h>
21
 
22
#include <bsp.h>
23
#include <rtems/libio.h>
24
 
25
extern 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
 
37
volatile rtems_unsigned32 Clock_driver_ticks;
38
 
39
/*
40
 *  This is the value programmed into the count down timer.
41
 */
42
 
43
rtems_unsigned32 Clock_Decrementer_value;
44
 
45
/*
46
 * This is the value of the old isr routine.
47
 */
48
rtems_isr_entry  Old_ticker;
49
 
50
 
51
void Clock_exit( void );
52
 
53
/*
54
 * These are set by clock driver during its init
55
 */
56
 
57
rtems_device_major_number rtems_clock_major = ~0;
58
rtems_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
 
75
rtems_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
 
114
extern int CLOCK_SPEED;
115
 
116
void 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
 
144
void 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
 
168
rtems_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
 
206
rtems_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
 
234
done:
235
    return RTEMS_SUCCESSFUL;
236
}
237
 
238
 
239
 
240
 
241
 

powered by: WebSVN 2.1.0

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