source: rtems/c/src/lib/libcpu/a29k/clock/ckinit.c @ 2a1ca73

4.104.114.84.95
Last change on this file since 2a1ca73 was 2a1ca73, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 25, 2000 at 7:06:25 PM

2000-09-25 Joel Sherrill <joel@…>

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