source: rtems/c/src/lib/libcpu/mips/clock/ckinit.c @ 707f5c7

4.104.114.84.95
Last change on this file since 707f5c7 was f817b02, checked in by Joel Sherrill <joel.sherrill@…>, on 11/04/99 at 18:05:09

The files in libcpu should not be directly dependent on any BSP. In
particular, using bsp.h, or getting information from the BSP which
should properly be obtained from RTEMS is forbidden. This is
necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.
The changes primarily eliminated the need to include bsp.h and
peeking at BSP_Configuration. The use of Cpu_table in each
BSP needs to be eliminated.

  • Property mode set to 100644
File size: 5.9 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-1998.
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 be
28 *  found in 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
47#define EXT_INT5    0x8000  /* external interrupt 5 */
48
49#include "clock.h"
50
51/* formerly in the BSP */
52#if 0
53#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */
54#endif
55
56#define CLOCKS_PER_MICROSECOND \
57  rtems_cpu_configuration_get_clicks_per_microsecond()
58/* to avoid including the bsp */
59mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int );
60
61void Clock_exit( void );
62rtems_isr Clock_isr( rtems_vector_number vector );
63
64
65/*
66 *  The interrupt vector number associated with the clock tick device
67 *  driver.
68 */
69
70#define CLOCK_VECTOR_MASK    EXT_INT5
71#define CLOCK_VECTOR         0x7
72
73/*
74 *  Clock_driver_ticks is a monotonically increasing counter of the
75 *  number of clock ticks since the driver was initialized.
76 */
77
78volatile rtems_unsigned32 Clock_driver_ticks;
79
80/*
81 *  Clock_isrs is the number of clock ISRs until the next invocation of
82 *  the RTEMS clock tick routine.  The clock tick device driver
83 *  gets an interrupt once a millisecond and counts down until the
84 *  length of time between the user configured microseconds per tick
85 *  has passed.
86 */
87
88rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
89
90/*
91 * These are set by clock driver during its init
92 */
93 
94rtems_device_major_number rtems_clock_major = ~0;
95rtems_device_minor_number rtems_clock_minor;
96
97/*
98 *  The previous ISR on this clock tick interrupt vector.
99 */
100
101rtems_isr_entry  Old_ticker;
102
103void Clock_exit( void );
104
105static unsigned32 mips_timer_rate = 0;
106
107/*
108 *  Isr Handler
109 */
110
111rtems_isr Clock_isr(
112  rtems_vector_number vector
113)
114{
115/*
116 * bump the number of clock driver ticks since initialization
117 *
118 * determine if it is time to announce the passing of tick as configured
119 * to RTEMS through the rtems_clock_tick directive
120 *
121 * perform any timer dependent tasks
122 */
123
124  /* refresh the internal CPU timer */
125  mips_set_timer( mips_timer_rate );
126
127  Clock_driver_ticks += 1;
128
129  rtems_clock_tick();
130}
131
132/* User callback shell (set from Clock_Control) */
133static void (*user_callback)(void);
134
135rtems_isr User_Clock_isr(
136  rtems_vector_number vector
137)
138{
139   /* refresh the internal CPU timer */
140   mips_set_timer( mips_timer_rate );
141
142   if (user_callback)
143      user_callback();
144}
145
146/*
147 *  Install_clock
148 *
149 *  Install a clock tick handleR and reprograms the chip.  This
150 *  is used to initially establish the clock tick.
151 */
152
153void Install_clock(
154  rtems_isr_entry clock_isr
155)
156{
157  /*
158   *  Initialize the clock tick device driver variables
159   */
160
161  Clock_driver_ticks = 0;
162  Clock_isrs = rtems_configuration_get_milliseconds_per_tick();
163
164  /*
165   *  If ticks_per_timeslice is configured as non-zero, then the user
166   *  wants a clock tick.
167   */
168
169  if ( rtems_configuration_get_ticks_per_timeslice() ) {
170    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
171    /*
172     *  Hardware specific initialize goes here
173     */
174
175    mips_timer_rate = rtems_configuration_get_microseconds_per_tick() * CLOCKS_PER_MICROSECOND;
176    mips_set_timer( mips_timer_rate );
177    enable_int(CLOCK_VECTOR_MASK);
178  }
179
180  /*
181   *  Schedule the clock cleanup routine to execute if the application exits.
182   */
183
184  atexit( Clock_exit );
185}
186
187/*
188 *  Clean up before the application exits
189 */
190
191void Clock_exit( void )
192{
193  if ( rtems_configuration_get_ticks_per_timeslice() ) {
194    /* mips: turn off the timer interrupts */
195    disable_int(CLOCK_VECTOR_MASK);
196  }
197}
198
199/*
200 *  Clock_initialize
201 *
202 *  Device driver entry point for clock tick driver initialization.
203 */
204
205rtems_device_driver Clock_initialize(
206  rtems_device_major_number major,
207  rtems_device_minor_number minor,
208  void *pargp
209)
210{
211  Install_clock( Clock_isr );
212 
213  /*
214   * make major/minor avail to others such as shared memory driver
215   */
216 
217  rtems_clock_major = major;
218  rtems_clock_minor = minor;
219 
220  return RTEMS_SUCCESSFUL;
221}
222
223rtems_device_driver Clock_control(
224  rtems_device_major_number major,
225  rtems_device_minor_number minor,
226  void *pargp
227)
228{
229    rtems_unsigned32 isrlevel;
230    rtems_libio_ioctl_args_t *args = pargp;
231 
232    if (args == 0)
233        goto done;
234 
235    /*
236     * This is hokey, but until we get a defined interface
237     * to do this, it will just be this simple...
238     */
239 
240    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
241    {
242        Clock_isr(CLOCK_VECTOR);
243    }
244    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
245    {
246      rtems_interrupt_disable( isrlevel );
247      user_callback = (void (*)(void))args->buffer;
248      (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 );
249      rtems_interrupt_enable( isrlevel );
250    }
251 
252done:
253    return RTEMS_SUCCESSFUL;
254}
Note: See TracBrowser for help on using the repository browser.