source: rtems/c/src/lib/libbsp/sparc/leon/clock/ckinit.c @ b21b0ab

4.104.114.84.95
Last change on this file since b21b0ab was b21b0ab, checked in by Joel Sherrill <joel.sherrill@…>, on 11/13/00 at 22:40:29

2000-11-13 Jiri Gaisler <jgais@…>

  • .cvsignore, ChangeLog?, Makefile.am, README, bsp_specs, configure.in, times, clock/.cvsignore, clock/Makefile.am, clock/ckinit.c, console/.cvsignore, console/Makefile.am, console/console.c, console/consolereserveresources.c, console/debugputs.c, gnatsupp/.cvsignore, gnatsupp/Makefile.am, gnatsupp/gnatsupp.c, include/.cvsignore, include/Makefile.am, include/bsp.h, include/coverhd.h, include/leon.h, start/.cvsignore, start/Makefile.am, startup/.cvsignore, startup/Makefile.am, startup/boardinit.S, startup/linkcmds, startup/setvec.c, startup/spurious.c, timer/.cvsignore, timer/Makefile.am, timer/timer.c, tools/.cvsignore, tools/Makefile.am, tools/configure.in, tools/runtest.in, wrapup/.cvsignore, wrapup/Makefile.am: New file.
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 *  Clock Tick Device Driver
3 *
4 *  This routine initializes LEON timer 1 which used for the clock tick.
5 *
6 *  The tick frequency is directly programmed to the configured number of
7 *  microseconds per tick.
8 *
9 *  COPYRIGHT (c) 1989-1998.
10 *  On-Line Applications Research Corporation (OAR).
11 *  Copyright assigned to U.S. Government, 1994.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  Ported to LEON implementation of the SPARC by On-Line Applications
18 *  Research Corporation (OAR) under contract to the European Space
19 *  Agency (ESA).
20 *
21 *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
22 *  European Space Agency.
23 *
24 *  $Id$
25 */
26
27#include <stdlib.h>
28
29#include <bsp.h>
30#include <rtems/libio.h>
31
32/*
33 *  The Real Time Clock Counter Timer uses this trap type.
34 */
35
36#define CLOCK_VECTOR LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 )
37
38/*
39 *  Clock ticks since initialization
40 */
41
42volatile rtems_unsigned32 Clock_driver_ticks;
43
44/*
45 *  This is the value programmed into the count down timer.  It
46 *  is artificially lowered when SIMSPARC_FAST_IDLE is defined to
47 *  cut down how long we spend in the idle task while executing on
48 *  the simulator.
49 */
50
51extern rtems_unsigned32 CPU_SPARC_CLICKS_PER_TICK;
52
53rtems_isr_entry  Old_ticker;
54
55void Clock_exit( void );
56 
57/*
58 * These are set by clock driver during its init
59 */
60 
61rtems_device_major_number rtems_clock_major = ~0;
62rtems_device_minor_number rtems_clock_minor;
63
64/*
65 *  Clock_isr
66 *
67 *  This is the clock tick interrupt handler.
68 *
69 *  Input parameters:
70 *    vector - vector number
71 *
72 *  Output parameters:  NONE
73 *
74 *  Return values:      NONE
75 *
76 */
77
78rtems_isr Clock_isr(
79  rtems_vector_number vector
80)
81{
82  /*
83   *  If we are in "fast idle" mode, then the value for clicks per tick
84   *  is lowered to decrease the amount of time spent executing the idle
85   *  task while using the SPARC Instruction Simulator.
86   */
87
88#if SIMSPARC_FAST_IDLE
89  LEON_REG.Real_Time_Clock_Counter = CPU_SPARC_CLICKS_PER_TICK;
90  LEON_REG_Set_Real_Time_Clock_Timer_Control(
91    LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
92      LEON_REG_TIMER_COUNTER_LOAD_COUNTER
93  );
94#endif
95
96  /*
97   *  The driver has seen another tick.
98   */
99
100  Clock_driver_ticks += 1;
101
102  /*
103   *  Real Time Clock counter/timer is set to automatically reload.
104   */
105
106  rtems_clock_tick();
107}
108
109/*
110 *  Install_clock
111 *
112 *  This routine actually performs the hardware initialization for the clock.
113 *
114 *  Input parameters:
115 *    clock_isr - clock interrupt service routine entry point
116 *
117 *  Output parameters:  NONE
118 *
119 *  Return values:      NONE
120 *
121 */
122
123void Install_clock(
124  rtems_isr_entry clock_isr
125)
126{
127  Clock_driver_ticks = 0;
128
129  if ( BSP_Configuration.ticks_per_timeslice ) {
130    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
131
132    LEON_REG.Timer_Reload_1  = CPU_SPARC_CLICKS_PER_TICK - 1;
133
134    LEON_REG.Timer_Control_1 = (
135      LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
136        LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO |
137        LEON_REG_TIMER_COUNTER_LOAD_COUNTER
138    );
139 
140    atexit( Clock_exit );
141  }
142
143}
144
145/*
146 *  Clock_exit
147 *
148 *  This routine allows the clock driver to exit by masking the interrupt and
149 *  disabling the clock's counter.
150 *
151 *  Input parameters:   NONE
152 *
153 *  Output parameters:  NONE
154 *
155 *  Return values:      NONE
156 *
157 */
158
159void Clock_exit( void )
160{
161  if ( BSP_Configuration.ticks_per_timeslice ) {
162    LEON_Mask_interrupt( LEON_INTERRUPT_TIMER1 );
163
164    LEON_REG.Timer_Control_1 = 0;
165
166    /* do not restore old vector */
167  }
168}
169 
170/*
171 *  Clock_initialize
172 *
173 *  This routine initializes the clock driver.
174 *
175 *  Input parameters:
176 *    major - clock device major number
177 *    minor - clock device minor number
178 *    parg  - pointer to optional device driver arguments
179 *
180 *  Output parameters:  NONE
181 *
182 *  Return values:
183 *    rtems_device_driver status code
184 */
185
186rtems_device_driver Clock_initialize(
187  rtems_device_major_number major,
188  rtems_device_minor_number minor,
189  void *pargp
190)
191{
192  Install_clock( Clock_isr );
193 
194  /*
195   * make major/minor avail to others such as shared memory driver
196   */
197 
198  rtems_clock_major = major;
199  rtems_clock_minor = minor;
200 
201  return RTEMS_SUCCESSFUL;
202}
203 
204/*
205 *  Clock_control
206 *
207 *  This routine is the clock device driver control entry point.
208 *
209 *  Input parameters:
210 *    major - clock device major number
211 *    minor - clock device minor number
212 *    parg  - pointer to optional device driver arguments
213 *
214 *  Output parameters:  NONE
215 *
216 *  Return values:
217 *    rtems_device_driver status code
218 */
219
220rtems_device_driver Clock_control(
221  rtems_device_major_number major,
222  rtems_device_minor_number minor,
223  void *pargp
224)
225{
226    rtems_unsigned32 isrlevel;
227    rtems_libio_ioctl_args_t *args = pargp;
228 
229    if (args == 0)
230        goto done;
231 
232    /*
233     * This is hokey, but until we get a defined interface
234     * to do this, it will just be this simple...
235     */
236 
237    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
238    {
239        Clock_isr(CLOCK_VECTOR);
240    }
241    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
242    {
243      rtems_interrupt_disable( isrlevel );
244       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
245      rtems_interrupt_enable( isrlevel );
246    }
247 
248done:
249    return RTEMS_SUCCESSFUL;
250}
Note: See TracBrowser for help on using the repository browser.