source: rtems/c/src/lib/libbsp/m68k/gen68340/clock/ckinit.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 17, 1999 at 5:51:34 PM

Updated copyright notice.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * This routine initializes the MC68340/349 Periodic Interval Timer
3 *
4 * Based on the `gen68360' board support package, and covered by the
5 * original distribution terms.
6 *
7 * Geoffroy Montel
8 * France Telecom - CNET/DSM/TAM/CAT
9 * 4, rue du Clos Courtel
10 * 35512 CESSON-SEVIGNE
11 * FRANCE
12 *
13 * e-mail: g_montel@yahoo.com
14 *
15 *  $Id$
16 */
17
18/*
19 * Input parameters:    NONE
20 *
21 * Output parameters:   NONE
22 *
23 * COPYRIGHT (c) 1989-1999.
24 * On-Line Applications Research Corporation (OAR).
25 *
26 * The license and distribution terms for this file may be
27 * found in the file LICENSE in this distribution or at
28 * http://www.OARcorp.com/rtems/license.html.
29 */
30
31#include <stdlib.h>                     /* for atexit() */
32#include <bsp.h>
33#include <rtems/libio.h>
34#include <m68340.h>
35
36#define CLOCK_VECTOR    120             /* clock isr routine vector in the vbr */
37#define CLOCK_IRQ_LEVEL 6               /* clock isr level */
38
39/*
40 * Clock_driver_ticks is a monotonically increasing counter of the
41 * number of clock ticks since the driver was initialized.
42 */
43volatile rtems_unsigned32 Clock_driver_ticks;
44
45/*
46 * These are set by clock driver during its init
47 */
48rtems_device_major_number rtems_clock_major = ~0;
49rtems_device_minor_number rtems_clock_minor;
50
51/*
52 * Periodic interval timer interrupt handler
53 */
54
55/******************************************************
56  Name: Clock_isr
57  Input parameters: irq vector
58  Output parameters: none
59  Description: update # of clock ticks
60 *****************************************************/
61rtems_isr
62Clock_isr (rtems_vector_number vector)
63{
64        /*
65         * Announce the clock tick
66         */
67        Clock_driver_ticks++;
68        rtems_clock_tick();
69}
70
71/******************************************************
72  Name: clock_exit
73  Input parameters: -
74  Output parameters: -
75  Description: turn off periodic time at shutdown
76 *****************************************************/
77void
78Clock_exit (void)
79{
80        if (BSP_Configuration.ticks_per_timeslice ) {
81                /*
82                 * Turn off periodic interval timer
83                 */             
84                SIMPITR = 0;
85        }
86}
87
88/******************************************************
89  Name: Install_clock
90  Input parameters: the Clock Interrupt Subroutine
91  Output parameters: -
92  Description: initialize the periodic interval ticker
93               called by Clock_Initialize
94 *****************************************************/
95static void
96Install_clock (rtems_isr_entry clock_isr)
97{
98        unsigned32 pitr_tmp;
99
100        Clock_driver_ticks = 0;
101        if ( BSP_Configuration.ticks_per_timeslice ) {
102
103                set_vector (clock_isr, CLOCK_VECTOR, 1);
104               
105                /* sets the Periodic Interrupt Control Register PICR */
106                /* voir a quoi correspond exactement le Clock Vector */
107
108                SIMPICR = ( CLOCK_IRQ_LEVEL << 8 ) | ( CLOCK_VECTOR );         
109                                 
110                /* sets the PITR count value */
111                /* this assumes a 32.765 kHz crystal */
112               
113                /* find out whether prescaler should be enabled or not */
114                if ( BSP_Configuration.microseconds_per_tick <= 31128 ) {
115                   pitr_tmp = ( BSP_Configuration.microseconds_per_tick * 8192 ) / 1000000 ;
116                }
117                else {
118                   pitr_tmp = ( BSP_Configuration.microseconds_per_tick / 1000000 ) * 16;
119                   /* enable it */                 
120                   pitr_tmp |= 0x100;             
121                }
122
123                SIMPITR = (unsigned char) pitr_tmp;
124
125                atexit (Clock_exit);
126        }
127}
128
129/******************************************************
130  Name: Clock_initialize
131  Input parameters: major & minor numbers
132  Output parameters: -
133  Description: main entry for clock initialization
134               calls the bsp dependant routine
135 *****************************************************/
136rtems_device_driver
137Clock_initialize(
138        rtems_device_major_number major,
139        rtems_device_minor_number minor,
140        void *pargp
141)
142{
143        Install_clock (Clock_isr);
144 
145        /*
146         * make major/minor avail to others such as shared memory driver
147         */
148        rtems_clock_major = major;
149        rtems_clock_minor = minor;
150 
151        return RTEMS_SUCCESSFUL;
152}
153 
154/******************************************************
155  Name: Clock_control
156  Input parameters: major & minor number
157  Output parameters:
158  Description:
159 *****************************************************/
160rtems_device_driver Clock_control(
161        rtems_device_major_number major,
162        rtems_device_minor_number minor,
163        void *pargp
164)
165{
166        rtems_unsigned32 isrlevel;
167        rtems_libio_ioctl_args_t *args = pargp;
168
169        if (args) {
170                /*
171                 * This is hokey, but until we get a defined interface
172                 * to do this, it will just be this simple...
173                 */
174                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
175                        Clock_isr( CLOCK_VECTOR);
176                }
177                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
178                        rtems_interrupt_disable( isrlevel );
179                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
180                        rtems_interrupt_enable( isrlevel );
181                }
182        }
183        return RTEMS_SUCCESSFUL;
184}
Note: See TracBrowser for help on using the repository browser.