OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [gen68340/] [clock/] [ckinit.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: ckinit.c,v 1.2 2001-09-27 12:00:07 chris Exp $
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
 */
43
volatile rtems_unsigned32 Clock_driver_ticks;
44
 
45
/*
46
 * These are set by clock driver during its init
47
 */
48
rtems_device_major_number rtems_clock_major = ~0;
49
rtems_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
 *****************************************************/
61
rtems_isr
62
Clock_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
 *****************************************************/
77
void
78
Clock_exit (void)
79
{
80
        /*
81
         * Turn off periodic interval timer
82
         */
83
        SIMPITR = 0;
84
}
85
 
86
/******************************************************
87
  Name: Install_clock
88
  Input parameters: the Clock Interrupt Subroutine
89
  Output parameters: -
90
  Description: initialize the periodic interval ticker
91
               called by Clock_Initialize
92
 *****************************************************/
93
static void
94
Install_clock (rtems_isr_entry clock_isr)
95
{
96
        unsigned32 pitr_tmp;
97
        unsigned32 usecs_per_tick;
98
 
99
        Clock_driver_ticks = 0;
100
 
101
        set_vector (clock_isr, CLOCK_VECTOR, 1);
102
 
103
        /* sets the Periodic Interrupt Control Register PICR */
104
        /* voir a quoi correspond exactement le Clock Vector */
105
 
106
        SIMPICR = ( CLOCK_IRQ_LEVEL << 8 ) | ( CLOCK_VECTOR );
107
 
108
        /* sets the PITR count value */
109
        /* this assumes a 32.765 kHz crystal */
110
 
111
        usecs_per_tick = BSP_Configuration.microseconds_per_tick;
112
        /* find out whether prescaler should be enabled or not */
113
        if ( usecs_per_tick <= 31128 ) {
114
           pitr_tmp = ( usecs_per_tick * 8192 ) / 1000000 ;
115
        } else {
116
           pitr_tmp = ( usecs_per_tick / 1000000 ) * 16;
117
           /* enable it */
118
           pitr_tmp |= 0x100;
119
        }
120
 
121
        SIMPITR = (unsigned char) pitr_tmp;
122
 
123
        atexit (Clock_exit);
124
}
125
 
126
/******************************************************
127
  Name: Clock_initialize
128
  Input parameters: major & minor numbers
129
  Output parameters: -
130
  Description: main entry for clock initialization
131
               calls the bsp dependant routine
132
 *****************************************************/
133
rtems_device_driver
134
Clock_initialize(
135
        rtems_device_major_number major,
136
        rtems_device_minor_number minor,
137
        void *pargp
138
)
139
{
140
        Install_clock (Clock_isr);
141
 
142
        /*
143
         * make major/minor avail to others such as shared memory driver
144
         */
145
        rtems_clock_major = major;
146
        rtems_clock_minor = minor;
147
 
148
        return RTEMS_SUCCESSFUL;
149
}
150
 
151
/******************************************************
152
  Name: Clock_control
153
  Input parameters: major & minor number
154
  Output parameters:
155
  Description:
156
 *****************************************************/
157
rtems_device_driver Clock_control(
158
        rtems_device_major_number major,
159
        rtems_device_minor_number minor,
160
        void *pargp
161
)
162
{
163
        rtems_unsigned32 isrlevel;
164
        rtems_libio_ioctl_args_t *args = pargp;
165
 
166
        if (args) {
167
                /*
168
                 * This is hokey, but until we get a defined interface
169
                 * to do this, it will just be this simple...
170
                 */
171
                if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
172
                        Clock_isr( CLOCK_VECTOR);
173
                }
174
                else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
175
                        rtems_interrupt_disable( isrlevel );
176
                         (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
177
                        rtems_interrupt_enable( isrlevel );
178
                }
179
        }
180
        return RTEMS_SUCCESSFUL;
181
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.