source: rtems/c/src/lib/libbsp/m68k/mvme167/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: 7.3 KB
Line 
1/*  ckinit.c
2 *
3 *  Implementation of the 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.org/license/LICENSE.
22 *
23 *  Modifications of respective RTEMS files:
24 *  Copyright (c) 1998, National Research Council of Canada
25 */
26
27#include <stdlib.h>
28#include <bsp.h>
29
30#define MS_COUNT          1000              /* T2's countdown constant (1 ms) */
31#define CLOCK_INT_LEVEL   6                 /* T2's interrupt level */
32#define CLOCK_VECTOR (VBR0 * 0x10 + 0x9)    /* T2 is vector $X9 (p. 2-71)*/
33
34/*
35 *  These are declared in rtems/c/src/lib/include/clockdrv.h
36 *  In other BSPs, rtems_clock_major is set to the largest possible value
37 *  (which is almost certainly greater than the number of I/O devices) to
38 *  indicate that this device has not been initialized yet. The actual
39 *  device number is supplied during initialization. We do not do that.
40 *
41 *  Initialized data ends up the the .data section. This causes two problems:
42 *  1) the .data section is no longer ROMable because we need to write into
43 *  it. 2) The initial value is correct only after a download. On subsequent
44 *  program restarts, the value is not re-initialized but left to whatever it
45 *  was when the previous run terminated or aborted. If we depend on some
46 *  global variable value, we must initialize that value explicitly in code
47 *  at boot time.
48 */
49rtems_device_major_number rtems_clock_major;
50rtems_device_minor_number rtems_clock_minor;
51
52/*
53 *  Clock_driver_ticks is a monotonically increasing counter of the number of
54 *  VMEchip2 timer #2 ticks since the driver was initialized.
55 */
56volatile uint32_t         Clock_driver_ticks;
57
58/*
59 *  Clock_isrs is the number of clock ISRs until the next invocation of the
60 *  RTEMS clock tick routine. This clock tick device driver gets an interrupt
61 *  once a millisecond and counts down until the length of time between the
62 *  user configured microseconds per tick has passed. This allows the clock
63 *  device to "tick" faster than the kernel clock. Of course, the kernel clock
64 *  cannot tick faster than the hardware clock. Therefore, the kernel clock
65 *  ticks cannot occur more frequently than every 1 millisecond.
66 */
67uint32_t         Clock_isrs;
68
69/*
70 *  Records the previous clock ISR (should be NULL)
71 */
72rtems_isr_entry  Old_ticker;
73
74/*
75 *  Called when the kernel exits.
76 */
77void clock_exit( void );
78
79/*
80 *  VMEchip2_T2_isr
81 *
82 *  C ISR Handler. Increment the number of internal ticks. If it is time for a
83 *  kernel clock tick (if Clock_isrs == 1), call rtems_clock_tick() to signal
84 *  the event and reset the Clock_isrs counter; else, just decrement it.
85 *
86 *  Input parameters:
87 *    vector number
88 *
89 *  Output parameters: NONE
90 *
91 *  Return values: NONE
92 */
93rtems_isr VMEchip2_T2_isr(
94  rtems_vector_number vector
95)
96{
97  char overflow;                /* Content of overflow counter */
98  long i;
99  long ct;                      /* Number of T2 ticks per RTEMS ticks */
100
101  ct = rtems_configuration_get_microseconds_per_tick() / 1000;
102
103  /*
104   *  May have missed interrupts, so should look at the overflow counter.
105   */
106  lcsr->intr_clear |= 0x02000000;   /* Clear the interrupt */
107  overflow = (lcsr->board_ctl >> 12) & 0xF;
108  lcsr->board_ctl |= 0x400;         /* Reset overflow counter */
109
110  /* Attempt to protect against one more period */
111  if ( overflow == 0 )
112    overflow = 16;
113
114  Clock_driver_ticks += overflow;   /* One or more internal ticks */
115
116  if ( Clock_isrs <= overflow ) {
117    /* If its time for kernel clock ticks, signal the events to RTEMS */
118    for( i = overflow - Clock_isrs; i >= 0; i -= ct ) {
119      rtems_clock_tick();
120    }
121    /* Reset the counter */
122    Clock_isrs = (uint32_t)-i;
123  }
124  else
125    Clock_isrs -= overflow;
126}
127
128/*
129 *  VMEchip2_T2_initialize
130 *
131 *  Initialize the VMEchip2 Tick Timer #2.
132 *
133 *  THE VMECHIP2 PRESCALER REGISTER IS ASSUMED TO BE SET!
134 *  The prescaler is used by all VMEchip2 timers, including the VMEbus grant
135 *  timeout counter, the DMAC time off timer, the DMAC timer on timer, and the
136 *  VMEbus global timeout timer. The prescaler value is normally set by the
137 *  boot ROM to provide a 1 MHz clock to the timers. For a 25 MHz MVME167, the
138 *  prescaler value should be 0xE7 (page 2-63).
139 *
140 *  Input parameters: NONE
141 *
142 *  Output paremeters: NONE
143 *
144 *  Return values: NONE
145 */
146void VMEchip2_T2_initialize( void )
147{
148  Clock_driver_ticks = 0;
149  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
150
151  lcsr->intr_ena &= 0xFDFFFFFF;   /* Disable tick timer 2 interrupt */
152  lcsr->intr_clear = 0x02000000;  /* Clear tick timer 2 interrupt */
153  lcsr->intr_level[0] =           /* Set tick timer 2 interrupt level */
154      (lcsr->intr_level[0] & 0xFFFFFF0F ) | (CLOCK_INT_LEVEL << 4);
155  lcsr->timer_cmp_2 = MS_COUNT;   /* Period in compare register */
156  lcsr->timer_cnt_2 = 0;          /* Clear tick timer 2 counter */
157  Old_ticker =                    /* Install C ISR */
158      (rtems_isr_entry) set_vector( VMEchip2_T2_isr, CLOCK_VECTOR, 1 );
159  lcsr->board_ctl |= 0x700;       /* Start tick timer 2, reset-on-compare, */
160                                  /*  and clear tick timer 2 overflow counter */
161  lcsr->intr_ena |= 0x02000000;   /* Enable tick timer 2 interrupt */
162  lcsr->vector_base |= 0x00800000;/* Unmask VMEchip2 interrupts */
163  atexit( clock_exit );           /* Turn off T2 interrupts when we exit */
164}
165
166/*
167 *  clock_exit
168 *
169 *  This routine stops the VMEchip2 T2 timer, disables its interrupt, and
170 *  re-install the old interrupt vectors.
171 *
172 *  Input parameters:   NONE
173 *
174 *  Output parameters:  NONE
175 *
176 *  Return values:      NONE
177 *
178 */
179void clock_exit( void )
180{
181  lcsr->board_ctl &= 0xFFFFFEFF;  /* Stop tick timer 2 */
182  lcsr->intr_ena &= 0xFDFFFFFF;   /* Disable tick timer 2 interrupt */
183  lcsr->intr_clear = 0x02000000;  /* Clear tick timer 2 interrupt */
184
185  set_vector( Old_ticker, CLOCK_VECTOR, 1 );
186}
187
188/*
189 *  Clock_initialize()
190 *  prototyped in rtems/c/src/lib/include/clockdrv.h.
191 *
192 *  Input parameters:
193 *     major - console device major number
194 *     minor - console device minor number
195 *             ALWAYS 0 IN VERSION 3.6.0 OF RTEMS!
196 *             Probably provided for symmetry with the other I/O calls.
197 *     arg   - pointer to optional device driver arguments
198 *             ALWAYS NULL IN VERSION 3.6.0 OF RTEMS!
199 *
200 *  Output paremeters: NONE
201 *
202 *  Return values:
203 *     rtems_device_driver status code
204 */
205rtems_device_driver Clock_initialize(
206  rtems_device_major_number major,
207  rtems_device_minor_number minor,
208  void *pargp
209)
210{
211  VMEchip2_T2_initialize();
212
213  /*
214   *  Make major/minor avail to others such as shared memory driver
215   */
216  rtems_clock_major = major;
217  rtems_clock_minor = minor;
218
219  return RTEMS_SUCCESSFUL;
220}
Note: See TracBrowser for help on using the repository browser.