OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [mips64orion/] [clock/] [ckinit.c] - Blame information for rev 228

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
 
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-1999.
24
 *  On-Line Applications Research Corporation (OAR).
25
 *
26
 *  The license and distribution terms for this file may be
27
 *  found in the file LICENSE in this distribution or at
28
 *  http://www.OARcorp.com/rtems/license.html.
29
 *
30
 *  $Id: ckinit.c,v 1.2 2001-09-27 12:01:22 chris Exp $
31
 */
32
 
33
/*
34
 *  Rather than deleting this, it is commented out to (hopefully) help
35
 *  the submitter send updates.
36
 *
37
 *  static char _sccsid[] = "@(#)ckinit.c 08/20/96     1.3\n";
38
 */
39
 
40
 
41
#include <stdlib.h>
42
 
43
#include <rtems.h>
44
#include <rtems/libio.h>
45
 
46
#define EXT_INT5    0x8000  /* external interrupt 5 */
47
 
48
#include "clock.h"
49
 
50
/* formerly in the BSP */
51
#if 0
52
#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */
53
#endif
54
 
55
#define CLOCKS_PER_MICROSECOND \
56
  rtems_cpu_configuration_get_clicks_per_microsecond()
57
/* to avoid including the bsp */
58
mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int );
59
 
60
void Clock_exit( void );
61
rtems_isr Clock_isr( rtems_vector_number vector );
62
 
63
 
64
/*
65
 *  The interrupt vector number associated with the clock tick device
66
 *  driver.
67
 */
68
 
69
#define CLOCK_VECTOR_MASK    EXT_INT5
70
#define CLOCK_VECTOR         0x7
71
 
72
/*
73
 *  Clock_driver_ticks is a monotonically increasing counter of the
74
 *  number of clock ticks since the driver was initialized.
75
 */
76
 
77
volatile rtems_unsigned32 Clock_driver_ticks;
78
 
79
/*
80
 *  Clock_isrs is the number of clock ISRs until the next invocation of
81
 *  the RTEMS clock tick routine.  The clock tick device driver
82
 *  gets an interrupt once a millisecond and counts down until the
83
 *  length of time between the user configured microseconds per tick
84
 *  has passed.
85
 */
86
 
87
rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
88
 
89
/*
90
 * These are set by clock driver during its init
91
 */
92
 
93
rtems_device_major_number rtems_clock_major = ~0;
94
rtems_device_minor_number rtems_clock_minor;
95
 
96
/*
97
 *  The previous ISR on this clock tick interrupt vector.
98
 */
99
 
100
rtems_isr_entry  Old_ticker;
101
 
102
void Clock_exit( void );
103
 
104
static unsigned32 mips_timer_rate = 0;
105
 
106
/*
107
 *  Isr Handler
108
 */
109
 
110
rtems_isr Clock_isr(
111
  rtems_vector_number vector
112
)
113
{
114
/*
115
 * bump the number of clock driver ticks since initialization
116
 *
117
 * determine if it is time to announce the passing of tick as configured
118
 * to RTEMS through the rtems_clock_tick directive
119
 *
120
 * perform any timer dependent tasks
121
 */
122
 
123
  /* refresh the internal CPU timer */
124
  mips_set_timer( mips_timer_rate );
125
 
126
  Clock_driver_ticks += 1;
127
 
128
  rtems_clock_tick();
129
}
130
 
131
/* User callback shell (set from Clock_Control) */
132
static void (*user_callback)(void);
133
 
134
rtems_isr User_Clock_isr(
135
  rtems_vector_number vector
136
)
137
{
138
   /* refresh the internal CPU timer */
139
   mips_set_timer( mips_timer_rate );
140
 
141
   if (user_callback)
142
      user_callback();
143
}
144
 
145
/*
146
 *  Install_clock
147
 *
148
 *  Install a clock tick handleR and reprograms the chip.  This
149
 *  is used to initially establish the clock tick.
150
 */
151
 
152
void Install_clock(
153
  rtems_isr_entry clock_isr
154
)
155
{
156
  /*
157
   *  Initialize the clock tick device driver variables
158
   */
159
 
160
  Clock_driver_ticks = 0;
161
  Clock_isrs = rtems_configuration_get_milliseconds_per_tick();
162
 
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 =
169
     rtems_configuration_get_microseconds_per_tick() * CLOCKS_PER_MICROSECOND;
170
  mips_set_timer( mips_timer_rate );
171
  enable_int(CLOCK_VECTOR_MASK);
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
 
184
void Clock_exit( void )
185
{
186
  /* mips: turn off the timer interrupts */
187
  disable_int(~CLOCK_VECTOR_MASK);
188
}
189
 
190
/*
191
 *  Clock_initialize
192
 *
193
 *  Device driver entry point for clock tick driver initialization.
194
 */
195
 
196
rtems_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
 
214
rtems_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
 
243
done:
244
    return RTEMS_SUCCESSFUL;
245
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.