source: rtems/c/src/lib/libbsp/m68k/mvme167/clock/ckinit.c @ 12bd47e

4.104.114.95
Last change on this file since 12bd47e was 12bd47e, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:49:53

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 8.4 KB
Line 
1/*  ckinit.c
2 *
3 *  Implementation of the Clock_control() and Clock_initialize() functions
4 *  prototyped in rtems/c/src/lib/include/clockdrv.h.
5 *
6 *  This port does not allow the application to select which timer on the
7 *  MVME167 to use for the clock, nor does it allow the application to
8 *  configure the clock. The clock uses the VMEchip2 Tick Timer #2. This
9 *  timer is set up to raise a MC680x0 level-6 interrupt every 1 ms. The
10 *  interrupt vector is 0x69.
11 *
12 *  All page references are to the MVME166/MVME167/MVME187 Single Board
13 *  Computer Programmer's Reference Guide (MVME187PG/D2) with the April
14 *  1993 supplements/addenda (MVME187PG/D2A1).
15 *
16 *  COPYRIGHT (c) 1989-1999.
17 *  On-Line Applications Research Corporation (OAR).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.com/license/LICENSE.
22 *
23 *  Modifications of respective RTEMS files:
24 *  Copyright (c) 1998, National Research Council of Canada
25 *
26 *  $Id$
27 */
28
29#include <stdlib.h>
30#include <bsp.h>
31#include <rtems/libio.h>
32
33#define MS_COUNT          1000              /* T2's countdown constant (1 ms) */
34#define CLOCK_INT_LEVEL   6                 /* T2's interrupt level */
35#define CLOCK_VECTOR (VBR0 * 0x10 + 0x9)    /* T2 is vector $X9 (p. 2-71)*/
36
37/*
38 *  These are declared in rtems/c/src/lib/include/clockdrv.h
39 *  In other BSPs, rtems_clock_major is set to the largest possible value
40 *  (which is almost certainly greater than the number of I/O devices) to
41 *  indicate that this device has not been initialized yet. The actual
42 *  device number is supplied during initialization. We do not do that.
43 *
44 *  Initialized data ends up the the .data section. This causes two problems:
45 *  1) the .data section is no longer ROMable because we need to write into
46 *  it. 2) The initial value is correct only after a download. On subsequent
47 *  program restarts, the value is not re-initialized but left to whatever it
48 *  was when the previous run terminated or aborted. If we depend on some
49 *  global variable value, we must initialize that value explicitly in code
50 *  at boot time.
51 */
52rtems_device_major_number rtems_clock_major;
53rtems_device_minor_number rtems_clock_minor;
54
55/*
56 *  Clock_driver_ticks is a monotonically increasing counter of the number of
57 *  VMEchip2 timer #2 ticks since the driver was initialized.
58 */
59volatile uint32_t         Clock_driver_ticks;
60
61/*
62 *  Clock_isrs is the number of clock ISRs until the next invocation of the
63 *  RTEMS clock tick routine. This clock tick device driver gets an interrupt
64 *  once a millisecond and counts down until the length of time between the
65 *  user configured microseconds per tick has passed. This allows the clock
66 *  device to "tick" faster than the kernel clock. Of course, the kernel clock
67 *  cannot tick faster than the hardware clock. Therefore, the kernel clock
68 *  ticks cannot occur more frequently than every 1 millisecond.
69 */
70uint32_t         Clock_isrs;
71
72/*
73 *  Records the previous clock ISR (should be NULL)
74 */
75rtems_isr_entry  Old_ticker;
76
77/*
78 *  Called when the kernel exits.
79 */
80void clock_exit( void );
81
82/*
83 *  VMEchip2_T2_isr
84 *
85 *  C ISR Handler. Increment the number of internal ticks. If it is time for a
86 *  kernel clock tick (if Clock_isrs == 1), call rtems_clock_tick() to signal
87 *  the event and reset the Clock_isrs counter; else, just decrement it.
88 *
89 *  Input parameters:
90 *    vector number
91 *
92 *  Output parameters: NONE
93 *
94 *  Return values: NONE
95 */
96rtems_isr VMEchip2_T2_isr(
97  rtems_vector_number vector
98)
99{
100  char overflow;                /* Content of overflow counter */
101  long i;
102  long ct;                      /* Number of T2 ticks per RTEMS ticks */
103
104  ct = rtems_configuration_get_microseconds_per_tick() / 1000;
105
106  /*
107   *  May have missed interrupts, so should look at the overflow counter.
108   */
109  lcsr->intr_clear |= 0x02000000;   /* Clear the interrupt */
110  overflow = (lcsr->board_ctl >> 12) & 0xF;
111  lcsr->board_ctl |= 0x400;         /* Reset overflow counter */
112
113  /* Attempt to protect against one more period */
114  if ( overflow == 0 )
115    overflow = 16;
116
117  Clock_driver_ticks += overflow;   /* One or more internal ticks */
118
119  if ( Clock_isrs <= overflow ) {
120    /* If its time for kernel clock ticks, signal the events to RTEMS */
121    for( i = overflow - Clock_isrs; i >= 0; i -= ct ) {
122      rtems_clock_tick();
123    }
124    /* Reset the counter */
125    Clock_isrs = (uint32_t)-i;
126  }
127  else
128    Clock_isrs -= overflow;
129}
130
131/*
132 *  VMEchip2_T2_initialize
133 *
134 *  Initialize the VMEchip2 Tick Timer #2.
135 *
136 *  THE VMECHIP2 PRESCALER REGISTER IS ASSUMED TO BE SET!
137 *  The prescaler is used by all VMEchip2 timers, including the VMEbus grant
138 *  timeout counter, the DMAC time off timer, the DMAC timer on timer, and the
139 *  VMEbus global timeout timer. The prescaler value is normally set by the
140 *  boot ROM to provide a 1 MHz clock to the timers. For a 25 MHz MVME167, the
141 *  prescaler value should be 0xE7 (page 2-63).
142 *
143 *  Input parameters: NONE
144 *
145 *  Output paremeters: NONE
146 *
147 *  Return values: NONE
148 */
149void VMEchip2_T2_initialize( void )
150{
151  Clock_driver_ticks = 0;
152  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
153
154  lcsr->intr_ena &= 0xFDFFFFFF;   /* Disable tick timer 2 interrupt */
155  lcsr->intr_clear = 0x02000000;  /* Clear tick timer 2 interrupt */
156  lcsr->intr_level[0] =           /* Set tick timer 2 interrupt level */
157      (lcsr->intr_level[0] & 0xFFFFFF0F ) | (CLOCK_INT_LEVEL << 4);
158  lcsr->timer_cmp_2 = MS_COUNT;   /* Period in compare register */
159  lcsr->timer_cnt_2 = 0;          /* Clear tick timer 2 counter */
160  Old_ticker =                    /* Install C ISR */
161      (rtems_isr_entry) set_vector( VMEchip2_T2_isr, CLOCK_VECTOR, 1 );
162  lcsr->board_ctl |= 0x700;       /* Start tick timer 2, reset-on-compare, */
163                                  /*  and clear tick timer 2 overflow counter */
164  lcsr->intr_ena |= 0x02000000;   /* Enable tick timer 2 interrupt */
165  lcsr->vector_base |= 0x00800000;/* Unmask VMEchip2 interrupts */
166  atexit( clock_exit );           /* Turn off T2 interrupts when we exit */
167}
168
169/*
170 *  clock_exit
171 *
172 *  This routine stops the VMEchip2 T2 timer, disables its interrupt, and
173 *  re-install the old interrupt vectors.
174 *
175 *  Input parameters:   NONE
176 *
177 *  Output parameters:  NONE
178 *
179 *  Return values:      NONE
180 *
181 */
182void clock_exit( void )
183{
184  lcsr->board_ctl &= 0xFFFFFEFF;  /* Stop tick timer 2 */
185  lcsr->intr_ena &= 0xFDFFFFFF;   /* Disable tick timer 2 interrupt */
186  lcsr->intr_clear = 0x02000000;  /* Clear tick timer 2 interrupt */
187
188  set_vector( Old_ticker, CLOCK_VECTOR, 1 );
189}
190
191/*
192 *  Clock_initialize()
193 *  prototyped in rtems/c/src/lib/include/clockdrv.h.
194 *
195 *  Input parameters:
196 *     major - console device major number
197 *     minor - console device minor number
198 *             ALWAYS 0 IN VERSION 3.6.0 OF RTEMS!
199 *             Probably provided for symmetry with the other I/O calls.
200 *     arg   - pointer to optional device driver arguments
201 *             ALWAYS NULL IN VERSION 3.6.0 OF RTEMS!
202 *
203 *  Output paremeters: NONE
204 *
205 *  Return values:
206 *     rtems_device_driver status code
207 */
208rtems_device_driver Clock_initialize(
209  rtems_device_major_number major,
210  rtems_device_minor_number minor,
211  void *pargp
212)
213{
214  VMEchip2_T2_initialize();
215
216  /*
217   *  Make major/minor avail to others such as shared memory driver
218   */
219  rtems_clock_major = major;
220  rtems_clock_minor = minor;
221
222  return RTEMS_SUCCESSFUL;
223}
224
225/*
226 *  Clock_control().
227 *  Prototyped in rtems/c/src/lib/include/clockdrv.h
228 *
229 *  Input parameters:
230 *    major - clock device major number
231 *    minor - clock device minor number
232 *    parg  - pointer to optional device driver arguments
233 *
234 *  Output parameters:  NONE
235 *
236 *  Return values:
237 *    rtems_device_driver status code
238 */
239rtems_device_driver Clock_control(
240  rtems_device_major_number major,
241  rtems_device_minor_number minor,
242  void *pargp)
243{
244    uint32_t         isrlevel;
245    rtems_libio_ioctl_args_t *args = pargp;
246
247    if ( args == 0 )
248        goto done;
249
250    /*
251     * This is hokey, but until we get a defined interface
252     * to do this, it will just be this simple...
253     */
254    if ( args->command == rtems_build_name('I', 'S', 'R', ' ') )
255    {
256      VMEchip2_T2_isr( CLOCK_VECTOR );
257    }
258    else if ( args->command == rtems_build_name('N', 'E', 'W', ' ') )
259    {
260      rtems_interrupt_disable( isrlevel );
261      set_vector( args->buffer, CLOCK_VECTOR, 1 );
262      rtems_interrupt_enable( isrlevel );
263    }
264
265done:
266    return RTEMS_SUCCESSFUL;
267}
Note: See TracBrowser for help on using the repository browser.