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

4.104.114.84.95
Last change on this file since bdb2899 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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