source: rtems/c/src/lib/libbsp/mips/hurricane/clock/ckinit.c @ 58e37d48

4.104.114.84.95
Last change on this file since 58e37d48 was 58e37d48, checked in by Joel Sherrill <joel.sherrill@…>, on 03/12/07 at 11:17:57

2007-03-12 Joel Sherrill <joel@…>

  • clock/ckinit.c, startup/exception.S: Correct license URL and/or fix mistake in copyright notice. Both of these mistakes appear to be from code submitted after these changes were made previously.
  • Property mode set to 100644
File size: 6.1 KB
Line 
1
2/*  ckinit.c
3 *
4 *  This file contains the clock driver initialization for the Hurricane BSP.
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.rtems.com/license/LICENSE.
29 *
30 *  $Id$
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_INT1    0x800  /* 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 */
58mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int );
59
60void USC_isr( void );
61void reset_wdt(void);
62void enable_wdi(void);
63void init_hbt(void);
64void enable_hbi(void);
65void disable_hbi(void);
66
67void Clock_exit( void );
68rtems_isr Clock_isr( rtems_vector_number vector );
69
70
71/*
72 *  The interrupt vector number associated with the clock tick device
73 *  driver.
74 */
75
76#define CLOCK_VECTOR_MASK    EXT_INT1
77#define CLOCK_VECTOR         MIPS_INTERRUPT_BASE + 0x3
78
79/*
80 *  Clock_driver_ticks is a monotonically increasing counter of the
81 *  number of clock ticks since the driver was initialized.
82 */
83
84volatile uint32_t Clock_driver_ticks;
85
86/*
87 *  Clock_isrs is the number of clock ISRs until the next invocation of
88 *  the RTEMS clock tick routine.  The clock tick device driver
89 *  gets an interrupt once a millisecond and counts down until the
90 *  length of time between the user configured microseconds per tick
91 *  has passed.
92 */
93
94uint32_t Clock_isrs;              /* ISRs until next tick */
95
96/*
97 * These are set by clock driver during its init
98 */
99 
100rtems_device_major_number rtems_clock_major = ~0;
101rtems_device_minor_number rtems_clock_minor;
102
103/*
104 *  The previous ISR on this clock tick interrupt vector.
105 */
106
107rtems_isr_entry  Old_ticker;
108
109void Clock_exit( void );
110
111static uint32_t mips_timer_rate = 0;
112
113/*
114 *  Isr Handler
115 */
116
117rtems_isr Clock_isr(
118  rtems_vector_number vector
119)
120{
121/*
122 * bump the number of clock driver ticks since initialization
123 *
124 * determine if it is time to announce the passing of tick as configured
125 * to RTEMS through the rtems_clock_tick directive
126 *
127 * perform any timer dependent tasks
128 */
129
130  reset_wdt();          /* Reset hardware watchdog timer */
131
132  Clock_driver_ticks += 1;
133
134  rtems_clock_tick();
135}
136
137/* User callback shell (set from Clock_Control) */
138static void (*user_callback)(void);
139
140rtems_isr User_Clock_isr(
141  rtems_vector_number vector
142)
143{
144   if (user_callback)
145      user_callback();
146}
147
148/*
149 *  Install_clock
150 *
151 *  Install a clock tick handleR and reprograms the chip.  This
152 *  is used to initially establish the clock tick.
153 */
154
155void Install_clock(
156  rtems_isr_entry clock_isr
157)
158{
159        /*
160        *  Initialize the clock tick device driver variables
161        */
162
163        Clock_driver_ticks = 0;
164        Clock_isrs = rtems_configuration_get_milliseconds_per_tick();
165
166        mips_timer_rate =
167                rtems_configuration_get_microseconds_per_tick() * CLOCKS_PER_MICROSECOND;
168
169        /*
170        *  Hardware specific initialize goes here
171        */
172       
173        /* Set up USC heartbeat timer to generate interrupts */
174        disable_hbi();                  /* Disable heartbeat interrupt in USC */
175       
176                                                        /* Install interrupt handler */
177        Old_ticker = (rtems_isr_entry) set_vector( USC_isr, CLOCK_VECTOR, 1 );
178       
179        init_hbt();                             /* Initialize heartbeat timer */
180       
181        reset_wdt();                    /* Reset watchdog timer */
182       
183        enable_wdi();                   /* Enable watchdog interrupt in USC */
184       
185        enable_hbi();                   /* Enable heartbeat interrupt in USC */
186       
187                                                        /* Enable USC interrupt in MIPS processor */
188        mips_enable_in_interrupt_mask(CLOCK_VECTOR_MASK);
189       
190        /*
191        *  Schedule the clock cleanup routine to execute if the application exits.
192        */
193
194        atexit( Clock_exit );
195}
196
197/*
198 *  Clean up before the application exits
199 */
200
201void Clock_exit( void )
202{
203  /* mips: turn off the timer interrupts */
204  mips_disable_in_interrupt_mask(~CLOCK_VECTOR_MASK);
205}
206
207/*
208 *  Clock_initialize
209 *
210 *  Device driver entry point for clock tick driver initialization.
211 */
212
213rtems_device_driver Clock_initialize(
214  rtems_device_major_number major,
215  rtems_device_minor_number minor,
216  void *pargp
217)
218{
219  Install_clock( Clock_isr );
220 
221  /*
222   * make major/minor avail to others such as shared memory driver
223   */
224 
225  rtems_clock_major = major;
226  rtems_clock_minor = minor;
227 
228  return RTEMS_SUCCESSFUL;
229}
230
231rtems_device_driver Clock_control(
232  rtems_device_major_number major,
233  rtems_device_minor_number minor,
234  void *pargp
235)
236{
237    uint32_t isrlevel;
238    rtems_libio_ioctl_args_t *args = pargp;
239 
240    if (args == 0)
241        goto done;
242 
243    /*
244     * This is hokey, but until we get a defined interface
245     * to do this, it will just be this simple...
246     */
247 
248    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
249    {
250        Clock_isr(CLOCK_VECTOR);
251    }
252    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
253    {
254      rtems_interrupt_disable( isrlevel );
255      user_callback = (void (*)(void))args->buffer;
256      (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 );
257      rtems_interrupt_enable( isrlevel );
258    }
259 
260done:
261    return RTEMS_SUCCESSFUL;
262}
Note: See TracBrowser for help on using the repository browser.