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

4.104.114.84.95
Last change on this file since c629812 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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