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

4.104.114.95
Last change on this file since 12bd47e was 12bd47e, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:49:53

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 3.1 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.rtems.com/license/LICENSE.
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
33uint32_t         Clock_isrs;                  /* ISRs until next tick */
34volatile uint32_t         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 *  ISR Handler
48 */
49
50rtems_isr Clock_isr(rtems_vector_number vector)
51{
52  Clock_driver_ticks += 1;
53  pcc->timer2_int_control |= 0x80; /* Acknowledge interr. */
54
55  if (Clock_isrs == 1) {
56    rtems_clock_tick();
57    Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
58  }
59  else
60    Clock_isrs -= 1;
61}
62
63void Install_clock(rtems_isr_entry clock_isr )
64{
65
66  Clock_driver_ticks = 0;
67  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
68
69  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_2_VECTOR, 1 );
70
71  pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */
72  pcc->timer2_preload = MS_COUNT;
73  /* write preload value */
74  pcc->timer2_control = 0x07; /* clear T2 overflow counter, enable counter */
75  pcc->timer2_int_control = CLOCK_INT_LEVEL|0x08;
76  /* Enable Timer 2 and set its int. level */
77
78  atexit( Clock_exit );
79}
80
81void Clock_exit( void )
82{
83  pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */
84}
85
86rtems_device_driver Clock_initialize(
87  rtems_device_major_number major,
88  rtems_device_minor_number minor,
89  void *pargp
90)
91{
92  Install_clock( Clock_isr );
93
94  /*
95   * make major/minor avail to others such as shared memory driver
96   */
97
98  rtems_clock_major = major;
99  rtems_clock_minor = minor;
100
101  return RTEMS_SUCCESSFUL;
102}
103
104rtems_device_driver Clock_control(
105  rtems_device_major_number major,
106  rtems_device_minor_number minor,
107  void *pargp
108)
109{
110    uint32_t         isrlevel;
111    rtems_libio_ioctl_args_t *args = pargp;
112
113    if (args == 0)
114        goto done;
115
116    /*
117     * This is hokey, but until we get a defined interface
118     * to do this, it will just be this simple...
119     */
120
121    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
122    {
123        Clock_isr(TIMER_2_VECTOR);
124    }
125    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
126    {
127      rtems_interrupt_disable( isrlevel );
128       (void) set_vector( args->buffer, TIMER_2_VECTOR, 1 );
129      rtems_interrupt_enable( isrlevel );
130    }
131
132done:
133    return RTEMS_SUCCESSFUL;
134}
Note: See TracBrowser for help on using the repository browser.