source: rtems/c/src/lib/libcpu/mips/clock/ckinit.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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