source: rtems/c/src/lib/libbsp/m68k/efi68k/clock/ckinit.c @ a858910

4.104.114.84.95
Last change on this file since a858910 was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initializes the DP8570A periodic interrupt on the
4 *  efi68k board. The tick frequency is 1 millisecond.
5 *
6 *  Input parameters:  NONE
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <stdlib.h>
22#include <bsp.h>
23#include <rtems/libio.h>
24
25#define CLOCK_VECTOR  (TCP_ISR_LEVEL+24)
26
27rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
28volatile rtems_unsigned32 Clock_driver_ticks;
29                                    /* ticks since initialization */
30rtems_isr_entry  Old_ticker;
31
32void Clock_exit( void );
33 
34/*
35 * These are set by clock driver during its init
36 */
37 
38rtems_device_major_number rtems_clock_major = ~0;
39rtems_device_minor_number rtems_clock_minor;
40
41
42void per_interrupt(void)
43{
44  Clock_driver_ticks += 1;
45
46  *MSR = PER;
47
48  if ( Clock_isrs == 1 ) {
49    rtems_clock_tick();
50    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
51  }
52  else
53    Clock_isrs -= 1;
54}
55
56rtems_isr Clock_isr(
57  rtems_vector_number vector
58)
59{
60  unsigned char entry_msr, msr;
61
62  entry_msr = *MSR;
63  *MSR = 0;
64  while ( (msr=*MSR) & INT )
65    /* test enabled interrupt bits */
66    if (msr & PER)
67      per_interrupt();
68    else if (msr & T0) {
69      *MSR = T0;                /* reset interrupt */
70      Timer_interrupts++;       /* inc wrap around counter */
71    }
72    else     
73      /* there has been an error if we reach this point */
74      /* default action: reset all the interrupts */
75      *MSR = ( PER | AL | T0 | T1 );
76  *MSR = entry_msr & (RS | PS);
77}
78
79void Install_clock(
80  rtems_isr_entry clock_isr
81)
82{
83  Clock_driver_ticks = 0;
84  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
85
86  if ( BSP_Configuration.ticks_per_timeslice ) {
87    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
88
89    *MSR = RS;                  /* enable 1mS interrupts */
90    *ICR0 |= OME;
91
92    atexit( Clock_exit );
93  }
94}
95
96void Clock_exit( void )
97{
98
99  if ( BSP_Configuration.ticks_per_timeslice ) {
100
101    /* shutdown periodic interrupt */
102    *MSR = RS;
103    *ICR0 &= 0xc0;
104    /* do not restore old vector */
105
106  }
107}
108
109rtems_device_driver Clock_initialize(
110  rtems_device_major_number major,
111  rtems_device_minor_number minor,
112  void *pargp
113)
114{
115  Install_clock( Clock_isr );
116 
117  /*
118   * make major/minor avail to others such as shared memory driver
119   */
120 
121  rtems_clock_major = major;
122  rtems_clock_minor = minor;
123 
124  return RTEMS_SUCCESSFUL;
125}
126 
127rtems_device_driver Clock_control(
128  rtems_device_major_number major,
129  rtems_device_minor_number minor,
130  void *pargp
131)
132{
133    rtems_unsigned32 isrlevel;
134    rtems_libio_ioctl_args_t *args = pargp;
135 
136    if (args == 0)
137        goto done;
138 
139    /*
140     * This is hokey, but until we get a defined interface
141     * to do this, it will just be this simple...
142     */
143 
144    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
145    {
146        Clock_isr(CLOCK_VECTOR);
147    }
148    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
149    {
150      rtems_interrupt_disable( isrlevel );
151       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
152      rtems_interrupt_enable( isrlevel );
153    }
154 
155done:
156    return RTEMS_SUCCESSFUL;
157}
Note: See TracBrowser for help on using the repository browser.