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

4.104.114.95
Last change on this file since 34ef6c7 was 34ef6c7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 22:06:51

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c: The Shared Memory Driver no longer requires the special IOCTL in Clock_control. This was a hack which has existed since before the Classic API Timer Manager was implemented. All implementations of and references to Clock_control were removed.
  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[f198c63]1
2/*  ckinit.c
3 *
4 *  This file contains the clock driver initialization for the IDT 4650.
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 *
[08311cc3]23 *  COPYRIGHT (c) 1989-1999.
[f198c63]24 *  On-Line Applications Research Corporation (OAR).
25 *
[98e4ebf5]26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
[ae8d185]28 *  http://www.rtems.com/license/LICENSE.
[f198c63]29 *
[0971cd5]30 *  $Id$
[f198c63]31 */
32
[82478528]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
[f198c63]40
41#include <stdlib.h>
42
43#include <rtems.h>
44#include <rtems/libio.h>
45
[b944007b]46#define EXT_INT5    0x8000  /* external interrupt 5 */
[f198c63]47
48#include "clock.h"
49
[b72f5799]50extern uint32_t bsp_clicks_per_microsecond;
[f817b02]51
52/* to avoid including the bsp */
53mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int );
[f198c63]54
55void Clock_exit( void );
56rtems_isr Clock_isr( rtems_vector_number vector );
57
58
59/*
60 *  The interrupt vector number associated with the clock tick device
61 *  driver.
62 */
63
64#define CLOCK_VECTOR_MASK    EXT_INT5
65#define CLOCK_VECTOR         0x7
66
67/*
68 *  Clock_driver_ticks is a monotonically increasing counter of the
69 *  number of clock ticks since the driver was initialized.
70 */
71
[35f97010]72volatile uint32_t   Clock_driver_ticks;
[f198c63]73
74/*
75 *  Clock_isrs is the number of clock ISRs until the next invocation of
76 *  the RTEMS clock tick routine.  The clock tick device driver
77 *  gets an interrupt once a millisecond and counts down until the
78 *  length of time between the user configured microseconds per tick
79 *  has passed.
80 */
81
[35f97010]82uint32_t   Clock_isrs;              /* ISRs until next tick */
[f198c63]83
84/*
85 * These are set by clock driver during its init
86 */
87 
88rtems_device_major_number rtems_clock_major = ~0;
89rtems_device_minor_number rtems_clock_minor;
90
91/*
92 *  The previous ISR on this clock tick interrupt vector.
93 */
94
95rtems_isr_entry  Old_ticker;
96
97void Clock_exit( void );
98
[35f97010]99static uint32_t   mips_timer_rate = 0;
[f198c63]100
101/*
102 *  Isr Handler
103 */
104
105rtems_isr Clock_isr(
106  rtems_vector_number vector
107)
108{
109/*
110 * bump the number of clock driver ticks since initialization
111 *
112 * determine if it is time to announce the passing of tick as configured
113 * to RTEMS through the rtems_clock_tick directive
114 *
115 * perform any timer dependent tasks
116 */
117
118  /* refresh the internal CPU timer */
119  mips_set_timer( mips_timer_rate );
120
121  Clock_driver_ticks += 1;
122
123  rtems_clock_tick();
124}
125
126/* User callback shell (set from Clock_Control) */
127static void (*user_callback)(void);
128
129rtems_isr User_Clock_isr(
130  rtems_vector_number vector
131)
132{
133   /* refresh the internal CPU timer */
134   mips_set_timer( mips_timer_rate );
135
136   if (user_callback)
137      user_callback();
138}
139
140/*
141 *  Install_clock
142 *
143 *  Install a clock tick handleR and reprograms the chip.  This
144 *  is used to initially establish the clock tick.
145 */
146
147void Install_clock(
148  rtems_isr_entry clock_isr
149)
150{
151  /*
152   *  Initialize the clock tick device driver variables
153   */
154
155  Clock_driver_ticks = 0;
[f817b02]156  Clock_isrs = rtems_configuration_get_milliseconds_per_tick();
[f198c63]157
[0dd1d44]158  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
[f198c63]159  /*
[0dd1d44]160   *  Hardware specific initialize goes here
[f198c63]161   */
162
[b72f5799]163  mips_timer_rate = rtems_configuration_get_microseconds_per_tick() *
164     bsp_clicks_per_microsecond;
[0dd1d44]165  mips_set_timer( mips_timer_rate );
[b4d0d18e]166  mips_enable_in_interrupt_mask(CLOCK_VECTOR_MASK);
[f198c63]167
168  /*
169   *  Schedule the clock cleanup routine to execute if the application exits.
170   */
171
172  atexit( Clock_exit );
173}
174
175/*
176 *  Clean up before the application exits
177 */
178
179void Clock_exit( void )
180{
[0dd1d44]181  /* mips: turn off the timer interrupts */
[b4d0d18e]182  mips_disable_in_interrupt_mask(CLOCK_VECTOR_MASK);
[f198c63]183}
184
185/*
186 *  Clock_initialize
187 *
188 *  Device driver entry point for clock tick driver initialization.
189 */
190
191rtems_device_driver Clock_initialize(
192  rtems_device_major_number major,
193  rtems_device_minor_number minor,
194  void *pargp
195)
196{
197  Install_clock( Clock_isr );
198 
199  /*
200   * make major/minor avail to others such as shared memory driver
201   */
202 
203  rtems_clock_major = major;
204  rtems_clock_minor = minor;
205 
206  return RTEMS_SUCCESSFUL;
207}
Note: See TracBrowser for help on using the repository browser.