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

4.104.115
Last change on this file since e7791906 was e7791906, checked in by Joel Sherrill <joel.sherrill@…>, on 09/16/08 at 19:03:42

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

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