source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/clock/ckinit.c @ 9700578

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 30, 1995 at 9:54:45 PM

SPARC port passes all tests

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*  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$
14 */
15
16#include <stdlib.h>
17
18#include <rtems.h>
19#include <rtems/libio.h>
20#include <bsp.h>
21
22void Clock_exit( void );
23rtems_isr Clock_isr( rtems_vector_number vector );
24
25
26/*
27 *  The interrupt vector number associated with the clock tick device
28 *  driver.
29 */
30
31#define CLOCK_VECTOR    4
32
33/*
34 *  Clock_driver_ticks is a monotonically increasing counter of the
35 *  number of clock ticks since the driver was initialized.
36 */
37
38volatile rtems_unsigned32 Clock_driver_ticks;
39
40/*
41 *  Clock_isrs is the number of clock ISRs until the next invocation of
42 *  the RTEMS clock tick routine.  The clock tick device driver
43 *  gets an interrupt once a millisecond and counts down until the
44 *  length of time between the user configured microseconds per tick
45 *  has passed.
46 */
47
48rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
49
50/*
51 * These are set by clock driver during its init
52 */
53 
54rtems_device_major_number rtems_clock_major = ~0;
55rtems_device_minor_number rtems_clock_minor;
56
57/*
58 *  The previous ISR on this clock tick interrupt vector.
59 */
60
61rtems_isr_entry  Old_ticker;
62
63void Clock_exit( void );
64
65
66/*
67 *  Isr Handler
68 */
69
70rtems_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
84/*
85 *  Install_clock
86 *
87 *  Install a clock tick handler and reprograms the chip.  This
88 *  is used to initially establish the clock tick.
89 */
90
91void Install_clock(
92  rtems_isr_entry clock_isr
93)
94{
95  /*
96   *  Initialize the clock tick device driver variables
97   */
98
99  Clock_driver_ticks = 0;
100  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
101
102  /*
103   *  If ticks_per_timeslice is configured as non-zero, then the user
104   *  wants a clock tick.
105   */
106
107  if ( BSP_Configuration.ticks_per_timeslice ) {
108    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
109    /*
110     *  Hardware specific initialize goes here
111     */
112
113    /* XXX */
114  }
115
116  /*
117   *  Schedule the clock cleanup routine to execute if the application exits.
118   */
119
120  atexit( Clock_exit );
121}
122
123/*
124 *  Clean up before the application exits
125 */
126
127void Clock_exit( void )
128{
129  if ( BSP_Configuration.ticks_per_timeslice ) {
130
131    /* XXX: turn off the timer interrupts */
132
133    /* XXX: If necessary, restore the old vector */
134  }
135}
136
137/*
138 *  Clock_initialize
139 *
140 *  Device driver entry point for clock tick driver initialization.
141 */
142
143rtems_device_driver Clock_initialize(
144  rtems_device_major_number major,
145  rtems_device_minor_number minor,
146  void *pargp
147)
148{
149  Install_clock( Clock_isr );
150 
151  /*
152   * make major/minor avail to others such as shared memory driver
153   */
154 
155  rtems_clock_major = major;
156  rtems_clock_minor = minor;
157 
158  return RTEMS_SUCCESSFUL;
159}
160
161rtems_device_driver Clock_control(
162  rtems_device_major_number major,
163  rtems_device_minor_number minor,
164  void *pargp
165)
166{
167    rtems_unsigned32 isrlevel;
168    rtems_libio_ioctl_args_t *args = pargp;
169 
170    if (args == 0)
171        goto done;
172 
173    /*
174     * This is hokey, but until we get a defined interface
175     * to do this, it will just be this simple...
176     */
177 
178    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
179    {
180        Clock_isr(CLOCK_VECTOR);
181    }
182    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
183    {
184      rtems_interrupt_disable( isrlevel );
185       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
186      rtems_interrupt_enable( isrlevel );
187    }
188 
189done:
190    return RTEMS_SUCCESSFUL;
191}
Note: See TracBrowser for help on using the repository browser.