source: rtems/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on 04/22/97 at 17:20:27

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initializes the Z80386 1 on the MVME136 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 in
15 *  the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <stdlib.h>
22 
23#include <bsp.h>
24#include <rtems/libio.h>
25
26rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
27volatile rtems_unsigned32 Clock_driver_ticks;
28                                    /* ticks since initialization */
29rtems_isr_entry  Old_ticker;
30
31void Clock_exit( void );
32
33#define CLOCK_VECTOR  TIMER_VECTOR
34 
35/*
36 * These are set by clock driver during its init
37 */
38 
39rtems_device_major_number rtems_clock_major = ~0;
40rtems_device_minor_number rtems_clock_minor;
41
42/*
43 *  ISR Handler
44 */
45
46rtems_isr Clock_isr(
47  rtems_vector_number vector
48)
49{
50  Clock_driver_ticks += 1;
51
52  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xE2 );
53  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x22 );
54  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
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(
65  rtems_isr_entry clock_isr
66)
67{
68  rtems_unsigned8 data;
69
70  Clock_driver_ticks = 0;
71  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
72
73  if ( BSP_Configuration.ticks_per_timeslice ) {
74    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
75
76    Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 );
77    Z8x36_READ ( TIMER, MASTER_INTR, data );
78    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x7E) );
79    Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x04 );
80    Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0xCE );
81    Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x83 );
82    Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, CLOCK_VECTOR );
83    Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 );
84    Z8x36_READ ( TIMER, MASTER_INTR, data );
85    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 );
86
87    /*
88     * ACC_IC54 - interrupt 5 will be vectored and mapped to level 6
89     */
90
91    data = (*(rtems_unsigned8 *)0x0D00000B);
92    (*(rtems_unsigned8 *)0x0D00000B) = (data & 0x7F) | 0x60;
93
94    Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
95
96    atexit( Clock_exit );
97  }
98}
99
100void Clock_exit( void )
101{
102  rtems_unsigned8 data;
103
104  if ( BSP_Configuration.ticks_per_timeslice ) {
105
106    Z8x36_READ ( TIMER, MASTER_INTR, data );
107    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
108    /* do not restore old vector */
109
110  }
111}
112
113rtems_device_driver Clock_initialize(
114  rtems_device_major_number major,
115  rtems_device_minor_number minor,
116  void *pargp
117)
118{
119  Install_clock( Clock_isr );
120 
121  /*
122   * make major/minor avail to others such as shared memory driver
123   */
124 
125  rtems_clock_major = major;
126  rtems_clock_minor = minor;
127 
128  return RTEMS_SUCCESSFUL;
129}
130 
131rtems_device_driver Clock_control(
132  rtems_device_major_number major,
133  rtems_device_minor_number minor,
134  void *pargp
135)
136{
137    rtems_unsigned32 isrlevel;
138    rtems_libio_ioctl_args_t *args = pargp;
139 
140    if (args == 0)
141        goto done;
142 
143    /*
144     * This is hokey, but until we get a defined interface
145     * to do this, it will just be this simple...
146     */
147 
148    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
149    {
150        Clock_isr(CLOCK_VECTOR);
151    }
152    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
153    {
154      rtems_interrupt_disable( isrlevel );
155       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
156      rtems_interrupt_enable( isrlevel );
157    }
158 
159done:
160    return RTEMS_SUCCESSFUL;
161}
162
Note: See TracBrowser for help on using the repository browser.