source: rtems/c/src/lib/libcpu/mips/clock/ckinit.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:20:27 PM

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1
2/*  ckinit.c
3 *
4 *  This file contains the clock driver initialization for the IDT 4650.
5 *
6 *  Author:     Craig Lebakken <craigl@transition.com>
7 *
8 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
9 *
10 *  To anyone who acknowledges that this file is provided "AS IS"
11 *  without any express or implied warranty:
12 *      permission to use, copy, modify, and distribute this file
13 *      for any purpose is hereby granted without fee, provided that
14 *      the above copyright notice and this notice appears in all
15 *      copies, and that the name of Transition Networks not be used in
16 *      advertising or publicity pertaining to distribution of the
17 *      software without specific, written prior permission.
18 *      Transition Networks makes no representations about the suitability
19 *      of this software for any purpose.
20 *
21 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/clock/ckinit.c:
22 *
23 *  COPYRIGHT (c) 1989-1997.
24 *  On-Line Applications Research Corporation (OAR).
25 *  Copyright assigned to U.S. Government, 1994.
26 *
27 *  The license and distribution terms for this file may in
28 *  the file LICENSE in this distribution or at
29 *  http://www.OARcorp.com/rtems/license.html.
30 *
31 *  $Id$
32 */
33
34/*
35 *  Rather than deleting this, it is commented out to (hopefully) help
36 *  the submitter send updates.
37 *
38 *  static char _sccsid[] = "@(#)ckinit.c 08/20/96     1.3\n";
39 */
40
41
42#include <stdlib.h>
43
44#include <rtems.h>
45#include <rtems/libio.h>
46#include <bsp.h>
47
48#define EXT_INT5    0x8000  /* external interrupt 5 */
49
50#include "clock.h"
51
52#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */
53
54void Clock_exit( void );
55rtems_isr Clock_isr( rtems_vector_number vector );
56
57
58/*
59 *  The interrupt vector number associated with the clock tick device
60 *  driver.
61 */
62
63#define CLOCK_VECTOR_MASK    EXT_INT5
64#define CLOCK_VECTOR         0x7
65
66/*
67 *  Clock_driver_ticks is a monotonically increasing counter of the
68 *  number of clock ticks since the driver was initialized.
69 */
70
71volatile rtems_unsigned32 Clock_driver_ticks;
72
73/*
74 *  Clock_isrs is the number of clock ISRs until the next invocation of
75 *  the RTEMS clock tick routine.  The clock tick device driver
76 *  gets an interrupt once a millisecond and counts down until the
77 *  length of time between the user configured microseconds per tick
78 *  has passed.
79 */
80
81rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
82
83/*
84 * These are set by clock driver during its init
85 */
86 
87rtems_device_major_number rtems_clock_major = ~0;
88rtems_device_minor_number rtems_clock_minor;
89
90/*
91 *  The previous ISR on this clock tick interrupt vector.
92 */
93
94rtems_isr_entry  Old_ticker;
95
96void Clock_exit( void );
97
98static unsigned32 mips_timer_rate = 0;
99
100/*
101 *  Isr Handler
102 */
103
104rtems_isr Clock_isr(
105  rtems_vector_number vector
106)
107{
108/*
109 * bump the number of clock driver ticks since initialization
110 *
111 * determine if it is time to announce the passing of tick as configured
112 * to RTEMS through the rtems_clock_tick directive
113 *
114 * perform any timer dependent tasks
115 */
116
117  /* refresh the internal CPU timer */
118  mips_set_timer( mips_timer_rate );
119
120  Clock_driver_ticks += 1;
121
122  rtems_clock_tick();
123}
124
125/* User callback shell (set from Clock_Control) */
126static void (*user_callback)(void);
127
128rtems_isr User_Clock_isr(
129  rtems_vector_number vector
130)
131{
132   /* refresh the internal CPU timer */
133   mips_set_timer( mips_timer_rate );
134
135   if (user_callback)
136      user_callback();
137}
138
139/*
140 *  Install_clock
141 *
142 *  Install a clock tick handleR and reprograms the chip.  This
143 *  is used to initially establish the clock tick.
144 */
145
146void Install_clock(
147  rtems_isr_entry clock_isr
148)
149{
150  /*
151   *  Initialize the clock tick device driver variables
152   */
153
154  Clock_driver_ticks = 0;
155  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
156
157  /*
158   *  If ticks_per_timeslice is configured as non-zero, then the user
159   *  wants a clock tick.
160   */
161
162  if ( BSP_Configuration.ticks_per_timeslice ) {
163    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
164    /*
165     *  Hardware specific initialize goes here
166     */
167
168    mips_timer_rate = BSP_Configuration.microseconds_per_tick * CLOCKS_PER_MICROSECOND;
169    mips_set_timer( mips_timer_rate );
170    enable_int(CLOCK_VECTOR_MASK);
171  }
172
173  /*
174   *  Schedule the clock cleanup routine to execute if the application exits.
175   */
176
177  atexit( Clock_exit );
178}
179
180/*
181 *  Clean up before the application exits
182 */
183
184void Clock_exit( void )
185{
186  if ( BSP_Configuration.ticks_per_timeslice ) {
187
188    /* mips: turn off the timer interrupts */
189    disable_int(CLOCK_VECTOR_MASK);
190
191  }
192}
193
194/*
195 *  Clock_initialize
196 *
197 *  Device driver entry point for clock tick driver initialization.
198 */
199
200rtems_device_driver Clock_initialize(
201  rtems_device_major_number major,
202  rtems_device_minor_number minor,
203  void *pargp
204)
205{
206  Install_clock( Clock_isr );
207 
208  /*
209   * make major/minor avail to others such as shared memory driver
210   */
211 
212  rtems_clock_major = major;
213  rtems_clock_minor = minor;
214 
215  return RTEMS_SUCCESSFUL;
216}
217
218rtems_device_driver Clock_control(
219  rtems_device_major_number major,
220  rtems_device_minor_number minor,
221  void *pargp
222)
223{
224    rtems_unsigned32 isrlevel;
225    rtems_libio_ioctl_args_t *args = pargp;
226 
227    if (args == 0)
228        goto done;
229 
230    /*
231     * This is hokey, but until we get a defined interface
232     * to do this, it will just be this simple...
233     */
234 
235    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
236    {
237        Clock_isr(CLOCK_VECTOR);
238    }
239    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
240    {
241      rtems_interrupt_disable( isrlevel );
242      user_callback = (void (*)(void))args->buffer;
243      (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 );
244      rtems_interrupt_enable( isrlevel );
245    }
246 
247done:
248    return RTEMS_SUCCESSFUL;
249}
Note: See TracBrowser for help on using the repository browser.