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

4.104.114.84.95
Last change on this file since b1b5a7cb was bdf531ee, checked in by Joel Sherrill <joel.sherrill@…>, on 03/06/96 at 22:25:11

include of mc68360.h changed to m68360.h to reflect filename change.

  • Property mode set to 100644
File size: 3.3 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        Clock_driver_ticks++;
61        rtems_clock_tick();
62}
63
64void
65Clock_exit (void)
66{
67        if (BSP_Configuration.ticks_per_timeslice ) {
68                /*
69                 * Turn off periodic interval timer
70                 */
71                m360.pitr &= ~0xFF;
72        }
73}
74
75static void
76Install_clock (rtems_isr_entry clock_isr)
77{
78        Clock_driver_ticks = 0;
79        if ( BSP_Configuration.ticks_per_timeslice ) {
80                int pitr;
81
82                /*
83                 * Choose periodic interval timer register value
84                 * For a 25 MHz external clock the basic clock rate is
85                 *      40 nsec * 128 * 4 = 20.48 usec/tick
86                 */
87                pitr = ((BSP_Configuration.microseconds_per_tick * 100) + 1023) / 2048;
88                if (pitr >= 256) {
89                        pitr = (pitr + 255) / 512;
90                        if (pitr >= 256)
91                                pitr = 255;
92                        else if (pitr == 0)
93                                pitr = 1;
94                        pitr |= 0x100;
95                }
96                else if (pitr == 0) {
97                        pitr = 1;
98                }
99                m360.pitr &= ~0x1FF;
100                m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;
101                set_vector (clock_isr, CLOCK_VECTOR, 1);
102                m360.pitr |= pitr;
103                atexit (Clock_exit);
104        }
105}
106
107rtems_device_driver
108Clock_initialize(
109        rtems_device_major_number major,
110        rtems_device_minor_number minor,
111        void *pargp
112)
113{
114        Install_clock (Clock_isr);
115 
116        /*
117         * make major/minor avail to others such as shared memory driver
118         */
119        rtems_clock_major = major;
120        rtems_clock_minor = minor;
121 
122        return RTEMS_SUCCESSFUL;
123}
124 
125rtems_device_driver Clock_control(
126        rtems_device_major_number major,
127        rtems_device_minor_number minor,
128        void *pargp
129)
130{
131        rtems_unsigned32 isrlevel;
132        rtems_libio_ioctl_args_t *args = pargp;
133
134        if (args) {
135                /*
136                 * This is hokey, but until we get a defined interface
137                 * to do this, it will just be this simple...
138                 */
139                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
140                        Clock_isr( CLOCK_VECTOR);
141                }
142                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
143                        rtems_interrupt_disable( isrlevel );
144                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
145                        rtems_interrupt_enable( isrlevel );
146                }
147        }
148        return RTEMS_SUCCESSFUL;
149}
Note: See TracBrowser for help on using the repository browser.