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

4.104.114.84.95
Last change on this file since 7e642ba was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 17, 1999 at 5:51:34 PM

Updated copyright notice.

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