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

4.104.114.84.95
Last change on this file since d2632274 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 3.6 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-1997.
25 * On-Line Applications Research Corporation (OAR).
26 * Copyright assigned to U.S. Government, 1994.
27 *
28 * The license and distribution terms for this file may be
29 * found in the file LICENSE in this distribution or at
30 * http://www.OARcorp.com/rtems/license.html.
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
54char M360DefaultWatchdogFeeder = 1;
55
56/*
57 * Periodic interval timer interrupt handler
58 */
59
60rtems_isr
61Clock_isr (rtems_vector_number vector)
62{
63        /*
64         * Perform a dummy read of DPRAM.
65         * This works around a bug in Rev. B of the 68360
66         */
67        m360.dpram0[0];
68
69        /*
70         * Feed the watchdog
71         * Application code can override this by
72         * setting M360DefaultWatchdogFeeder to zero.
73         */
74        if (M360DefaultWatchdogFeeder) {
75                m360.swsr = 0x55;
76                m360.swsr = 0xAA;
77        }
78
79        /*
80         * Announce the clock tick
81         */
82        Clock_driver_ticks++;
83        rtems_clock_tick();
84}
85
86void
87Clock_exit (void)
88{
89        if (BSP_Configuration.ticks_per_timeslice ) {
90                /*
91                 * Turn off periodic interval timer
92                 */
93                m360.pitr &= ~0xFF;
94        }
95}
96
97static void
98Install_clock (rtems_isr_entry clock_isr)
99{
100        Clock_driver_ticks = 0;
101        if ( BSP_Configuration.ticks_per_timeslice ) {
102                int pitr;
103
104                /*
105                 * Choose periodic interval timer register value
106                 * For a 25 MHz external clock the basic clock rate is
107                 *      40 nsec * 128 * 4 = 20.48 usec/tick
108                 */
109                pitr = ((BSP_Configuration.microseconds_per_tick * 100) + 1023) / 2048;
110                if (pitr >= 256) {
111                        pitr = (pitr + 255) / 512;
112                        if (pitr >= 256)
113                                pitr = 255;
114                        else if (pitr == 0)
115                                pitr = 1;
116                        pitr |= 0x100;
117                }
118                else if (pitr == 0) {
119                        pitr = 1;
120                }
121                m360.pitr &= ~0x1FF;
122                m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;
123                set_vector (clock_isr, CLOCK_VECTOR, 1);
124                m360.pitr |= pitr;
125                atexit (Clock_exit);
126        }
127}
128
129rtems_device_driver
130Clock_initialize(
131        rtems_device_major_number major,
132        rtems_device_minor_number minor,
133        void *pargp
134)
135{
136        Install_clock (Clock_isr);
137 
138        /*
139         * make major/minor avail to others such as shared memory driver
140         */
141        rtems_clock_major = major;
142        rtems_clock_minor = minor;
143 
144        return RTEMS_SUCCESSFUL;
145}
146 
147rtems_device_driver Clock_control(
148        rtems_device_major_number major,
149        rtems_device_minor_number minor,
150        void *pargp
151)
152{
153        rtems_unsigned32 isrlevel;
154        rtems_libio_ioctl_args_t *args = pargp;
155
156        if (args) {
157                /*
158                 * This is hokey, but until we get a defined interface
159                 * to do this, it will just be this simple...
160                 */
161                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
162                        Clock_isr( CLOCK_VECTOR);
163                }
164                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
165                        rtems_interrupt_disable( isrlevel );
166                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
167                        rtems_interrupt_enable( isrlevel );
168                }
169        }
170        return RTEMS_SUCCESSFUL;
171}
Note: See TracBrowser for help on using the repository browser.