source: rtems/c/src/lib/libbsp/m68k/mvme147/clock/ckinit.c @ 98e4ebf5

4.104.114.84.95
Last change on this file since 98e4ebf5 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initializes the Tick Timer 2 on the MVME147 board.
4 *  The tick frequency is 1 millisecond.
5 *
6 *  Input parameters:  NONE
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  MVME147 port for TNI - Telecom Bretagne
19 *  by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr)
20 *  May 1996
21 *
22 *  $Id$
23 */
24
25#include <stdlib.h>
26
27#include <bsp.h>
28#include <rtems/libio.h>
29
30#define MS_COUNT          65376    /* 1ms */
31/* MS_COUNT = 0x10000 - 1e-3/6.25e-6 */
32#define CLOCK_INT_LEVEL   6               /* T2's interrupt level */
33
34rtems_unsigned32 Clock_isrs;                  /* ISRs until next tick */
35volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */
36rtems_isr_entry  Old_ticker;
37
38void Clock_exit( void );
39 
40/*
41 * These are set by clock driver during its init
42 */
43 
44rtems_device_major_number rtems_clock_major = ~0;
45rtems_device_minor_number rtems_clock_minor;
46 
47
48/*
49 *  ISR Handler
50 */
51
52rtems_isr Clock_isr(rtems_vector_number vector)
53{
54  Clock_driver_ticks += 1;
55  pcc->timer2_int_control |= 0x80; /* Acknowledge interr. */
56
57  if (Clock_isrs == 1) {
58    rtems_clock_tick();
59    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
60  }
61  else
62    Clock_isrs -= 1;
63}
64
65void Install_clock(rtems_isr_entry clock_isr )
66{
67
68  Clock_driver_ticks = 0;
69  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
70
71  if ( BSP_Configuration.ticks_per_timeslice ) {
72    Old_ticker =
73      (rtems_isr_entry) set_vector( clock_isr, TIMER_2_VECTOR, 1 );
74
75    pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */
76    pcc->timer2_preload = MS_COUNT;
77    /* write preload value */
78    pcc->timer2_control = 0x07; /* clear T2 overflow counter, enable counter */
79    pcc->timer2_int_control = CLOCK_INT_LEVEL|0x08;
80    /* Enable Timer 2 and set its int. level */
81   
82    atexit( Clock_exit );
83  }
84}
85
86void Clock_exit( void )
87{
88  if ( BSP_Configuration.ticks_per_timeslice ) {
89    pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */
90  }
91}
92
93rtems_device_driver Clock_initialize(
94  rtems_device_major_number major,
95  rtems_device_minor_number minor,
96  void *pargp
97)
98{
99  Install_clock( Clock_isr );
100 
101  /*
102   * make major/minor avail to others such as shared memory driver
103   */
104 
105  rtems_clock_major = major;
106  rtems_clock_minor = minor;
107 
108  return RTEMS_SUCCESSFUL;
109}
110 
111rtems_device_driver Clock_control(
112  rtems_device_major_number major,
113  rtems_device_minor_number minor,
114  void *pargp
115)
116{
117    rtems_unsigned32 isrlevel;
118    rtems_libio_ioctl_args_t *args = pargp;
119 
120    if (args == 0)
121        goto done;
122 
123    /*
124     * This is hokey, but until we get a defined interface
125     * to do this, it will just be this simple...
126     */
127 
128    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
129    {
130        Clock_isr(TIMER_2_VECTOR);
131    }
132    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
133    {
134      rtems_interrupt_disable( isrlevel );
135       (void) set_vector( args->buffer, TIMER_2_VECTOR, 1 );
136      rtems_interrupt_enable( isrlevel );
137    }
138 
139done:
140    return RTEMS_SUCCESSFUL;
141}
142
Note: See TracBrowser for help on using the repository browser.