source: rtems/c/src/lib/libbsp/m68k/mvme162/clock/ckinit.c @ cfefaa6e

4.104.114.84.95
Last change on this file since cfefaa6e 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.7 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initializes the Tick Timer 2 on the MVME162 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 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
19 *  EISCAT Scientific Association. M.Savitski
20 *
21 *  This material is a part of the MVME162 Board Support Package
22 *  for the RTEMS executive. Its licensing policies are those of the
23 *  RTEMS above.
24 *
25 *  $Id$
26 */
27
28#include <stdlib.h>
29
30#include <bsp.h>
31#include <rtems/libio.h>
32
33#define MS_COUNT          1000            /* T2's countdown constant (1 ms) */
34#define CLOCK_INT_LEVEL   6               /* T2's interrupt level */
35
36rtems_unsigned32 Clock_isrs;                  /* ISRs until next tick */
37volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */
38rtems_isr_entry  Old_ticker;
39
40void Clock_exit( void );
41 
42#define CLOCK_VECTOR (VBR0 * 0x10 + 0x9)
43/*
44 * These are set by clock driver during its init
45 */
46 
47rtems_device_major_number rtems_clock_major = ~0;
48rtems_device_minor_number rtems_clock_minor;
49 
50
51/*
52 *  ISR Handler
53 */
54
55rtems_isr Clock_isr(rtems_vector_number vector)
56{
57  Clock_driver_ticks += 1;
58  lcsr->timer_cnt_2 = 0;            /* clear counter */
59  lcsr->intr_clear |= 0x02000000;
60
61  if ( Clock_isrs == 1 ) {
62    rtems_clock_tick();
63    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
64  }
65  else
66    Clock_isrs -= 1;
67}
68
69void Install_clock(rtems_isr_entry clock_isr )
70{
71
72  Clock_driver_ticks = 0;
73  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
74
75  if ( BSP_Configuration.ticks_per_timeslice ) {
76    Old_ticker =
77      (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
78    lcsr->vector_base |= MASK_INT;   /* unmask VMEchip2 interrupts */
79    lcsr->to_ctl = 0xE7;             /* prescaler to 1 MHz (see Appendix A1) */
80    lcsr->timer_cmp_2 = MS_COUNT;
81    lcsr->timer_cnt_2 = 0;           /* clear counter */
82    lcsr->board_ctl |= 0x700;        /* increment, reset-on-compare, and */
83                                     /*   clear-overflow-cnt */
84
85    lcsr->intr_level[0] |= CLOCK_INT_LEVEL * 0x10;      /* set int level */
86    lcsr->intr_ena |= 0x02000000;       /* enable tick timer 2 interrupt */
87
88    atexit( Clock_exit );
89  }
90}
91
92void Clock_exit( void )
93{
94/* Dummy for now. See other m68k BSP's for code examples */
95}
96
97rtems_device_driver Clock_initialize(
98  rtems_device_major_number major,
99  rtems_device_minor_number minor,
100  void *pargp
101)
102{
103  Install_clock( Clock_isr );
104 
105  /*
106   * make major/minor avail to others such as shared memory driver
107   */
108 
109  rtems_clock_major = major;
110  rtems_clock_minor = minor;
111 
112  return RTEMS_SUCCESSFUL;
113}
114 
115rtems_device_driver Clock_control(
116  rtems_device_major_number major,
117  rtems_device_minor_number minor,
118  void *pargp
119)
120{
121    rtems_unsigned32 isrlevel;
122    rtems_libio_ioctl_args_t *args = pargp;
123 
124    if (args == 0)
125        goto done;
126 
127    /*
128     * This is hokey, but until we get a defined interface
129     * to do this, it will just be this simple...
130     */
131 
132    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
133    {
134        Clock_isr(CLOCK_VECTOR);
135    }
136    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
137    {
138      rtems_interrupt_disable( isrlevel );
139       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
140      rtems_interrupt_enable( isrlevel );
141    }
142 
143done:
144    return RTEMS_SUCCESSFUL;
145}
146
Note: See TracBrowser for help on using the repository browser.