source: rtems/c/src/lib/libbsp/mips/hurricane/clock/ckinit.c @ 0c0181d

4.115
Last change on this file since 0c0181d was 0c0181d, checked in by Jennifer Averett <jennifer.averett@…>, on 04/04/12 at 13:39:46

PR 1993 - Convert MIPS to PIC IRQ model

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/**
2 *  @file
3 * 
4 *  This file contains the clock driver initialization for the Hurricane BSP.
5 */
6
7/*
8 *  Author:     Craig Lebakken <craigl@transition.com>
9 *
10 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
11 *
12 *  To anyone who acknowledges that this file is provided "AS IS"
13 *  without any express or implied warranty:
14 *      permission to use, copy, modify, and distribute this file
15 *      for any purpose is hereby granted without fee, provided that
16 *      the above copyright notice and this notice appears in all
17 *      copies, and that the name of Transition Networks not be used in
18 *      advertising or publicity pertaining to distribution of the
19 *      software without specific, written prior permission.
20 *      Transition Networks makes no representations about the suitability
21 *      of this software for any purpose.
22 *
23 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/clock/ckinit.c
24 *
25 *  COPYRIGHT (c) 1989-2012.
26 *  On-Line Applications Research Corporation (OAR).
27 *
28 *  The license and distribution terms for this file may be
29 *  found in the file LICENSE in this distribution or at
30 *  http://www.rtems.com/license/LICENSE.
31 *
32 *  $Id$
33 */
34
35/*
36 *  Rather than deleting this, it is commented out to (hopefully) help
37 *  the submitter send updates.
38 *
39 *  static char _sccsid[] = "@(#)ckinit.c 08/20/96     1.3\n";
40 */
41
42
43#include <stdlib.h>
44
45#include <rtems.h>
46#include <bsp.h>
47#include <bsp/irq.h>
48
49extern uint32_t bsp_clicks_per_microsecond;
50
51#define EXT_INT1    0x800  /* external interrupt 5 */
52
53#include "clock.h"
54
55rtems_isr USC_isr(void *unused);
56
57void reset_wdt(void);
58void enable_wdi(void);
59void init_hbt(void);
60void enable_hbi(void);
61void disable_hbi(void);
62
63void Clock_exit(void);
64rtems_isr Clock_isr(rtems_vector_number vector);
65rtems_isr User_Clock_isr(rtems_vector_number vector);
66void Install_clock(rtems_isr_entry clock_isr);
67
68
69/*
70 *  The interrupt vector number associated with the clock tick device
71 *  driver.
72 */
73
74#define CLOCK_VECTOR_MASK    EXT_INT1
75#define CLOCK_VECTOR         MIPS_INTERRUPT_BASE + 0x3
76
77/*
78 *  Clock_driver_ticks is a monotonically increasing counter of the
79 *  number of clock ticks since the driver was initialized.
80 */
81
82volatile uint32_t Clock_driver_ticks;
83
84/*
85 *  Clock_isrs is the number of clock ISRs until the next invocation of
86 *  the RTEMS clock tick routine.  The clock tick device driver
87 *  gets an interrupt once a millisecond and counts down until the
88 *  length of time between the user configured microseconds per tick
89 *  has passed.
90 */
91
92uint32_t Clock_isrs;              /* ISRs until next tick */
93
94/*
95 *  The previous ISR on this clock tick interrupt vector.
96 */
97
98rtems_isr_entry  Old_ticker;
99
100void Clock_exit( void );
101
102static uint32_t mips_timer_rate = 0;
103
104/*
105 *  Isr Handler
106 */
107
108rtems_isr Clock_isr(
109  rtems_vector_number vector
110)
111{
112/*
113 * bump the number of clock driver ticks since initialization
114 *
115 * determine if it is time to announce the passing of tick as configured
116 * to RTEMS through the rtems_clock_tick directive
117 *
118 * perform any timer dependent tasks
119 */
120
121  reset_wdt();    /* Reset hardware watchdog timer */
122
123  Clock_driver_ticks += 1;
124
125  rtems_clock_tick();
126}
127
128/* User callback shell (set from Clock_Control) */
129static void (*user_callback)(void);
130
131rtems_isr User_Clock_isr(
132  rtems_vector_number vector
133)
134{
135   if (user_callback)
136      user_callback();
137}
138
139/*
140 *  Install_clock
141 *
142 *  Install a clock tick handleR and reprograms the chip.  This
143 *  is used to initially establish the clock tick.
144 */
145
146void Install_clock(
147  rtems_isr_entry clock_isr
148)
149{
150  /*
151  *  Initialize the clock tick device driver variables
152  */
153
154  Clock_driver_ticks = 0;
155  Clock_isrs = rtems_configuration_get_milliseconds_per_tick();
156
157  mips_timer_rate = rtems_configuration_get_microseconds_per_tick() *
158           bsp_clicks_per_microsecond;
159
160  /*
161  *  Hardware specific initialize goes here
162  */
163
164  /* Set up USC heartbeat timer to generate interrupts */
165  disable_hbi();      /* Disable heartbeat interrupt in USC */
166
167  /* Install interrupt handler */
168  rtems_interrupt_handler_install(
169    CLOCK_VECTOR,
170    "clock",
171    0,
172    USC_isr,
173    NULL
174  );
175
176  init_hbt();        /* Initialize heartbeat timer */
177
178  reset_wdt();      /* Reset watchdog timer */
179
180  enable_wdi();      /* Enable watchdog interrupt in USC */
181
182  enable_hbi();      /* Enable heartbeat interrupt in USC */
183
184              /* Enable USC interrupt in MIPS processor */
185  mips_enable_in_interrupt_mask(CLOCK_VECTOR_MASK);
186
187  /*
188  *  Schedule the clock cleanup routine to execute if the application exits.
189  */
190
191  atexit( Clock_exit );
192}
193
194/*
195 *  Clean up before the application exits
196 */
197
198void Clock_exit( void )
199{
200  /* mips: turn off the timer interrupts */
201  mips_disable_in_interrupt_mask(~CLOCK_VECTOR_MASK);
202}
203
204/*
205 *  Clock_initialize
206 *
207 *  Device driver entry point for clock tick driver initialization.
208 */
209
210rtems_device_driver Clock_initialize(
211  rtems_device_major_number major,
212  rtems_device_minor_number minor,
213  void *pargp
214)
215{
216  Install_clock( Clock_isr );
217
218  return RTEMS_SUCCESSFUL;
219}
220
Note: See TracBrowser for help on using the repository browser.