source: rtems/c/src/lib/libbsp/m68k/gen68340/clock/ckinit.c @ 6693a68

4.104.114.84.95
Last change on this file since 6693a68 was 132f194, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/98 at 22:03:20

Initial submission of gen68340 BSP (should run on a 68349) from
Geoffroy Montel <g_montel@…>.

  • Property mode set to 100644
File size: 4.6 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-1998.
24 * On-Line Applications Research Corporation (OAR).
25 * Copyright assigned to U.S. Government, 1994.
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 <m68340.h>
36
37#define CLOCK_VECTOR    120             /* clock isr routine vector in the vbr */
38#define CLOCK_IRQ_LEVEL 6               /* clock isr level */
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 */
49rtems_device_major_number rtems_clock_major = ~0;
50rtems_device_minor_number rtems_clock_minor;
51
52/*
53 * Periodic interval timer interrupt handler
54 */
55
56/******************************************************
57  Name: Clock_isr
58  Input parameters: irq vector
59  Output parameters: none
60  Description: update # of clock ticks
61 *****************************************************/
62rtems_isr
63Clock_isr (rtems_vector_number vector)
64{
65        /*
66         * Announce the clock tick
67         */
68        Clock_driver_ticks++;
69        rtems_clock_tick();
70}
71
72/******************************************************
73  Name: clock_exit
74  Input parameters: -
75  Output parameters: -
76  Description: turn off periodic time at shutdown
77 *****************************************************/
78void
79Clock_exit (void)
80{
81        if (BSP_Configuration.ticks_per_timeslice ) {
82                /*
83                 * Turn off periodic interval timer
84                 */             
85                SIMPITR = 0;
86        }
87}
88
89/******************************************************
90  Name: Install_clock
91  Input parameters: the Clock Interrupt Subroutine
92  Output parameters: -
93  Description: initialize the periodic interval ticker
94               called by Clock_Initialize
95 *****************************************************/
96static void
97Install_clock (rtems_isr_entry clock_isr)
98{
99        unsigned32 pitr_tmp;
100
101        Clock_driver_ticks = 0;
102        if ( BSP_Configuration.ticks_per_timeslice ) {
103
104                set_vector (clock_isr, CLOCK_VECTOR, 1);
105               
106                /* sets the Periodic Interrupt Control Register PICR */
107                /* voir a quoi correspond exactement le Clock Vector */
108
109                SIMPICR = ( CLOCK_IRQ_LEVEL << 8 ) | ( CLOCK_VECTOR );         
110                                 
111                /* sets the PITR count value */
112                /* this assumes a 32.765 kHz crystal */
113               
114                /* find out whether prescaler should be enabled or not */
115                if ( BSP_Configuration.microseconds_per_tick <= 31128 ) {
116                   pitr_tmp = ( BSP_Configuration.microseconds_per_tick * 8192 ) / 1000000 ;
117                }
118                else {
119                   pitr_tmp = ( BSP_Configuration.microseconds_per_tick / 1000000 ) * 16;
120                   /* enable it */                 
121                   pitr_tmp |= 0x100;             
122                }
123
124                SIMPITR = (unsigned char) pitr_tmp;
125
126                atexit (Clock_exit);
127        }
128}
129
130/******************************************************
131  Name: Clock_initialize
132  Input parameters: major & minor numbers
133  Output parameters: -
134  Description: main entry for clock initialization
135               calls the bsp dependant routine
136 *****************************************************/
137rtems_device_driver
138Clock_initialize(
139        rtems_device_major_number major,
140        rtems_device_minor_number minor,
141        void *pargp
142)
143{
144        Install_clock (Clock_isr);
145 
146        /*
147         * make major/minor avail to others such as shared memory driver
148         */
149        rtems_clock_major = major;
150        rtems_clock_minor = minor;
151 
152        return RTEMS_SUCCESSFUL;
153}
154 
155/******************************************************
156  Name: Clock_control
157  Input parameters: major & minor number
158  Output parameters:
159  Description:
160 *****************************************************/
161rtems_device_driver Clock_control(
162        rtems_device_major_number major,
163        rtems_device_minor_number minor,
164        void *pargp
165)
166{
167        rtems_unsigned32 isrlevel;
168        rtems_libio_ioctl_args_t *args = pargp;
169
170        if (args) {
171                /*
172                 * This is hokey, but until we get a defined interface
173                 * to do this, it will just be this simple...
174                 */
175                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
176                        Clock_isr( CLOCK_VECTOR);
177                }
178                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
179                        rtems_interrupt_disable( isrlevel );
180                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
181                        rtems_interrupt_enable( isrlevel );
182                }
183        }
184        return RTEMS_SUCCESSFUL;
185}
Note: See TracBrowser for help on using the repository browser.