source: rtems/c/src/lib/libbsp/m68k/gen68360/clock/ckinit.c @ f9f375e

4.104.114.84.95
Last change on this file since f9f375e was f8f370b6, checked in by Joel Sherrill <joel.sherrill@…>, on 04/16/97 at 17:45:35

Update from Eric Norum.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * This routine initializes the MC68360 Periodic Interval Timer
3 *
4 * The PIT has rather poor resolution, but it is easy to set up
5 * and requires no housekeeping once it is going.
6 *
7 * Based on the `gen68302' board support package, and covered by the
8 * original distribution terms.
9 *
10 * W. Eric Norum
11 * Saskatchewan Accelerator Laboratory
12 * University of Saskatchewan
13 * Saskatoon, Saskatchewan, CANADA
14 * eric@skatter.usask.ca
15 *
16 *  $Id$
17 */
18
19/*
20 * Input parameters:    NONE
21 *
22 * Output parameters:   NONE
23 *
24 * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
25 * On-Line Applications Research Corporation (OAR).
26 * All rights assigned to U.S. Government, 1994.
27 *
28 * This material may be reproduced by or for the U.S. Government pursuant
29 * to the copyright license under the clause at DFARS 252.227-7013.  This
30 * notice must appear in all copies of this file and its derivatives.
31 */
32
33#include <stdlib.h>                     /* for atexit() */
34#include <bsp.h>
35#include <rtems/libio.h>
36#include "m68360.h"
37
38#define CLOCK_VECTOR    120
39#define CLOCK_IRQ_LEVEL 6
40
41/*
42 * Clock_driver_ticks is a monotonically increasing counter of the
43 * number of clock ticks since the driver was initialized.
44 */
45volatile rtems_unsigned32 Clock_driver_ticks;
46
47/*
48 * These are set by clock driver during its init
49 */
50 
51rtems_device_major_number rtems_clock_major = ~0;
52rtems_device_minor_number rtems_clock_minor;
53
54/*
55 * Periodic interval timer interrupt handler
56 */
57rtems_isr
58Clock_isr (rtems_vector_number vector)
59{
60        /*
61         * Perform a dummy read of DPRAM.
62         * This works around a bug in Rev. B of the 68360
63         */
64        m360.dpram0[0];
65
66        /*
67         * Announce the clock tick
68         */
69        Clock_driver_ticks++;
70        rtems_clock_tick();
71}
72
73void
74Clock_exit (void)
75{
76        if (BSP_Configuration.ticks_per_timeslice ) {
77                /*
78                 * Turn off periodic interval timer
79                 */
80                m360.pitr &= ~0xFF;
81        }
82}
83
84static void
85Install_clock (rtems_isr_entry clock_isr)
86{
87        Clock_driver_ticks = 0;
88        if ( BSP_Configuration.ticks_per_timeslice ) {
89                int pitr;
90
91                /*
92                 * Choose periodic interval timer register value
93                 * For a 25 MHz external clock the basic clock rate is
94                 *      40 nsec * 128 * 4 = 20.48 usec/tick
95                 */
96                pitr = ((BSP_Configuration.microseconds_per_tick * 100) + 1023) / 2048;
97                if (pitr >= 256) {
98                        pitr = (pitr + 255) / 512;
99                        if (pitr >= 256)
100                                pitr = 255;
101                        else if (pitr == 0)
102                                pitr = 1;
103                        pitr |= 0x100;
104                }
105                else if (pitr == 0) {
106                        pitr = 1;
107                }
108                m360.pitr &= ~0x1FF;
109                m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;
110                set_vector (clock_isr, CLOCK_VECTOR, 1);
111                m360.pitr |= pitr;
112                atexit (Clock_exit);
113        }
114}
115
116rtems_device_driver
117Clock_initialize(
118        rtems_device_major_number major,
119        rtems_device_minor_number minor,
120        void *pargp
121)
122{
123        Install_clock (Clock_isr);
124 
125        /*
126         * make major/minor avail to others such as shared memory driver
127         */
128        rtems_clock_major = major;
129        rtems_clock_minor = minor;
130 
131        return RTEMS_SUCCESSFUL;
132}
133 
134rtems_device_driver Clock_control(
135        rtems_device_major_number major,
136        rtems_device_minor_number minor,
137        void *pargp
138)
139{
140        rtems_unsigned32 isrlevel;
141        rtems_libio_ioctl_args_t *args = pargp;
142
143        if (args) {
144                /*
145                 * This is hokey, but until we get a defined interface
146                 * to do this, it will just be this simple...
147                 */
148                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
149                        Clock_isr( CLOCK_VECTOR);
150                }
151                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
152                        rtems_interrupt_disable( isrlevel );
153                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
154                        rtems_interrupt_enable( isrlevel );
155                }
156        }
157        return RTEMS_SUCCESSFUL;
158}
Note: See TracBrowser for help on using the repository browser.