source: rtems/c/src/lib/libcpu/mips64orion/clock/ckinit.c @ b944007b

4.104.114.84.95
Last change on this file since b944007b was b944007b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/08/96 at 16:24:43

added definition of EXT_INT5

  • 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, 1990, 1991, 1992, 1993, 1994.
24 *  On-Line Applications Research Corporation (OAR).
25 *  All rights assigned to U.S. Government, 1994.
26 *
27 *  This material may be reproduced by or for the U.S. Government pursuant
28 *  to the copyright license under the clause at DFARS 252.227-7013.  This
29 *  notice must appear in all copies of this file and its derivatives.
30 *
31 *  ckinit.c,v 1.5 1995/10/30 21:53:23 joel Exp
32 */
33
34#ifndef lint
35static char _sccsid[] = "@(#)ckinit.c 08/20/96     1.3\n";
36#endif
37
38#include <stdlib.h>
39
40#include <rtems.h>
41#include <rtems/libio.h>
42#include <bsp.h>
43
44#define EXT_INT5    0x8000  /* external interrupt 5 */
45
46#include "clock.h"
47
48#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */
49
50void Clock_exit( void );
51rtems_isr Clock_isr( rtems_vector_number vector );
52
53
54/*
55 *  The interrupt vector number associated with the clock tick device
56 *  driver.
57 */
58
59#define CLOCK_VECTOR_MASK    EXT_INT5
60#define CLOCK_VECTOR         0x7
61
62/*
63 *  Clock_driver_ticks is a monotonically increasing counter of the
64 *  number of clock ticks since the driver was initialized.
65 */
66
67volatile rtems_unsigned32 Clock_driver_ticks;
68
69/*
70 *  Clock_isrs is the number of clock ISRs until the next invocation of
71 *  the RTEMS clock tick routine.  The clock tick device driver
72 *  gets an interrupt once a millisecond and counts down until the
73 *  length of time between the user configured microseconds per tick
74 *  has passed.
75 */
76
77rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
78
79/*
80 * These are set by clock driver during its init
81 */
82 
83rtems_device_major_number rtems_clock_major = ~0;
84rtems_device_minor_number rtems_clock_minor;
85
86/*
87 *  The previous ISR on this clock tick interrupt vector.
88 */
89
90rtems_isr_entry  Old_ticker;
91
92void Clock_exit( void );
93
94static unsigned32 mips_timer_rate = 0;
95
96/*
97 *  Isr Handler
98 */
99
100rtems_isr Clock_isr(
101  rtems_vector_number vector
102)
103{
104/*
105 * bump the number of clock driver ticks since initialization
106 *
107 * determine if it is time to announce the passing of tick as configured
108 * to RTEMS through the rtems_clock_tick directive
109 *
110 * perform any timer dependent tasks
111 */
112
113  /* refresh the internal CPU timer */
114  mips_set_timer( mips_timer_rate );
115
116  Clock_driver_ticks += 1;
117
118  rtems_clock_tick();
119}
120
121/* User callback shell (set from Clock_Control) */
122static void (*user_callback)(void);
123
124rtems_isr User_Clock_isr(
125  rtems_vector_number vector
126)
127{
128   /* refresh the internal CPU timer */
129   mips_set_timer( mips_timer_rate );
130
131   if (user_callback)
132      user_callback();
133}
134
135/*
136 *  Install_clock
137 *
138 *  Install a clock tick handleR and reprograms the chip.  This
139 *  is used to initially establish the clock tick.
140 */
141
142void Install_clock(
143  rtems_isr_entry clock_isr
144)
145{
146  /*
147   *  Initialize the clock tick device driver variables
148   */
149
150  Clock_driver_ticks = 0;
151  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
152
153  /*
154   *  If ticks_per_timeslice is configured as non-zero, then the user
155   *  wants a clock tick.
156   */
157
158  if ( BSP_Configuration.ticks_per_timeslice ) {
159    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
160    /*
161     *  Hardware specific initialize goes here
162     */
163
164    mips_timer_rate = BSP_Configuration.microseconds_per_tick * CLOCKS_PER_MICROSECOND;
165    mips_set_timer( mips_timer_rate );
166    enable_int(CLOCK_VECTOR_MASK);
167  }
168
169  /*
170   *  Schedule the clock cleanup routine to execute if the application exits.
171   */
172
173  atexit( Clock_exit );
174}
175
176/*
177 *  Clean up before the application exits
178 */
179
180void Clock_exit( void )
181{
182  if ( BSP_Configuration.ticks_per_timeslice ) {
183
184    /* mips: turn off the timer interrupts */
185    disable_int(CLOCK_VECTOR_MASK);
186
187  }
188}
189
190/*
191 *  Clock_initialize
192 *
193 *  Device driver entry point for clock tick driver initialization.
194 */
195
196rtems_device_driver Clock_initialize(
197  rtems_device_major_number major,
198  rtems_device_minor_number minor,
199  void *pargp
200)
201{
202  Install_clock( Clock_isr );
203 
204  /*
205   * make major/minor avail to others such as shared memory driver
206   */
207 
208  rtems_clock_major = major;
209  rtems_clock_minor = minor;
210 
211  return RTEMS_SUCCESSFUL;
212}
213
214rtems_device_driver Clock_control(
215  rtems_device_major_number major,
216  rtems_device_minor_number minor,
217  void *pargp
218)
219{
220    rtems_unsigned32 isrlevel;
221    rtems_libio_ioctl_args_t *args = pargp;
222 
223    if (args == 0)
224        goto done;
225 
226    /*
227     * This is hokey, but until we get a defined interface
228     * to do this, it will just be this simple...
229     */
230 
231    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
232    {
233        Clock_isr(CLOCK_VECTOR);
234    }
235    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
236    {
237      rtems_interrupt_disable( isrlevel );
238      user_callback = (void (*)(void))args->buffer;
239      (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 );
240      rtems_interrupt_enable( isrlevel );
241    }
242 
243done:
244    return RTEMS_SUCCESSFUL;
245}
Note: See TracBrowser for help on using the repository browser.