source: rtems/c/src/lib/libcpu/a29k/clock/ckinit.c @ 946178d

4.104.114.84.95
Last change on this file since 946178d was 946178d, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 18, 2000 at 1:09:03 PM

2000-10-18 Joel Sherrill <joel@…>

  • clock/ckinit.c: Removed commented out include of bsp.h.
  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*  ckinit.c
2 *
3 *  This file provides a template for the clock device driver initialization.
4 *
5 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
6 *  On-Line Applications Research Corporation (OAR).
7 *  All rights assigned to U.S. Government, 1994.
8 *
9 *  This material may be reproduced by or for the U.S. Government pursuant
10 *  to the copyright license under the clause at DFARS 252.227-7013.  This
11 *  notice must appear in all copies of this file and its derivatives.
12 *
13 *  $Id$
14 */
15
16#ifndef lint
17static char _sccsid[] = "@(#)ckinit.c 03/15/96     1.1\n";
18#endif
19
20#include <stdlib.h>
21
22#include <rtems.h>
23#include <rtems/libio.h>
24
25#include "clock.h"
26
27extern int CPU_CLOCK_RATE_MHZ; /* provided in bsp */
28
29#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */
30
31void Clock_exit( void );
32rtems_isr Clock_isr( rtems_vector_number vector );
33
34
35/*
36 *  The interrupt vector number associated with the clock tick device
37 *  driver.
38 */
39
40#define CLOCK_VECTOR         14
41
42/*
43 *  Clock_driver_ticks is a monotonically increasing counter of the
44 *  number of clock ticks since the driver was initialized.
45 */
46
47volatile rtems_unsigned32 Clock_driver_ticks;
48
49
50/*
51 * These are set by clock driver during its init
52 */
53 
54rtems_device_major_number rtems_clock_major = ~0;
55rtems_device_minor_number rtems_clock_minor;
56
57/*
58 *  The previous ISR on this clock tick interrupt vector.
59 */
60
61rtems_isr_entry  Old_ticker;
62
63void Clock_exit( void );
64
65static unsigned32 a29k_timer_rate = 0;
66
67/*
68 *  Isr Handler
69 */
70
71rtems_isr Clock_isr(
72  rtems_vector_number vector
73)
74{
75/*
76 * bump the number of clock driver ticks since initialization
77 *
78 * determine if it is time to announce the passing of tick as configured
79 * to RTEMS through the rtems_clock_tick directive
80 *
81 * perform any timer dependent tasks
82 */
83
84  a29k_clear_timer();
85
86  Clock_driver_ticks += 1;
87
88  rtems_clock_tick();
89}
90
91/* User callback shell (set from Clock_Control) */
92static void (*user_callback)(void);
93
94rtems_isr User_Clock_isr(
95  rtems_vector_number vector
96)
97{
98   /* refresh the internal CPU timer */
99  a29k_clear_timer();
100
101   if (user_callback)
102      user_callback();
103}
104
105/*
106 *  Install_clock
107 *
108 *  Install a clock tick handler and reprograms the chip.  This
109 *  is used to initially establish the clock tick.
110 */
111
112void Install_clock(
113  rtems_isr_entry clock_isr
114)
115{
116  /*
117   *  Initialize the clock tick device driver variables
118   */
119
120  Clock_driver_ticks = 0;
121
122  /*
123   *  If ticks_per_timeslice is configured as non-zero, then the user
124   *  wants a clock tick.
125   */
126
127  if ( rtems_configuration_get_ticks_per_timeslice() ) {
128    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
129    /*
130     *  Hardware specific initialize goes here
131     */
132
133    a29k_timer_rate = rtems_configuration_get_microseconds_per_tick() * CLOCKS_PER_MICROSECOND;
134    a29k_init_timer( a29k_timer_rate );
135  }
136
137  /*
138   *  Schedule the clock cleanup routine to execute if the application exits.
139   */
140
141  atexit( Clock_exit );
142}
143
144/*
145 *  Clean up before the application exits
146 */
147
148void Clock_exit( void )
149{
150  if ( rtems_configuration_get_ticks_per_timeslice() ) {
151
152    /* a29k: turn off the timer interrupts */
153    a29k_disable_timer();
154
155  }
156}
157
158/*
159 *  Clock_initialize
160 *
161 *  Device driver entry point for clock tick driver initialization.
162 */
163
164rtems_device_driver Clock_initialize(
165  rtems_device_major_number major,
166  rtems_device_minor_number minor,
167  void *pargp
168)
169{
170  Install_clock( Clock_isr );
171 
172  /*
173   * make major/minor avail to others such as shared memory driver
174   */
175 
176  rtems_clock_major = major;
177  rtems_clock_minor = minor;
178 
179  return RTEMS_SUCCESSFUL;
180}
181
182rtems_device_driver Clock_control(
183  rtems_device_major_number major,
184  rtems_device_minor_number minor,
185  void *pargp
186)
187{
188    rtems_unsigned32 isrlevel;
189    rtems_libio_ioctl_args_t *args = pargp;
190 
191    if (args == 0)
192        goto done;
193 
194    /*
195     * This is hokey, but until we get a defined interface
196     * to do this, it will just be this simple...
197     */
198 
199    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
200    {
201        Clock_isr(CLOCK_VECTOR);
202    }
203    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
204    {
205      rtems_interrupt_disable( isrlevel );
206      user_callback = (void (*)(void))args->buffer;
207      (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 );
208      rtems_interrupt_enable( isrlevel );
209    }
210 
211done:
212    return RTEMS_SUCCESSFUL;
213}
Note: See TracBrowser for help on using the repository browser.