source: rtems/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c @ fc56b90c

4.104.114.84.95
Last change on this file since fc56b90c 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: 4.2 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 be
15 *  found in 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#include <zilog/z8036.h>
26
27#define MICRVAL     0xe2            /* disable lower chain, no vec */
28                                    /*  set right justified addr */
29                                    /*  and master int enable */
30#define MCCRVAL     0xc4            /* enable T1 and port B */
31                                    /*   timers independent */
32#define MS_COUNT    0x07d0          /* T1's countdown constant (1 ms) */
33#define T1MSRVAL    0x80            /* T1 cont. cycle/pulse output */
34#define T1CSRVAL    0xc6            /* enable interrupt, allow and */
35                                    /*   and trigger countdown */
36
37#define TIMER        0xfffb0000
38#define RELOAD       0x24            /* clr IP & IUS,allow countdown */
39 
40#define CLOCK_VECTOR 66
41
42rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
43
44volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */
45
46rtems_isr_entry  Old_ticker;
47
48void Clock_exit( void );
49
50/*
51 * These are set by clock driver during its init
52 */
53 
54rtems_device_major_number rtems_clock_major = ~0;
55rtems_device_minor_number rtems_clock_minor;
56 
57/*
58 *  ISR Handler
59 */
60 
61rtems_isr Clock_isr(
62  rtems_vector_number vector
63)
64{
65  Clock_driver_ticks += 1;
66  ((volatile struct z8036_map *) TIMER)->CT1_CMD_STATUS = RELOAD;
67
68  if ( Clock_isrs == 1 ) {
69    rtems_clock_tick();
70    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
71  }
72  else
73    Clock_isrs -= 1;
74}
75
76void Install_clock(
77  rtems_isr_entry clock_isr
78)
79{
80  volatile struct z8036_map *timer;
81
82  Clock_driver_ticks = 0;
83  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
84
85  if ( BSP_Configuration.ticks_per_timeslice ) {
86    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
87    timer = (struct z8036_map *) 0xfffb0000;
88    timer->MASTER_INTR        = MICRVAL;
89    timer->CT1_MODE_SPEC      = T1MSRVAL;
90
91    *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT;  /* write countdown value */
92
93    /*
94     *  timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8);
95     *  timer->CT1_TIME_CONST_LSB = (MS_COUNT &  0xff);
96     */
97
98    timer->MASTER_CFG         = MCCRVAL;
99    timer->CT1_CMD_STATUS     = T1CSRVAL;
100
101    /*
102     * Enable interrupt via VME interrupt mask register
103     */
104    (*(rtems_unsigned8 *)0xfffb0038) &= 0xfd;
105
106    atexit( Clock_exit );
107  }
108
109}
110
111void Clock_exit( void )
112{
113  volatile struct z8036_map *timer;
114
115  if ( BSP_Configuration.ticks_per_timeslice ) {
116    timer = (struct z8036_map *) 0xfffb0000;
117    timer->MASTER_INTR        = 0x62;
118    timer->CT1_MODE_SPEC      = 0x00;
119    timer->MASTER_CFG         = 0xf4;
120    timer->CT1_CMD_STATUS     = 0x00;
121    /* do not restore old vector */
122  }
123}
124
125rtems_device_driver Clock_initialize(
126  rtems_device_major_number major,
127  rtems_device_minor_number minor,
128  void *pargp
129)
130{
131  Install_clock( Clock_isr );
132
133  /*
134   * make major/minor avail to others such as shared memory driver
135   */
136
137  rtems_clock_major = major;
138  rtems_clock_minor = minor;
139 
140  return RTEMS_SUCCESSFUL;
141}
142
143rtems_device_driver Clock_control(
144  rtems_device_major_number major,
145  rtems_device_minor_number minor,
146  void *pargp
147)
148{
149    rtems_unsigned32 isrlevel;
150    rtems_libio_ioctl_args_t *args = pargp;
151 
152    if (args == 0)
153        goto done;
154 
155    /*
156     * This is hokey, but until we get a defined interface
157     * to do this, it will just be this simple...
158     */
159 
160    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
161    {
162        Clock_isr(CLOCK_VECTOR);
163    }
164    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
165    {
166      rtems_interrupt_disable( isrlevel );
167       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
168      rtems_interrupt_enable( isrlevel );
169    }
170 
171done:
172    return RTEMS_SUCCESSFUL;
173}
Note: See TracBrowser for help on using the repository browser.