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

Subversion Repositories openrisc_me

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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